Hello!
I've been trawling the forum, and all over looking for someone who has already solved this problem.
I have some Moteinos. And think they are great. I also have a small openHAB server (running on a RPi) controlling a few lights and simple things. I would like to connect the Moteinos to openHAB in the simplest way. With two way traffic between openHAB and the Moteinos.
I have MQTT installed on the openHAB server (it's easy, and MQTT will also talk relatively easily to ESP8266 based nodes, if I ever get round to playing with those). I have a Moteino connected to the RPi GPIO header. The radio traffic from sensors is translated to serial in the Moteino with a simple gateway sketch. I can see this works on the RPi by monitoring the serial connection with minicom. I guess I could use a MoetinoUSB, but I think the serial access would be the same on the RPi2 (I see there are some issues with the GPIO serial on the RPi3).
So I think a neat solution (and should be fairly straight forward!) would be to just read the serial input and send it to MQTT (and read other topics from MQTT and send to serial). I'm sure it can be done with a python script / daemon, or C, but I can't seem to manage it. In fact I am sure it is possible for someone with a python background and time: I had a one way script for reading serial and writing to MQTT working. I was a fool and didn't back up the RPi sd card and you can guess what happened next... Corrupt SD card. So I'm back at square one - months later :-(
Can anyone please help with the script for the bridge? I imagine others will also be interested. If I'm the only one, then I'm probably on the wrong track, so hopefully someone will give me a gentle shove in the right direction...
I know Felix has spent quite a lot of effort on his gateway (which I have installed at one point). I can't see how to integrate this with an openHAB install, on the same box. Ie Moteino <> Gateway <> MQTT <> openHab. I don't want to have two servers (even if they are as low power as RPis) running for this (simple - oh it should be so simple!) translation task.
Lots of people use an arduino with RFM69 board (Moteino) with an ethernet shield to bridge the wireless to MQTT. While this will probably work, I don't see why I can't get the Moteino <> GPIO <> serial <> MQTT bridge working.
I also see there is a solution (https://github.com/computourist/RFM69-MQTT-client) that reads and writes via GPIO to a RFM69W and then on to MQTT (but not necessarily a RFM69HW). This seems quite active, and would be neat, but my Moteinos are RFM69HW, and the spare radio I have is HW...
Another (https://github.com/bbx10/nanohab) claims to work for Moteinos <> ESP8266 <> WiFi <> openHAB. I can't tell if this working or under development.
This solution (https://github.com/Gussoh/serial-mqtt-bridge) seems to work in Java (but I haven't had a chance to work out what it is doing - does it need to be that complex to move data back and forth?)
Some people at MySensors (https://forum.mysensors.org/topic/655/serial-gateway-connection-to-openhab) seems to have something working, but I haven't worked out what MySensors entails.
Help?
I'm not sure if my proposal is what you want....I'm just working on a project, where I want to establish a serial transmission between an Arduino and a NETMF Board (as Gateway). I decided to use the Modbus protocol for the conversation and have the Arduino Modbus Client running with an adaption of an existing library.
https://www.ghielectronics.com/community/codeshare/entry/1102
I suppose (but did not verify) that you can find a Modbus Master library for the Raspberry Pi in the internet.
Kind Regards
RoSchmi
Thanks for your reply RoSchmi.
I'm not to worried about the format of the packets between the moteino and the serial input of the Pi. It's converting the serial input to MQTT that has me stumped.
Looks like I'll have to have a go at developing this myself (still can't believe no-one has already done this!)
Quote from: Stevo on March 25, 2017, 08:23:48 PM
Thanks for your reply RoSchmi.
I'm not to worried about the format of the packets between the moteino and the serial input of the Pi. It's converting the serial input to MQTT that has me stumped.
Looks like I'll have to have a go at developing this myself (still can't believe no-one has already done this!)
I did it!
I havn't documented it yet. And missing some parts still... I'll post very soon.
Great! Any chance you could share what you have (even if it is not yet perfect)?
Thanks!
I have written a gateway that serves my purpose (for now). It seems to work ok for me. I'm running it using systemd on a rpi with a moteino connected via the serial pins. I don't imagine too many other will be interested, but since I've started a thread, I have put the code on github. https://github.com/stevogray/SerialMQTTGateway/blob/master/SerialGateway.py
Nice job.
I'm still actively developing mine. That's why I didn't shared it. And I have included MySensors data serial api. Probably you won't need it...
Great work! Thank you for sharing!
Could you please be so kind to show the gateway-code you "slightly modified" ? :D
Hello walti82w
I'm not sure what gateway you are looking for. You can find the code for the python gateway I wrote at:
https://github.com/stevogray/SerialMQTTGateway/blob/master/SerialGateway.py
I hope this will help you!
Sorry I am talkin about the moteino sketch. Regarding colons/comma :-)
My broker is running fine, tested with Mqtt.fx. My only problem is to connect the moteino via serial interface to the broker. I am using the Python script that translates. It is running as well. What I do not understand is, how the serial data coming from the moteino-gateway(connected using FTDI to Pi) should look like
Something like this for node 2??? :
2,home/status/moteino_2_signal:54
Thank you in advance ::) ???
Hi Walti82w,
Sorry for the massive delay. I've been riding my bicycle around Europe.
What I have done is modified the Pi-gateway sketch by Felix to output comma delimited data. As I wrote in the code I posted, the form should be:
<sending_node_number>,<topic>:<message>,<topic>:<message>
For Node 2, this could look like:
2,signal:54,temperature:28
And this data would be published to MQTT topics by the script:
sensors/</2/signal (published value would be 54)
sensors/</2/temperature (published value would be 28)
Sorry for the long delay, and hope this helps!
Hi Stevo,
if you were in south-germany you could have seen the problem ;D
Hope your trip was good? :o
Thank you for your reply. In fact it helped me to understand how this output has to look like.
But I am struggling with the construction. Actually it looks like this :
3,S:16.00 I:21.00
I do not know how to insert the comma...
How does your sketch look like in this particular area ?
Sorry for the very slow replies. I did ride through southern Germany. I'm still on the trip - in Romania at the moment :-)
I think the only thing you will need to change is in the sketch in the moteino that is sending the messages. I just add the commas in the message that is sent by the radio. Your gateway seems to be right, there is a comma between the node number and the rest of the message.
In the remote moteino, one of my sketches has a line (inside loop()):
sprintf(sendstring, "T:%d.%02d,H:%d.%02d",temp, tempdec,humid, humiddec);
This is how I add commas between the different topics.
The sketch after this is the same as the examples (I've taken out some of the the Serial.print lines):
sprintf(sendstring, "T:%d.%02d,H:%d.%02d",temp, tempdec,humid, humiddec);
sendSize = strlen(sendstring);
if (radio.sendWithRetry(GATEWAYID, sendstring, sendSize))
Serial.print(" ok!");
else Serial.print(" nothing...");