Raspberry pi B, kura, mqtt [message #1777063] |
Fri, 24 November 2017 09:06 |
Javier A. Messages: 10 Registered: November 2017 |
Junior Member |
|
|
Good morning, I have a raspberry pi with kura installed and for other hand my computer with "mosquitto" (a mqtt broker). I´m tryng to send a mqtt message from my raspberry to mosquitto, the problem is:
-To test how works mqtt, i write a simple example in java with eclipse to send a mqtt msg.
try {
System.out.println(1);
MqttClient client = new MqttClient("tcp://192.168.0.116:1883",
MqttClient.generateClientId());
client.connect();
System.out.println(2);
MqttMessage message = new MqttMessage();
message.setPayload(messageString.getBytes());
client.publish("test", message);
System.out.println("\tMessage '"+ messageString +"' to 'test'");
client.disconnect();
System.out.println("== END PUBLISHER ==");
}catch(Exception e){
System.out.println(e.getMessage());
}
And it works, in mosquitto i can see the msg.
I write helloword example follow doc (tested and works show msg in kura-console), now with this example I wanted to test send mqtt msg with kura. I configure kura project, export *.jar, generate *.dp and install it using kura interface and all good, without errors.
protected void activate(ComponentContext componentContext) {
System.out.println("Start: Hello World");
try {
String messageString = "Hello World from Java!";
System.out.println(1);
MqttClient client = new MqttClient("tcp://192.168.0.93:1883", MqttClient.generateClientId());
client.connect();
System.out.println(2);
MqttMessage message = new MqttMessage();
message.setPayload(messageString.getBytes());
client.publish("test", message);
System.out.println("\tMessage '"+ messageString +"' to 'test'");
client.disconnect();
System.out.println("== END PUBLISHER ==");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
protected void deactivate(ComponentContext componentContext) {
System.out.println("Stop: Hello World");
s_logger.info("Bundle " + APP_ID + " has stopped!");
}
But when I go to "Kura->Devices->Bundles" the state is "Installed"instead of "Active" and when I try to start it, show an error
Someone has some idea about how can I solve this or how have I to do to send mqtt msg from Kura to mosquito.
All help is wellcome.
Thank.
-
Attachment: error.jpg
(Size: 22.50KB, Downloaded 784 times) -
Attachment: error log.jpg
(Size: 54.06KB, Downloaded 784 times)
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03059 seconds