Receiving sensor data in Eclipse via Kura (IoT) [message #1754411] |
Fri, 17 February 2017 07:58  |
Eclipse User |
|
|
|
Hi, everyone.
I'm working on an IoT project. The objective is to receive sensor readings data (in this case, a thermostat) in Eclipse, so that a management application can be developed later on.
The sensor is plugged in a microcontroller. The microcontroller is connected to a Raspberry Pi gateway via WiFi (the gateway's WiFi).
The Raspberry Pi is running a Linux server, and on top of it is Kura Framework.
The Raspberry Pi is connected to a router, and then to my computer.
All of the itens listed above are already working. The sensor is reading temperature data, sending it to the gateway via WiFi and the linux server within sends the data to my computer, on which I can read it in a terminal (PuTTY).
The Kura web UI is also working.
Now, I need to make this data that is being received on PuTTY to be transmitted to Eclipse instead, or to Kura web UI and then to Eclipse. That way, I can manipulate the data anyway I want.
To help develop all of this I'm following the steps in Eclipse Kura documentation, and it has helped A LOT so far, but now that it has come to receive the sensor data, I got stuck.
Does anyone has any hints, tutorials or documentations that can help me with this?
Thanks in advance!
|
|
|
|
|
|
|
Re: Receiving sensor data in Eclipse via Kura (IoT) [message #1754972 is a reply to message #1754968] |
Fri, 24 February 2017 12:49  |
Eclipse User |
|
|
|
I've managed to show the data in Eclipse. Here's the code for the update method that is being called every time data is send:
private Map<String, Object> properties;
public void updated(Map<String, Object> properties) {
this.properties = properties;
String broker = "";
String clientId = "";
String topic = "";
if(properties != null && !properties.isEmpty()) {
broker = (String) properties.get("broker.name");
clientId = (String) properties.get("clientId.name");
topic = (String) properties.get("topic.name");
doDemo(broker, clientId, topic);
}
}
public void doDemo(String broker, String clientId, String topic) {
MemoryPersistence persistence = new MemoryPersistence();
try {
MqttClient sampleClient = new MqttClient(broker, clientId, persistence);
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(true);
sampleClient.setCallback(new MqttCallback() {
public void connectionLost(Throwable cause) {}
public void messageArrived(String topic, MqttMessage message) throws Exception {
System.out.println("Message: " + message.toString());
}
public void deliveryComplete(IMqttDeliveryToken token) {}
});
sampleClient.connect(connOpts);
sampleClient.subscribe(topic);
} catch(MqttException e) {
e.printStackTrace();
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.05123 seconds