Using mqttGateway2.pl for Serial to MQTT on RaspberryPI
-
@Artur-Maj You also have the option of going towards a prototype 2.0 branch that is being worked on. Doing this, you will be able to get support and updates in the future.
My branch is here: https://github.com/aaron832/Arduino/tree/feature/MQTTSupport
Perform "make mqtt" under Arduino/libraries/MySensors
You can change any mqtt settings by uncommenting lines in Arduino/libraries/MySensors/examples_RPi/PiGateway.cpp
The format MQTT messages are as follows:
From MySensors to Openhab: mygateway1-out/node/sensor/command/ack/dataType
From OpenHab to MySensors: mygateway1-in/node/sensor/command/ack/dataTypeThere is still more work to be done, but it works at least as well as the previous version.
@aaron832 While running make all from libraries/MySensors I am getting errors like that:
examples_RPi/PiGateway.o: In function
transportSendWrite(unsigned char, MyMessage&)': /home/artur/Arduino-feature-MQTTSupport/libraries/MySensors/./core/MyTransportNRF24.cpp:102: undefined reference toRF24::powerUp()'
/home/artur/Arduino-feature-MQTTSupport/libraries/MySensors/./core/MyTransportNRF24.cpp:103: undefined reference toRF24::stopListening()' /home/artur/Arduino-feature-MQTTSupport/libraries/MySensors/./core/MyTransportNRF24.cpp:104: undefined reference toRF24::openWritingPipe
and continues....
I have installed : https://github.com/TMRh20/RF24.
What I am doing wrong? -
Try typing
"uname -m"into your console (that hosts the gateway). If it does not say
"armv6l" or "armv7l" (edit: correction)
then the Makefile will not include -lrf24-bcm in the LDFLAGS (libraries include). If this is the problem then what hardware are you making the gateway on? -
Try typing
"uname -m"into your console (that hosts the gateway). If it does not say
"armv6l" or "armv7l" (edit: correction)
then the Makefile will not include -lrf24-bcm in the LDFLAGS (libraries include). If this is the problem then what hardware are you making the gateway on? -
Hi, i tried to make the script work but i couldnt. did anybody make it work? I used the serial gateway option, installed all the libraries.
. thankspi@raspberrypi:/ $ sudo ./mqttGateway2.pl --serial /dev/ttyUSB0
Subroutine main::inet_aton redefined at /usr/share/perl/5.20/Exporter.pm line 66.
at ./mqttGateway2.pl line 42.
given is experimental at ./mqttGateway2.pl line 267.
when is experimental at ./mqttGateway2.pl line 269.
when is experimental at ./mqttGateway2.pl line 270.
when is experimental at ./mqttGateway2.pl line 271.
when is experimental at ./mqttGateway2.pl line 272.
Smartmatch is experimental at ./mqttGateway2.pl line 313.
Smartmatch is experimental at ./mqttGateway2.pl line 332.
given is experimental at ./mqttGateway2.pl line 400.
when is experimental at ./mqttGateway2.pl line 402.
when is experimental at ./mqttGateway2.pl line 411.
Name "main::fh" used only once: possible typo at ./mqttGateway2.pl line 207.
can't create /var/run/mqttMySensors/Gateway__dev_ttyUSB0: No existe el fichero o el directorio at ./mqttGateway2.pl line 452.
What does it means?
Thanks -
@Yveaux Keep on getting this error
-
Hi, i tried to make the script work but i couldnt. did anybody make it work? I used the serial gateway option, installed all the libraries.
. thankspi@raspberrypi:/ $ sudo ./mqttGateway2.pl --serial /dev/ttyUSB0
Subroutine main::inet_aton redefined at /usr/share/perl/5.20/Exporter.pm line 66.
at ./mqttGateway2.pl line 42.
given is experimental at ./mqttGateway2.pl line 267.
when is experimental at ./mqttGateway2.pl line 269.
when is experimental at ./mqttGateway2.pl line 270.
when is experimental at ./mqttGateway2.pl line 271.
when is experimental at ./mqttGateway2.pl line 272.
Smartmatch is experimental at ./mqttGateway2.pl line 313.
Smartmatch is experimental at ./mqttGateway2.pl line 332.
given is experimental at ./mqttGateway2.pl line 400.
when is experimental at ./mqttGateway2.pl line 402.
when is experimental at ./mqttGateway2.pl line 411.
Name "main::fh" used only once: possible typo at ./mqttGateway2.pl line 207.
can't create /var/run/mqttMySensors/Gateway__dev_ttyUSB0: No existe el fichero o el directorio at ./mqttGateway2.pl line 452.
What does it means?
Thanks -
@cingolanifede said:
/var/run/mqttMySensors/Gateway__dev_ttyUSB0: No existe el fichero o el directorio at
This path doesn't exist. Create it, or change the path.
All others are warnings, due to an incompatible perl version you're using.@Yveaux ok. Thanks. I did it. But i am having a different problem now. I have serial gateway running fine. I installed mosquitto and try to follow different steps from the forum and I dont know how to make this work.K cant make the connection beetwen openhab--mosquitto-script--serial gateway. Can you help me ? Is there any post where this is done? Thanks in advance.
-
@Yveaux ok. Thanks. I did it. But i am having a different problem now. I have serial gateway running fine. I installed mosquitto and try to follow different steps from the forum and I dont know how to make this work.K cant make the connection beetwen openhab--mosquitto-script--serial gateway. Can you help me ? Is there any post where this is done? Thanks in advance.
@cingolanifede I don't have a step by step description for your solution. Searching (and reading) the forum sounds like a good start. If you give us a clear description of what seems to be working and what not, or where you get stuck, it's easier to help.
-
@cingolanifede I don't have a step by step description for your solution. Searching (and reading) the forum sounds like a good start. If you give us a clear description of what seems to be working and what not, or where you get stuck, it's easier to help.
@Yveaux 1) The script is running. It reads from serial port, this is what I get, then it crashes, and says broken pipe.
20160509-10:48:33 RX: [0;0;3;0;9;read: 30-30-0 s=1,c=1,t=16,pt=2,l=2,sg=1:1] fr=000 ci=000 c=C_INTERNAL st=I_LOG_MESSAGE noack 'read: 30-30-0 s=1,c=1,t=16,pt=2,l=2,sg=1:1' -> Publish to broker 'MyMQTT/0/0/I_LOG_MESSAGE':'read: 30-30-0 s=1,c=1,t=16,pt=2,l=2,sg=1:1'
20160509-10:48:33 RX: [30;1;1;0;16;1 ] fr=030 ci=001 c=C_SET st=V_TRIPPED noack '1' -> Publish to broker 'MyMQTT/30/1/V_TRIPPED':'1'
20160509-10:48:43 Exception: Error: Tubería rota20160509-10:48:43 Restarting...
20160509-10:48:43 trying to restore subscriptions====2)On openhab log I get this========
2016-05-09 10:48:33.189 [ERROR] [o.i.t.m.i.MqttBrokerConnection] - MQTT connection to broker was lost
org.eclipse.paho.client.mqttv3.MqttException: Se ha perdido la conexión
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:138) [mqtt-client-0.4.0.jar:na]
at java.lang.Thread.run(Thread.java:744) [na:1.8.0]
Caused by: java.io.EOFException: null
at java.io.DataInputStream.readByte(DataInputStream.java:267) ~[na:1.8.0]
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:56) ~[na:na]
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:100) [mqtt-client-0.4.0.jar:na]
... 1 common frames omitted
2016-05-09 10:48:33.191 [ERROR] [o.i.t.m.i.MqttBrokerConnection] - MQTT connection to 'mysensor' was lost: Se ha perdido la conexión : ReasonCode 32109 : Cause : null
2016-05-09 10:48:33.193 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'mysensor'On openhab.cfg i put this and i have the addons installed
mqtt:mysensor.url=tcp://192.168.1.109:1883
mqtt:mysensor.clientId=mysA simple switch setting
Switch node2_sw1 "sw1" (node2,all) {mqtt=">[mysensor:MyMQTT/30/10/V_LIGHT:command:ON:1],>[mysensor:MyMQTT/30/10/V_LIGHT:command:OFF:0]"}I think the problem is that i am not setting mosquitto well beetwen openhab and your script. I tested an example publishing and i get the message. Do I have to change conf.d file? or setting?
Thanks.
-
@Yveaux I made improvement:
I am using mosquitto_sub to read what the script posted. Thats ok.pi@domotic /opt/domotic/runtime $ mosquitto_sub -d -t MyMQTT/30/1/V_TRIPPED
Client mosqsub/3629-domotic sending CONNECT
Client mosqsub/3629-domotic received CONNACK
Client mosqsub/3629-domotic sending SUBSCRIBE (Mid: 1, Topic: MyMQTT/30/1/V_TRIPPED, QoS: 0)
Client mosqsub/3629-domotic received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/3629-domotic received PUBLISH (d0, q0, r1, m0, 'MyMQTT/30/1/V_TRIPPED', ... (1 bytes))
1
Client mosqsub/3629-domotic received PUBLISH (d0, q0, r0, m0, 'MyMQTT/30/1/V_TRIPPED', ... (1 bytes))
0
Client mosqsub/3629-domotic sending PINGREQ
Client mosqsub/3629-domotic received PINGRESP
Client mosqsub/3629-domotic sending PINGREQ
Client mosqsub/3629-domotic received PINGRESP
Client mosqsub/3629-domotic sending PINGREQ
Client mosqsub/3629-domotic received PINGRESPThe thing is when I start openhab this happens, it crashes and i get this error. What could it be?
2016-05-09 11:56:52.216 [ERROR] [o.i.t.m.i.MqttBrokerConnection] - MQTT connection to broker was lost
org.eclipse.paho.client.mqttv3.MqttException: Se ha perdido la conexión
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:138) [mqtt-client-0.4.0.jar:na]
at java.lang.Thread.run(Thread.java:744) [na:1.8.0]
Caused by: java.io.EOFException: null
at java.io.DataInputStream.readByte(DataInputStream.java:267) ~[na:1.8.0]
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:56) ~[na:na]
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:100) [mqtt-client-0.4.0.jar:na]
... 1 common frames omitted
2016-05-09 11:56:52.219 [ERROR] [o.i.t.m.i.MqttBrokerConnection] - MQTT connection to 'mysensor' was lost: Se ha perdido la conexión : ReasonCode 32109 : Cause : null
2016-05-09 11:56:52.220 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'mysensor' -
The script is running for months without issues on my place; both for serial and Ethernet gateway. I am not using the script in combination with a raspberry pi. Maybe there is an issue with the version of mosquitto and/or AnyEvent::MQTT.
I remember other people having issues in combination with raspberry pi - search the forum. -
The script is running for months without issues on my place; both for serial and Ethernet gateway. I am not using the script in combination with a raspberry pi. Maybe there is an issue with the version of mosquitto and/or AnyEvent::MQTT.
I remember other people having issues in combination with raspberry pi - search the forum.@Yveaux Thanks again. I used a phyton script. Now is working.
-
Not sure I'm doing this right way, but changing this line:
fh => $serialDevice->{'HANDLE'},to this line
fh => new_from_fd IO::Handle ($serialDevice->{FD}, "w"),Fixed
Filehandle GEN0 opened only for inputbug for me on RPi 2. Fix works because of$serialDevice->{'HANDLE'}is opened as read only in SerialDevice and should not be used for write:# a handle object for ioctls: read-only ok $self->{HANDLE} = new_from_fd IO::Handle ($self->{FD}, "r");