Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » Publish data to the cloud
Publish data to the cloud [message #1764596] Wed, 31 May 2017 14:41 Go to next message
Javier Ortiz is currently offline Javier OrtizFriend
Messages: 8
Registered: May 2017
Junior Member
Hello there,

I want to publish data to aws cloud, I've already configured it on the kura web UI. Now, I'm my bundle, I'm not sure what to do to publish data to a specific topic.

I've been looking at Bluetooth LE Example and Heater Demo, and I've seen the methods doPublishKeys and doPublish. I understand that those methods are the one used to publish data to a topic. My question is, something called KuraPayload is been used, and I don't know if that is compatible with AWS Json (I want, if possible, to send data in Json format to the cloud).

Will I be able to understand that KuraPayload when it arrives in my aws console?
Is there a way to just publish a message with pairs of "attribute": "valor"?

Also, when in the bundle the cloudservice is set, it's the one I want?, I mean in the kura web UI there are 2 Cloud Services: org.eclipse.kura.cloud.CloudService and org.eclipse.kura.cloud.CloudService-AWS, and from the web UI I did connect to the AWS service. When I call the respective method publishSomething() in my bundle, will it publish de data to the AWS cloud?

I hope I did express myself well.

Thanks for reading,
Javi.

[Updated on: Wed, 31 May 2017 14:52]

Report message to a moderator

Re: Publish data to the cloud [message #1764607 is a reply to message #1764596] Wed, 31 May 2017 18:03 Go to previous messageGo to next message
Matteo Maiero is currently offline Matteo MaieroFriend
Messages: 423
Registered: July 2015
Location: Italy
Senior Member
Hi Javier,
the KuraPayload is an abstraction to allow a simple way to define a message. Then, the Kura payload can be converted to a form that can be published.
Since Kura 3.0.0, the Cloud Service tab allows you to select the publishing format of the mqtt message as Kura Protobuf (have a look at the Google Protobuf for more details) or simple JSON.

As far as I know, you could publish with both KuraProtobuf or simple JSON to AWS, but you will be able to see only the JSON ones in the simple AWS console.

By default, the Bluetooth example and the heater will publish to the CloudService instance. If you want to use the CloudService-AWS instance you created, you need the Example Publisher or to create your own application.

Best regards,
Matteo
Re: Publish data to the cloud [message #1764613 is a reply to message #1764607] Wed, 31 May 2017 19:19 Go to previous messageGo to next message
Javier Ortiz is currently offline Javier OrtizFriend
Messages: 8
Registered: May 2017
Junior Member
Hello Matteo,

Thanks for answering. What if I just put all the AWS cloud configuration in the default cloud service that appears in the website? Would that work for me?

Thanks,
Javi.
Re: Publish data to the cloud [message #1764614 is a reply to message #1764613] Wed, 31 May 2017 19:20 Go to previous messageGo to next message
Matteo Maiero is currently offline Matteo MaieroFriend
Messages: 423
Registered: July 2015
Location: Italy
Senior Member
It should.
Best regards,
Matteo
Re: Publish data to the cloud [message #1764702 is a reply to message #1764614] Thu, 01 June 2017 13:41 Go to previous messageGo to next message
Javier Ortiz is currently offline Javier OrtizFriend
Messages: 8
Registered: May 2017
Junior Member
I did it and it worked!

I've been using the DataService instead of the CloudService to publish de data (I need to have control on the topic) and it has worked good so far. However, in my policy I don't want to allow subscriptions, and if in the policy that we created for the AWS cloud example I remove the action "iot:Subscribe" and try to connect and send data to the cloud, It does not work because the DataService is trying to subscribe to a topic (rpi/rpi/myapp/xmltopic) but it fails and disconnects. 'rpi' is what I put in the attributes topic.context.name and client-id. Here I put what appears in the log:

2017-06-01 13:27:18,023 [DataServiceImpl:ReconnectTask] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  Connecting...
2017-06-01 13:27:18,025 [pool-9-thread-1] INFO  o.e.k.c.s.r.LogStatusRunnable - Notification LED fast blinking
2017-06-01 13:27:18,061 [MQTT Con: rpi] INFO  o.e.k.c.s.SSLSocketFactoryWrapper - SSL Endpoint Identification enabled.
2017-06-01 13:27:22,099 [DataServiceImpl:ReconnectTask] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  Connected!
2017-06-01 13:27:22,100 [DataServiceImpl:ReconnectTask] INFO  o.e.k.c.d.t.m.MqttDataTransport - # ------------------------------------------------------------
2017-06-01 13:27:22,101 [pool-9-thread-1] INFO  o.e.k.c.s.r.LogStatusRunnable - Notification LED off
2017-06-01 13:27:22,102 [DataServiceImpl:ReconnectTask] INFO  o.e.k.c.d.DataServiceImpl - Notified connected
2017-06-01 13:27:22,104 [DataServiceImpl:ReconnectTask] INFO  o.e.k.c.d.DataServiceImpl - New session established. Unpublishing all in-flight messages. Disregarding the QoS level, this may cause duplicate messages.
2017-06-01 13:27:22,110 [DataServiceImpl:ReconnectTask] INFO  o.e.k.c.c.CloudServiceImpl - Birth certificate republish is disabled in configuration
2017-06-01 13:27:22,112 [DataServiceImpl:ReconnectTask] INFO  o.e.k.c.c.CloudServiceImpl - Default subscriptions are disabled in configuration
2017-06-01 13:27:22,113 [DataServiceImpl:ReconnectTask] INFO  o.e.k.c.Cloudlet - Cloud Client Connection Restored
2017-06-01 13:27:22,114 [DataServiceImpl:ReconnectTask] INFO  o.e.k.c.Cloudlet - Cloud Client Connection Restored
2017-06-01 13:27:22,115 [DataServiceImpl:ReconnectTask] INFO  o.e.k.c.Cloudlet - Cloud Client Connection Restored
2017-06-01 13:27:22,117 [DataServiceImpl:ReconnectTask] INFO  o.e.k.c.d.t.m.MqttDataTransport - Subscribing to topic: rpi/rpi/myapp/xmltopic with QoS: 0
2017-06-01 13:27:22,196 [DataServiceImpl:ReconnectTask] ERROR o.e.k.c.d.t.m.MqttDataTransport - Cannot subscribe to topic: rpi/rpi/myapp/xmltopic
Connection lost (32109) - java.io.EOFException
	at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:154)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException
	at java.io.DataInputStream.readByte(DataInputStream.java:267)
	at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:89)
	at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:112)
	... 1 more
2017-06-01 13:27:22,197 [MQTT Rec: rpi] WARN  o.e.k.c.d.t.m.MqttDataTransport - Connection Lost


I've been loking into it and try to guess where the bundle tries to subscribe to that topic, but I did not manage to find it.
Is there a way for my bundle to not to try to connect to that topic?

Thanks and regards,
Javi.
Re: Publish data to the cloud [message #1764706 is a reply to message #1764702] Thu, 01 June 2017 13:49 Go to previous messageGo to next message
Matteo Maiero is currently offline Matteo MaieroFriend
Messages: 423
Registered: July 2015
Location: Italy
Senior Member
I think that the bundle needs some changes.
Re: Publish data to the cloud [message #1764711 is a reply to message #1764706] Thu, 01 June 2017 14:40 Go to previous messageGo to next message
Javier Ortiz is currently offline Javier OrtizFriend
Messages: 8
Registered: May 2017
Junior Member
Hello Matteo,

Thanks for answering. My bundle is pretty much like the Bluetooth LE Example, but instead of implementing the CloudServiceListener interface, it does implement the DataServiceListener interface, and uses DataService instead of CloudService to connect and publish data to the cloud.
The bundle scans for BLE devices, but in my case I am interested on reading heart rate measurements from devices that offer the Heart Rate Service, so it does connect to them, and when it receives a heart rate measurement, it publish this data to the cloud, to a specific topic.

So what I do is the following:

1. Get the DataService
	public void setDataService(DataService dataService) {
		this.dataService = dataService;
	}


2. Connect to the cloud
if (!dataService.isConnected())
    	{
    		logger.info("Conectando a la nube...");
    		try {
    			dataService.connect();
    		}
    		catch (KuraConnectException e)
    		{
    			logger.error("Error al conectar a la nube", e);
    		}
     	}


3. Publish data to the cloud when a heart rate measurement is received
protected static void publishData(String address, int pulso, int energia) 
    {
    	if (dataService.isConnected())
    	{
    	    JSONObject payload = new JSONObject();

    	    payload.put("address", address);
    	    payload.put("pulso", pulso);
            if (energia != -1) payload.put("energia", energia);

            int qos = 1;
            boolean retain = false;
            try 
            {
            	dataService.publish(topic, payload.toJSONString().getBytes(), qos, retain, 4);
            	logger.info("Datos publicados!");
            } catch (Exception e) {
            	logger.error("Error al publicar datos", e);
            }
    	}
    	else logger.error("Error al publicar: Desconectado de la nube.");
    }


My bundle does not try to subscribe to any topic in any moment, here are the methods for the DataServiceListener interface:
@Override
    public void onDisconnecting()
    {
    	
    }
    
    @Override
    public void onDisconnected()
    {
    	
    }
    
    @Override
    public void onConnectionLost(Throwable cause)
    {
    	
    }
    
    @Override
    public void onConnectionEstablished() 
    {
     		
    }

    @Override
    public void onMessageArrived(String topic, byte[] payload, int qos, boolean retained) 
    {
  
    }
    
    @Override
    public void onMessageConfirmed(int messageId, String appTopic) {

    }

    @Override
    public void onMessagePublished(int messageId, String appTopic) {

    }


Is there something I am doing wrong?

The DataService seems to be doing things that I dont want to be done (like subscribing to that topic, publishing control messages, etc.). Is there anyway to avoid that behavior?

Thanks so much for your help. Regards,
Javi.
Re: Publish data to the cloud [message #1764730 is a reply to message #1764711] Thu, 01 June 2017 17:29 Go to previous messageGo to next message
Javier Ortiz is currently offline Javier OrtizFriend
Messages: 8
Registered: May 2017
Junior Member
Update:

Somehow I did fix the problem. I searched 'myapp/xmltopic' in kura github and I saw that it appeared in some files regarding Camel, so from the kura console I stopped the Camel Cloud Factory bundle and the problem was gone. I hope that tomorrow it will work too.

Regards,
Javi.

Re: Publish data to the cloud [message #1765393 is a reply to message #1764730] Fri, 09 June 2017 07:54 Go to previous messageGo to next message
Matteo Maiero is currently offline Matteo MaieroFriend
Messages: 423
Registered: July 2015
Location: Italy
Senior Member
Hi Javier,
can I ask you to file an issue on this in the Kura Github repository, in order to start a discussion and see if the Camel bundle that is performing this subscription needs to be changed?

Thanks.
Best regards,
Matteo
Re: Publish data to the cloud [message #1766784 is a reply to message #1765393] Tue, 27 June 2017 09:45 Go to previous messageGo to next message
Javier Ortiz is currently offline Javier OrtizFriend
Messages: 8
Registered: May 2017
Junior Member
Hi Matteo,

Sure. I'm gonna check it out. By the way, is there any way to avoid the auto activation of a bundle in Kura? I mean, I have to manually deactivate the bundle every single time my Raspberry turns on. Is there a way to just don't activate that specific bundle when Kura starts?

Thanks.
Regards,
Javi.
Re: Publish data to the cloud [message #1766785 is a reply to message #1766784] Tue, 27 June 2017 09:49 Go to previous message
Matteo Maiero is currently offline Matteo MaieroFriend
Messages: 423
Registered: July 2015
Location: Italy
Senior Member
Hi,
you can do that modifying the config.ini file in /opt/eclipse/kura/kura removing the unwanted references.

Best regards,
Matteo
Previous Topic:Evend Admin?
Next Topic:Why git auth failed?
Goto Forum:
  


Current Time: Sat Apr 20 15:31:00 GMT 2024

Powered by FUDForum. Page generated in 0.04037 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top