MySensors Raspberry port suggestions


  • Code Contributor

    In an attempt to keep mysensors/Raspberry repository in sync with mysensors/Arduino, I started a while ago working on a solution but only recently had time to finish.
    I ended up with two approaches:

    Place the raspberry gateway files in a directory called examples_RPi within the libraries\MySensors folder (more or less like TMRh20/RF24 does)
    https://github.com/marceloaqno/Arduino/tree/raspberry-gateway

    or keep the two repos and use git subtree to bind them:
    https://github.com/marceloaqno/Raspberry/tree/experimental

    What you guys thinks?

    I'm trying to catch up with new changes into the development branch and thinking of a way to port this into it.


  • Admin

    @marceloaqno said:

    Place the raspberry gateway files in a directory called examples_RPi within the libraries\MySensors folder (more or less like TMRh20/RF24 does)

    Keeping the RPI specific files within libraries/MySensors/core and libraries/MySensors/drivers would be my first choice... Pinging @Oitzu here also as he talked about helping as well.



  • @marceloaqno said:

    I ended up with two approaches:

    Place the raspberry gateway files in a directory called examples_RPi within the libraries\MySensors folder (more or less like TMRh20/RF24 does)
    https://github.com/marceloaqno/Arduino/tree/raspberry-gateway

    or keep the two repos and use git subtree to bind them:
    https://github.com/marceloaqno/Raspberry/tree/experimental

    What you guys thinks?

    I was also thinking back and forth whats the best way to accomplish this.
    In the end i think the better way is to do it like TMRh20/RF24 do it, because it also fits better in the current mysensors git structure.

    @hek said:

    Keeping the RPI specific files within libraries/MySensors/core and libraries/MySensors/drivers would be my first choice...

    The RPi specific files would be withing these dirs, in examples_RPi would only be the example code for the serial-gateway, or other examples for the library. So this would be much like the arduino "examples" dir.



  • @marceloaqno I have been looking into your work to get the RaspberryPi up to date with the latest MySensors code. You have examples for Regular Gateway, Serial and Ethernet. Are you considering creating another for MQTT? I might start looking into this, just wanted to see if you had anything planned. I think it would be best to have a Raspberry PI acting as a gateway as well as an OpenHab/MQTT server.


  • Code Contributor

    @aaron832 I'm planning to add support to MQTT directly into the ethernet gateway. Gonna try to use mongoose (https://github.com/cesanta/mongoose) for the MQTT so it wouldn't require any external library. I got stuck exploring the many cool things that can be done with Node-Red that I didn't start to implement anything yet 😜



  • @marceloaqno Ha, Cool. Happy to hear you are looking at MQTT. I will keep a watch on your repository and will try experimenting with using mongoose as well.



  • Just as an update, I have the MQTT version with mongoose mostly working. Thanks for that recommendation @marceloaqno. Still very much a work in progress. If anyone is interested in following, here is the link: https://github.com/aaron832/Arduino/tree/raspberry-gateway-MQTT/libraries/MySensors/examples_RPi



  • FYI I had to ditch mongoose. It just wan't working properly. libmosquitto from http://mosquitto.org/ seems to work a lot better. Any idea about getting @marceloaqno 's branch merged into develop or vise versa? Would be nice to be working on 2.0


  • Code Contributor

    @aaron832 I'm very close to reaching a working version for the 2.0, will release something in the coming days.



  • @marceloaqno This is good news because I was about to give up trying to do the port. 😅 Hopefully some of my stuff was of some use.


  • Code Contributor

    This is the initial support for Linux/RaspberryPi for the 2.0:
    https://github.com/marceloaqno/Arduino/tree/dev-raspberrypi

    Supports:

    • RF24 radio
    • Ethernet gateway
    • Store "eeprom" to a file (thanks to @aaron832 )
    • MQTT (thanks to @aaron832 )
    • Can be compiled in a linux machine other than Pi

    To be implemented:

    • Store "eeprom" to a file
    • Serial
    • MQTT
    • RF24 interrupts
    • UDP
    • Act as a client to connect to a controller

    I haven't extensively test it, so there are probably some bugs. Any suggestions or ideas for improvement are welcome.



  • Thanks a bunch @marceloaqno for you update to 2.0. Some initial testing shows its working fine. I went ahead and just re-implemented my MQTT addition on top of this branch. Its significantly cleaner and just sits alongside your ethernet implementation. This way you can still connect with a controller via ethernet while getting the benefit of MQTT as well if desired.

    For the initial changes I created a pull request:
    https://github.com/marceloaqno/Arduino/pull/2
    for my branch
    https://github.com/aaron832/Arduino/tree/feature/MQTTSupport


  • Admin

    Great progress guys!


  • Code Contributor

    Perhaps we should start another topic with a better name so that more people become aware of this port?


  • Admin

    @marceloaqno
    Yes, might be a good idea.



  • Any plans for RFM69h(w) support??

    Thanks


  • Code Contributor

    @lafleur Do you recommend any RFM69h library that works well in Pi? I could try to add support if there is any.




  • Code Contributor

    Just an update, I've been using this port on my raspberry pi during the last months and it has been quite stable, the code is also up to date with the mysensors development branch.


  • Hardware Contributor

    That's great, thanks @marceloaqno

    I just started testing but I had to revert to 7d51087e589afb1296e71442fe2164807da399ef to have it working.
    Last commit SEGFAULT after

    Eth: Listening for connections on 0.0.0.0:5003
    

    Also, do you have an updated initscript to launch it automatically at boot? It seems the one from the old PiGateway is not working very well with this one. For now I just added a cronjob.


  • Code Contributor

    @emc2 Could you give more information about your setup? I wasn't able to reproduce the error.

    For the initscript, I will try to add an updated version for systemd.


  • Hardware Contributor

    So I did a few tests, one of my setup is working on the last commit, the other not. Both are model B.

    • Working Pi:
      Domoticz image, upgraded and up to date wheezy

    • Commit 7d51087e589afb1296e71442fe2164807da399ef Pi:
      Regular (non-Domoticz) old wheezy image updated to jessie

    All are up to date for all package on apt and firmware is up to date for rpi-update

    Linux domoticz 4.4.15+ #897 Tue Jul 12 18:38:58 BST 2016 armv6l GNU/Linux
    

    My bet is that my "non-working" Pi, wich is also my guinea pig Pi, is missing a dependency or something. Let me know if I can get you some logs to troubleshoot, but it may be very specific to this setup so may not be worthwhile investigation unless a common factor start to emerge.

    Anyways, thanks for the port! 👍



  • @marceloaqno

    very nice fork. but... i can't compile it:

    git clone https://github.com/marceloaqno/MySensors.git
    cd MySensors
    ./configure --my-gateway=mqtt --my-rf24-channel=1 --my-rf24-pa-level=RF24_PA_MAX --my-controller-ip-address=127,0,0,1 --my-mqtt-client-id=MyGW2 --my-mqtt-publish-topic-prefix="MyGW2out" --my-mqtt-subscribe-topic-prefix="MyGW2in"
    make
    
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DLINUX -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=MyGW2in -DMY_MQTT_PUBLISH_TOPIC_PREFIX=MyGW2out -DMY_MQTT_CLIENT_ID=MyGW2 -DMY_CONTROLLER_IP_ADDRESS=127,0,0,1 -DMY_RF24_PA_LEVEL=RF24_PA_MAX -DMY_RF24_CHANNEL=1  -I. -I./core -I./drivers/Linux -I/usr/local/include/RF24 -MMD -c -o drivers/Linux/EthernetClient.o drivers/Linux/EthernetClient.cpp
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DLINUX -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=MyGW2in -DMY_MQTT_PUBLISH_TOPIC_PREFIX=MyGW2out -DMY_MQTT_CLIENT_ID=MyGW2 -DMY_CONTROLLER_IP_ADDRESS=127,0,0,1 -DMY_RF24_PA_LEVEL=RF24_PA_MAX -DMY_RF24_CHANNEL=1  -I. -I./core -I./drivers/Linux -I/usr/local/include/RF24 -MMD -c -o drivers/Linux/compatibility.o drivers/Linux/compatibility.cpp
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DLINUX -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=MyGW2in -DMY_MQTT_PUBLISH_TOPIC_PREFIX=MyGW2out -DMY_MQTT_CLIENT_ID=MyGW2 -DMY_CONTROLLER_IP_ADDRESS=127,0,0,1 -DMY_RF24_PA_LEVEL=RF24_PA_MAX -DMY_RF24_CHANNEL=1  -I. -I./core -I./drivers/Linux -I/usr/local/include/RF24 -MMD -c -o drivers/Linux/IPAddress.o drivers/Linux/IPAddress.cpp
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DLINUX -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=MyGW2in -DMY_MQTT_PUBLISH_TOPIC_PREFIX=MyGW2out -DMY_MQTT_CLIENT_ID=MyGW2 -DMY_CONTROLLER_IP_ADDRESS=127,0,0,1 -DMY_RF24_PA_LEVEL=RF24_PA_MAX -DMY_RF24_CHANNEL=1  -I. -I./core -I./drivers/Linux -I/usr/local/include/RF24 -MMD -c -o drivers/Linux/EthernetServer.o drivers/Linux/EthernetServer.cpp
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DLINUX -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=MyGW2in -DMY_MQTT_PUBLISH_TOPIC_PREFIX=MyGW2out -DMY_MQTT_CLIENT_ID=MyGW2 -DMY_CONTROLLER_IP_ADDRESS=127,0,0,1 -DMY_RF24_PA_LEVEL=RF24_PA_MAX -DMY_RF24_CHANNEL=1  -I. -I./core -I./drivers/Linux -I/usr/local/include/RF24 -MMD -c -o examples_linux/mysGateway.o examples_linux/mysGateway.cpp
    ./core/MyProtocolMySensors.cpp: In function ‘bool protocolMQTTParse(MyMessage&, char*, uint8_t*, unsigned int)’:
    <command-line>:0:32: error: ‘MyGW2in’ was not declared in this scope
    ./core/MyProtocolMySensors.cpp:125:21: note: in expansion of macro ‘MY_MQTT_SUBSCRIBE_TOPIC_PREFIX’
         if (strcmp(str, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) != 0) {
                         ^
    In file included from ./MySensors.h:225:0,
                     from examples_linux/mysGateway.cpp:44:
    ./drivers/PubSubClient/PubSubClient.cpp: In member function ‘boolean PubSubClient::connect(const char*, const char*, const char*, const char*, uint8_t, boolean, const char*)’:
    ./drivers/PubSubClient/PubSubClient.cpp:176:55: error: ‘millis’ was not declared in this scope
                 lastInActivity = lastOutActivity = millis();
                                                           ^
    ./drivers/PubSubClient/PubSubClient.cpp: In member function ‘boolean PubSubClient::readByte(uint8_t*)’:
    ./drivers/PubSubClient/PubSubClient.cpp:210:37: error: ‘millis’ was not declared in this scope
        uint32_t previousMillis = millis();
                                         ^
    ./drivers/PubSubClient/PubSubClient.cpp: In member function ‘boolean PubSubClient::loop()’:
    ./drivers/PubSubClient/PubSubClient.cpp:284:34: error: ‘millis’ was not declared in this scope
             unsigned long t = millis();
                                      ^
    
    

    and more, more similar errors. with --my-gateway=ethernet compiled fine


  • Code Contributor

    @b0rmann It should work now. Thank you for reporting this.



  • Do I get it right that this is a RPi gateway with directly connected RF24L01+ tranceiver with support for both ethernet and MQTT?

    If so, is there a guide somewhere on how to set this all up?


  • Code Contributor

    @ericvdb That's right. I hope to add support for RFM69, Serial and software signing very soon.

    To use, clone the raspberryPi port for MySensors 2.0:

    git clone https://github.com/marceloaqno/MySensors.git
    cd MySensors
    

    To configure it, take a look at the options available within configure:

    ./configure --help
    

    For other options, you may have to edit the sample file example_linux/mysGateway.cpp, and uncoment what you need.

    Once done, run:

    make
    sudo make install
    

    To run the gateway you need to be root or use sudo:

    sudo msyGateway -h
    

    For wiring, follow this guide:
    https://forum.mysensors.org/topic/2437/step-by-step-procedure-to-connect-the-nrf24l01-to-the-gpio-pins-and-use-the-raspberry-as-a-serial-gateway-mysensors-1-x



  • @marceloaqno thanks, will try this asap. What about the status leds, is that supported?


  • Code Contributor

    @ericvdb sorry, no support for status led.



  • @marceloaqno

    1. configuration read/save bug:
    Aug 22 08:52:47 pi systemd[1]: Starting MySensors Gateway daemon...
    Aug 22 08:52:47 pi systemd[1]: Started MySensors Gateway daemon.
    Aug 22 08:52:47 pi mysGateway[22735]: Config file /tmp/MySensorGateway.cfg is not the correct size of 1024.  Please remove the file and a new one will be created.
    Aug 22 08:52:47 pi systemd[1]: mysgateway.service: main process exited, code=exited, status=1/FAILURE
    Aug 22 08:52:47 pi systemd[1]: Unit mysgateway.service entered failed state.
    
    root@pi:~# ls -la /tmp/MySensorGateway.cfg 
    -rw-r--r-- 1 root root 828 Aug 22 08:50 /tmp/MySensorGateway.cfg
    

    gateway starting only after manual removing old (bad sized) config

    p.s. content of config:

    0000000  ff ff 48 05 02 00 ac 43  01 00 48 05 02 00 f0 02  |..H....C..H.....|
    00000010  02 00 00 00 00 00 00 03  02 00 05 00 00 00 00 26  |...............&|
    00000020  01 00 02 00 00 00 01 00  00 02 02 00 00 00 00 00  |................|
    00000030  00 00 00 00 00 00 38 29  01 00 00 00 00 00 00 00  |......8)........|
    00000040  00 00 00 00 00 00 00 00  f9 76 00 00 00 00 94 62  |.........v.....b|
    00000050  c5 76 00 b0 d7 76 b4 fe  cd 7e 01 00 00 00 e0 24  |.v...v...~.....$|
    00000060  01 00 20 d0 a4 76 00 00  f8 76 00 00 00 00 00 00  |.. ..v...v......|
    00000070  00 00 38 29 01 00 00 00  00 00 00 00 00 00 00 00  |..8)............|
    00000080  00 00 00 00 f9 76 00 00  00 00 d7 84 d8 38 e7 1b  |.....v.......8..|
    00000090  d0 30 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |.0..............|
    000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
    000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
    000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
    000000d0  00 00 ff ff ff ff ff ff  ff ff 00 00 00 00 10 0b  |................|
    000000e0  f9 76 00 f0 e4 76 18 42  0d 00 ff ff ff ff 00 00  |.v...v.B........|
    000000f0  00 00 28 9e c4 76 00 00  f8 76 00 00 00 00 b8 f3  |..(..v...v......|
    00000100  f6 76 00 d4 a4 76 01 00  00 00 01 00 00 00 00 00  |.v...v..........|
    00000110  00 00 01 00 00 00 48 4e  c4 76 a4 ae f2 76 1c ff  |......HN.v...v..|
    00000120  f1 76 01 00 00 00 58 09  f9 76 00 00 00 00 d4 02  |.v....X..v......|
    00000130  02 00 c0 c4 a4 76 00 00  00 00 7c 0e 01 00 01 00  |.....v....|.....|
    00000140  00 00 00 00 00 00 b8 f3  f6 76 20 d0 a4 76 01 00  |.........v ..v..|
    00000150  00 00 01 00 00 00 00 00  00 00 00 a0 01 00 28 9e  |..............(.|
    00000160  c4 76 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |.v..............|
    00000170  00 00 00 00 00 00 00 00  00 00 00 00 f9 76 50 5f  |.............vP_|
    00000180  f7 76 00 00 00 00 00 00  00 00 38 29 01 00 00 00  |.v........8)....|
    00000190  00 00 00 00 00 00 64 29  01 00 88 ef 01 00 08 04  |......d)........|
    000001a0  f7 76 b4 fe cd 7e 86 ff  cd 7e 00 00 00 00 a0 ff  |.v...~...~......|
    000001b0  cd 7e 00 00 00 00 21 00  00 00 00 20 d2 7e 10 00  |.~....!.... .~..|
    000001c0  00 00 d6 b0 3f 00 06 00  00 00 00 10 00 00 11 00  |....?...........|
    000001d0  00 00 64 00 00 00 03 00  00 00 34 00 01 00 04 00  |..d.......4.....|
    000001e0  00 00 20 00 00 00 05 00  00 00 08 00 00 00 07 00  |.. .............|
    000001f0  00 00 00 00 f6 76 08 00  00 00 00 00 00 00 09 00  |.....v..........|
    00000200  00 00 38 29 01 00 0b 00  00 00 00 00 00 00 0c 00  |..8)............|
    00000210  00 00 00 00 00 00 0d 00  00 00 00 00 00 00 0e 00  |................|
    00000220  00 00 00 00 00 00 17 00  00 00 00 00 00 00 19 00  |................|
    00000230  00 00 72 ff cd 7e 1a 00  00 00 00 00 00 00 1f 00  |..r..~..........|
    00000240  00 00 e2 ff cd 7e 0f 00  00 00 82 ff cd 7e 00 00  |.....~.......~..|
    00000250  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
    00000260  00 00 00 00 49 3b f4 2c  b7 79 15 46 6b 69 82 6b  |....I;.,.y.Fki.k|
    00000270  8d d1 16 fc 76 37 6c 00  2f 75 73 72 2f 6c 6f 63  |....v7l./usr/loc|
    00000280  61 6c 2f 62 69 6e 2f 6d  79 73 47 61 74 65 77 61  |al/bin/mysGatewa|
    00000290  79 00 50 41 54 48 3d 2f  75 73 72 2f 6c 6f 63 61  |y.PATH=/usr/loca|
    000002a0  6c 2f 73 62 69 6e 3a 2f  75 73 72 2f 6c 6f 63 61  |l/sbin:/usr/loca|
    000002b0  6c 2f 62 69 6e 3a 2f 75  73 72 2f 73 62 69 6e 3a  |l/bin:/usr/sbin:|
    000002c0  2f 75 73 72 2f 62 69 6e  3a 2f 73 62 69 6e 3a 2f  |/usr/bin:/sbin:/|
    000002d0  62 69 6e 00 2f 75 73 72  2f 6c 6f 63 61 6c 2f 62  |bin./usr/local/b|
    000002e0  69 6e 2f 6d 79 73 47 61  74 65 77 61 79 00 00 00  |in/mysGateway...|
    000002f0  00 00                                             |..|
    


    1. routing problems?
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:READ,1-1-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:BC
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:FPAR REQ,ID=1
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:CHKUPL:OK,FCTRL
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:GWL OK
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:SEND,0-0-1-1,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:READ,3-3-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:BC
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:FPAR REQ,ID=3
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:CHKUPL:OK,FCTRL
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:GWL OK
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:SEND,0-0-3-3,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:READ,2-2-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:BC
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:FPAR REQ,ID=2
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:CHKUPL:OK,FCTRL
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:GWL OK
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:SEND,0-0-2-2,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:READ,2-2-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:BC
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:FPAR REQ,ID=2
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:CHKUPL:OK,FCTRL
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:GWL OK
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:SEND,0-0-2-2,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:READ,1-1-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:BC
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:FPAR REQ,ID=1
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:CHKUPL:OK,FCTRL
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:GWL OK
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:SEND,0-0-1-1,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:READ,3-3-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:BC
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:FPAR REQ,ID=3
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:CHKUPL:OK,FCTRL
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:GWL OK
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:SEND,0-0-3-3,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:READ,2-2-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:BC
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:FPAR REQ,ID=2
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:CHKUPL:OK,FCTRL
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:GWL OK
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:SEND,0-0-2-2,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:READ,3-3-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:BC
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:FPAR REQ,ID=3
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:CHKUPL:OK,FCTRL
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:GWL OK
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:SEND,0-0-3-3,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:READ,2-2-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:BC
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:FPAR REQ,ID=2
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:CHKUPL:OK,FCTRL
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:GWL OK
    Aug 22 09:02:16 pi mysGateway[22785]: TSF:MSG:SEND,0-0-2-2,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    
    

  • Code Contributor

    @b0rmann Fixed a bug with the config file. Please remove your MySensorGateway.cfg and let the gateway re-create it.
    Also the default config file name was changed to /etc/mysensors.dat

    For the routing problem, do you have the output from the nodes that are communicating with the gateway?



  • @marceloaqno

    it was not a problem with the routing, but the powering nrf24 from 3v3 rpi output. It solved a separate power source



  • I'm trying to get this to work, and it looked good. But after a day of running my Pi3 with Domoticz stopped answering to anything. Couldn't even connect with SSH.
    So now I need to start to troubleshoot. But I wonder if mysGateway produces a log somewhere? And where can I find the MySensorGateway.cfg? It is not in /tmp.

    After restart of the Pi3 I always get a error from Domoticz about not being able to send the command, although it does get through anyway.
    Don't know if mysGateway is the problem, but I need to gather all the logs I can find to figure it out.


  • Code Contributor

    @raptorjr MySensorGateway.cfg was renamed to mysensors.dat in the last version. The default directory that the gateway keeps the file is /etc. The file is used mostly to keep the nodes routes, so you won't find anything useful there. Which linux distro/version you're using in your RPi?



  • @marceloaqno

    Thank you. I thought that the .cfg file contained some information about a log file, but now I know it's purpose 😃

    I'm using a SD card image I found at the Domoticz site, preinstalled with Domoticz.

    Linux raspberrypi 4.1.18-v7+ #846 SMP Thu Feb 25 14:22:53 GMT 2016 armv7l GNU/Linux

    The problem could be with Domoticz also, but since I thought that mysGateway is still kind of beta I would start to look for the problem there.

    Now I found a entry in the Domoticz error log:
    2016-08-26 19:31:00.663 Error: Gateway hardware (4) thread seems to have ended unexpectedly

    So it seems that something maybe happened with the mysController. Maybe not died, but stopped answering and locking the whole Pi?
    Or if that error refers to some internal Domoticz gateway thread.


  • Code Contributor

    @raptorjr you could try to pipe the gateway output to a file starting it manually:

    sudo mysGateway &> /tmp/mysensors.log &
    


  • Would it be possible to enable both the Serial and Ethernet communication at the same time in the gateway? I'm about to try PiDome as a controller. And it seems that it only have support for Serial gateway. But the Ethernet gateway is so practical to use when I need to debug and use MYScontroller to connect and see what is happening. Or if I would like to try OTA updates of my nodes.


  • Mod

    @raptorjr some people have used nodered to "split" the communication to more than one controller. NodeRed has the ability to prevent certain types of messages. If two controllers are connected to the same gateway without filtering, both controllers will respond which might be very confusing for the node.

    https://forum.mysensors.org/topic/4112/is-it-possible-to-connect-an-ethernet-gateway-to-node-red-and-share-it/ is a pretty good place to start



  • @mfalkvidd

    Thank you. Maybe I should just try out PiDome first with serial gateway 😃

    But anyway, I thought that mysGateway would create something like /dev/ttyMySensorsGateway that I could then use, or ln to something like ttyUSB20, and add it in PiDome.

    But after compiling and installing mysGateway with serial support I only get a a error "Unable to open the serial port /dev/ttyUSB0". Am I thinking the wrong way? Isn't mysGateway supposed to work like the old Raspberry MySensors gateway?


  • Code Contributor

    @raptorjr Sorry, pseudo tty isn't supported. I will try to add it till the end of the day.



  • @marceloaqno

    What does the serial gateway do then? Can I use it as it is today with PiDomo and a RasberryPi? Or do I need to make a dedicated stand-alone serial gateway with a Arduino and a NRF?


  • Code Contributor

    @raptorjr
    In the current state, serial gateway on RPi can only use a "real" serial port like /dev/ttyAMA0 (gpio pins) or (if an arduino is connected or a USB->Serial adapter) /dev/ttyACM0. To use PiDomo you will need to put an Arduino to the mix.



  • @marceloaqno

    Thank you. I'll have to wait for pseudo tty or for PiDome to get support for Ethernet gateway.


  • Code Contributor

    @raptorjr
    I think PiDome also supports MQTT Gateway. Did you try that?



  • @marceloaqno

    I don't really understands what MQTT is and how to use it. But maybe I'll try that. Would like to see how PiDome works and if I like it better than Domoticz.


  • Code Contributor

    @raptorjr PiDome should work now (https://forum.mysensors.org/topic/2389/added-support-for-local-mysensors-rpi-direct-radio-connection).

    You need to add --my-serial-is-pty when running ./configure or uncomment the line #define MY_IS_SERIAL_PTY in mysGateway.cpp.



  • @marceloaqno

    Wow. That was fast work 😃

    Trying it now and the /dev/ttyMySensorsGateway is created. Followed the guide in the link you provided. Everything goes great until the last step. I don't see the message "Gateway startup complete". So I don't know if I have any communication between PiDome and the gateway?

    I'll start reading forums and see if I can find a solution. Or if I missed something.



  • @marceloaqno I've got the MysGateway configured and built to be an MQTT Gateway. I have a node (MySensors v2.01) sending temperature, humidity and voltage data to the Gateway. Looking at the stdout on the Raspberry Pi I can see that the information is being correctly received but there seems to be a problem with the published messages. I'm getting "send: Broken pipe" messages. I've copied and pasted some of the MysGateway stdout terminal output below. Do you have any insights on what might be going wrong?

    Thanks very much

    Sending message on topic: MyGW2out/0/255/0/0/18
    TSF:MSG:READ,20-20-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    TSF:MSG:BC
    TSF:MSG:FPAR REQ,ID=20
    TSF:CHKUPL:OK
    TSF:MSG:GWL OK
    TSF:MSG:SEND,0-0-20-20,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    TSF:MSG:READ,20-20-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    TSF:MSG:PINGED,ID=20,HP=1
    TSF:MSG:SEND,0-0-20-20,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1
    TSF:MSG:READ,20-20-0,s=255,c=3,t=12,pt=0,l=3,sg=0:0.5
    Sending message on topic: MyGW2out/20/255/3/0/12
    send: Broken pipe
    Attempting MQTT connection...
    MQTT connected
    Sending message on topic: MyGW2out/0/255/0/0/18
    TSF:MSG:READ,20-20-0,s=2,c=0,t=23,pt=0,l=0,sg=0:
    Sending message on topic: MyGW2out/20/2/0/0/23
    TSF:MSG:READ,20-20-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2
    TSF:MSG:SEND,0-0-20-20,s=255,c=3,t=27,pt=1,l=1,sg=0,ft=0,st=OK:1
    TSF:MSG:READ,20-20-0,s=1,c=1,t=0,pt=7,l=5,sg=0:19.9
    Sending message on topic: MyGW2out/20/1/1/0/0
    send: Broken pipe
    Attempting MQTT connection...
    MQTT connected
    Sending message on topic: MyGW2out/0/255/0/0/18
    TSF:MSG:READ,20-20-0,s=2,c=1,t=38,pt=7,l=5,sg=0:3319.0
    Sending message on topic: MyGW2out/20/2/1/0/38
    send: Broken pipe
    Attempting MQTT connection...
    MQTT connected
    Sending message on topic: MyGW2out/0/255/0/0/18
    TSF:MSG:READ,20-20-0,s=0,c=1,t=1,pt=7,l=5,sg=0:58.6
    Sending message on topic: MyGW2out/20/0/1/0/1
    send: Broken pipe
    Attempting MQTT connection...
    MQTT connected
    Sending message on topic: MyGW2out/0/255/0/0/18



  • feature request: logging via syslog (journald). or unbuffered debug output to stdio



  • @marceloaqno

    I think there may be a memory leak in the gateway. While using it as a ethernet gateway I loose about 100Mb every day, if my only node is turned on. After a few days I can't even login with SSH and need to remove the power to my Pi3 to reboot it.

    If I turn off my node, memory usage is normal. So it seems to have something to to when messages is received/transmitted. Is there anything I can do to get more details where the problem could be?

    I'm using the image from Domoticz where everything is installed, and have only added mysGateway.


  • Code Contributor

    @raptorjr @hawk_2050 I'll check.
    @b0rmann I'll do something about it.



  • @raptorjr

    gateway running 8 days:

    pi@pi:~$ ls -ld /proc/`pidof mysGateway`
    dr-xr-xr-x 7 root root 0 Aug 30 22:40 /proc/3935
    

    memory consumption (peak) - 22M

    pi@pi:~$ cat /proc/`pidof mysGateway`/status
    Name:   mysGateway
    State:  S (sleeping)
    Tgid:   3935
    Ngid:   0
    Pid:    3935
    PPid:   1
    TracerPid:      0
    Uid:    0       0       0       0
    Gid:    0       0       0       0
    FDSize: 256
    Groups:
    NStgid: 3935
    NSpid:  3935
    NSpgid: 3935
    NSsid:  3935
    VmPeak:    22108 kB
    VmSize:    22108 kB
    VmLck:         0 kB
    VmPin:         0 kB
    VmHWM:      3088 kB
    VmRSS:      3088 kB
    VmData:      236 kB
    VmStk:       136 kB
    VmExe:        80 kB
    VmLib:      4392 kB
    VmPTE:        30 kB
    VmPMD:         0 kB
    VmSwap:        0 kB
    Threads:        1
    SigQ:   0/7339
    SigPnd: 0000000000000000
    ShdPnd: 0000000000000000
    SigBlk: 0000000000000000
    SigIgn: 0000000000001000
    SigCgt: 0000000180004002
    CapInh: 0000000000000000
    CapPrm: 0000003fffffffff
    CapEff: 0000003fffffffff
    CapBnd: 0000003fffffffff
    Seccomp:        0
    Cpus_allowed:   f
    Cpus_allowed_list:      0-3
    Mems_allowed:   1
    Mems_allowed_list:      0
    voluntary_ctxt_switches:        71974874
    nonvoluntary_ctxt_switches:     167964
    


  • @marceloaqno Hi, could you please explain to me what the steps are to compile it for RPi3?
    I went here - https://github.com/marceloaqno/Raspberry
    Downloaded and tried to compile. The following error has come up:

    pi@m:~/Raspberry-GW $ make all
    make -C librf24-bcm
    make[1]: Entering directory '/home/pi/Raspberry-GW/librf24-bcm'
    cp utility/RPi/includes.h utility/includes.h
    g++ -Wall -fPIC -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv7-a -mtune=arm1176jzf-s -c RF24.cpp
    g++ -Wall -fPIC -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv7-a -mtune=arm1176jzf-s -c utility/RPi/spi.cpp
    gcc -Wall -fPIC -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv7-a -mtune=arm1176jzf-s -c utility/RPi/bcm2835.c
    g++ -Wall -fPIC -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv7-a -mtune=arm1176jzf-s -c utility/RPi/interrupt.c
    g++ -shared -Wl,-soname,librf24-bcm.so.1 -pthread -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv7-a -mtune=arm1176jzf-s -o librf24-bcm.so.1.0 RF24.o spi.o bcm2835.o interrupt.o
    make[1]: Leaving directory '/home/pi/Raspberry-GW/librf24-bcm'
    g++ -std=c++0x -g -Wall -Wextra -Ofast -mfpu=vfp -mfloat-abi=hard -mtune=arm1176jzf-s -Ilibmysensors -Ilibrf24-bcm -pthread -DRASPBERRYPI_ARCH  -march=armv7-a -MMD -c -o src/Basic/PiGatewaySample.o src/Basic/PiGatewaySample.cpp
    src/Basic/PiGatewaySample.cpp: In function ‘int main()’:
    src/Basic/PiGatewaySample.cpp:63:15: error: ‘usleep’ was not declared in this scope
       usleep(10000); // 10ms
                   ^
    Makefile:103: recipe for target 'src/Basic/PiGatewaySample.o' failed
    make: *** [src/Basic/PiGatewaySample.o] Error 1
    

    Thanks



  • OK, I manage to install it finally.

    However, again I have a problem:

    ./configure --my-gateway=ethernet --my-rf24-channel=1 --my-rf24-pa-level=RF24_PA_MAX --my-controller-ip-address=127,0,0,1
    

    when I start it I have the following in the log:

    failed to bind
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    accept: Bad file descriptor
    
    
    

  • Code Contributor

    Add some options to the gateway execution:

    # ./examples_linux/mysGateway -h
    Usage: mysGateway [options]
    
    Options:
    -h            Display a short summary of all program options.
    -d            Enable debug.
    -b            Become a daemon.
    

    Debug is now disabled by default.
    You can't run it as a linux daemon if debug is enabled.
    When daemonized all messages will be print to syslog.



  • This post is deleted!


  • @marceloaqno Interesting. When I execute "mysGateway -h" I get the following:

    pi@m:~/MySensors/examples_linux $ mysGateway -h
    MCO:BGN:INIT GW,CP=RNNG---,VER=2.0.1-beta
    TSM:INIT
    Segmentation fault
    

    What does "Segmentation fault' mean please?


  • Code Contributor

    @alexsh1 You must be root to run the gateway:

    $ sudo mysGateway
    

    It seems that you are not using the latest version, -h should have shown you the options list.



  • @marceloaqno I have the latest version (downloaded yesterday). Thanks very much for your help. I got the following:

    pi@m:~/MySensors/examples_linux $ sudo mysGateway -h
    MCO:BGN:INIT GW,CP=RNNG---,VER=2.0.1-beta
    TSM:INIT
    TSM:INIT:TSP OK
    TSM:INIT:GW MODE
    TSM:READY
    MCO:REG:NOT NEEDED
    MCO:BGN:STP
    MCO:BGN:INIT OK,ID=0,PAR=0,DIS=0,REG=1
    

    In Domoticz:

    2016-09-09 09:32:26.032 TCP: Reconnecting... 
    2016-09-09 09:32:26.032 MySensors: connected to: 127.0.0.1:5003 
    

    I added MySensors with LAN in Domoticz (port 5003), but here a problem. I can see the node and the GW communicating:

    GW:

    TSF:MSG:READ,255-255-0,s=255,c=3,t=3,pt=0,l=0,sg=0:
    TSF:MSG:READ,255-255-0,s=255,c=3,t=3,pt=0,l=0,sg=0:
    TSF:MSG:READ,255-255-0,s=255,c=3,t=3,pt=0,l=0,sg=0:
    Client 0: 0;0;3;0;18;PING
    TSF:MSG:READ,255-255-0,s=255,c=3,t=3,pt=0,l=0,sg=0:
    TSF:MSG:READ,255-255-0,s=255,c=3,t=3,pt=0,l=0,sg=0:
    Client 0: 0;0;3;0;18;PING
    
    Starting sensor (RNNNA-, 2.0.0-beta)
    Radio init successful.
    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    Init complete, id=255, parent=0, distance=1
    requesting time
    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    requesting time
    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    requesting time
    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    requesting time
    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    requesting time
    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    
    

    The RF communication is fine, but I do not understand why Domoticz is not assigning ID.......

    EDIT: I can see in Domoticz in the Hardware section:

    MySensors Gateway with LAN interface
    Version: ? Setup
    

    Typically ? comes up when the controller is not recognised or not connected

    EDIT2:Deleted and started fresh. Unfortunately, now the log file is flooded with the following:

    
    mysGateway: Max number of ethernet clients reached.
    mysGateway: Max number of ethernet clients reached.
    mysGateway: Max number of ethernet clients reached.
    mysGateway: Max number of ethernet clients reached.
    mysGateway: Max number of ethernet clients reached.
    mysGateway: Max number of ethernet clients reached.
    mysGateway: Max number of ethernet clients reached.
    mysGateway: Max number of ethernet clients reached.
    mysGateway: Max number of ethernet clients reached.
    mysGateway: Max number of ethernet clients reached.
    mysGateway: Max number of ethernet clients reached.
    mysGateway: Max number of ethernet clients reached.
    mysGateway: Max number of ethernet clients reached.
    

  • Code Contributor

    @alexsh1 There is a bug with --my-controller-ip-address, I'm not sure if it's your case, but try to avoid it.

    I tried Domoticz here and everything seems fine:

    MySensors Gateway with LAN interface
    Version: 2.0.1-beta (Setup)
    

    I recommend you to start from scratch, re-download the gateway from here:
    https://github.com/marceloaqno/MySensors/tree/dev-raspberrypi



  • @marceloaqno OK, this must be the reason. I have tried the serial setup and it worked with a little tweak:

    /dev/ttyUSB20 -> /dev/ttyMySensorsGateway
    

    For whatever reason Domoticz did not see ttyMySensorsGateway so I had to create ttyUSB20


  • Hardware Contributor

    @alexsh1 said:

    For whatever reason Domoticz did not see ttyMySensorsGateway so I had to create ttyUSB20

    Domoticz seems to only look for ttyUSB* interfaces. One easy trick is to run ./configure with this option so you don't have to worry with symlinking

    ./configure --my-serial-pty=/dev/ttyUSBMySensorsGateway
    

    BTW @marceloaqno , what does the option --my-serial-is-pty exactly do?
    So far I've been running the gateway in ethernet mode for a little while and it's working flawlessly, thanks a lot for this port.



  • @emc2 said:

    ./configure --my-serial-pty=/dev/ttyUSBMySensorsGateway

    Exallent fix! Thanks

    @marceloaqno I can confirm that the Ethernet GW works fine without --my-controller-ip-address
    MAny thanks for your port and help!


  • Hardware Contributor

    @alexsh1 said:
    I can confirm that the Ethernet GW works fine without --my-controller-ip-address

    Just a guess, I see on your previous post that you used --my-controller-ip-address=127,0,0,1 it may have been a typo here, but did you try with --my-controller-ip-address=127.0.0.1? (dots instead of commas in the IP)?



  • @emc2 No, this is not a typo. This is a format. And yes, I have tried it with dots (127.0.0.1) - it did not compile.


  • Hardware Contributor

    Good to know then, thanks!



  • BTW, I am using a nice adapter for nrf24l01+ LNA+PA designed by @GertSanders :
    https://www.openhardware.io/view/17/Raspberry-Pi2-GPIO-interface-for-NRF24L01

    Works nicely with this port and RPi 3.


  • Hardware Contributor

    Same, I had one Pi with GertSanders adapter and now switched to the SMD versions to fit nicely in my case.
    https://www.openhardware.io/view/105/MySRaspiGW
    https://www.openhardware.io/view/116/MySRaspiGW-PALNA

    Interestingly the regular one is working better than the PA+LNA version since moved to 2.0, at least in term of sending commands. Receiving is fine. Compiling with --my-rf24-pa-level=RF24_PA_LOW helps a lot. It seems 2.0 is really more power hungry, any hope to optimize this?

    Which remind me of one thing, sorry to bother you again @marceloaqno (how) is the --my-rf24-irq-pin=<PIN> working?
    I installed wiringpi to get rid of the wiringPiISR: Can't find gpio program but I'm not sure if it's supposed to do anything in the long term.
    I was thinking updating the design of my PCB to link BCM 24 (pin 18) to the IRQ pin of the radio module but it's unclear to me if the IRQ will ever actually be used on the gateway.


  • Code Contributor

    Those are cool adapters, I need to build one for me.

    @emc2 It's no bother at all!
    Using nrf24 IRQ pin can give you more throughput and less chance of losing messages. It makes more sense to use if you have many sensors or need to transfer binary data (https://forum.mysensors.org/topic/3594/solar-powered-observation-nesting-box-network/).

    --my-serial-is-pty will simulate a serial port and create a symbolic link to it instead of using a real one.


  • Hardware Contributor

    @marceloaqno Thanks for the heads up.
    I'm totally happy with the ethernet version, but as it seems @hek is in the process of writing guides on https://www.mysensors.org/build/raspberry I did a few tests.

    If I understood correctly (and it seems to work), to "replace" the 1.x serial gateway with the new one running the following command should work as is (/dev/ttyUSBMySensorsGateway can be renamed to /dev/ttyMySensorsGateway to be exactly as in 1.x or /dev/ttyUSB20 to bypass the symlink step)

    ./configure --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyUSBMySensorsGateway --my-rf24-pa-level=RF24_PA_LOW
    

    --my-rf24-pa-level=RF24_PA_LOW can be omitted, especially if not using a PA+LNA module, but it seems 2.0 is really more power hungry than 1.4.

    @marceloaqno said:

    Those are cool adapters, I need to build one for me.

    If you are interested by the SMD ones, PM me your address and I will happily send you something!



  • @marceloaqno The mechanism for assigning the pty serial port the specified group ownership doesn't appear to be working. The pty port is always created with root:root ownership. Can you (or anyone else) confirm whether this is working for you? I'm on a Raspberry Pi 2 running Raspian Jessie. Thanks.


  • Code Contributor

    @emc2 I appreciate the offer for the adapter, but my country's post is a little complicated (to say the least).

    @hawk_2050 /dev/ttyUSBMySensorsGateway (or any other parameter you pass to --my-serial-pty) is a symbolic link:

    $ ls -lah /dev/ttyMySensorsGateway
    lrwxrwxrwx 1 root root 10 Sep 16 12:39 /dev/ttyMySensorsGateway -> /dev/pts/2
    

    In this case it is pointing to /dev/pts/2 but can vary, and it's the one who holds the specified group ownership.


  • Hardware Contributor

    @marceloaqno Up to you. I don't mind giving it a shot, if I send you the pcb alone it will fit in a regular letter and should not even have to go through customs etc. Worst case scenario it won't reach you.



  • @marceloaqno , I assume your link for the wiring pinout behind the link is for Raspi 1 A+ with 26 pin header? Or for which version?

    I'd like to try this with raspi 2 B, would you have instructions how to wire it?

    Raspi2:
    raspi2 pinout
    Raspi1:
    raspi1 pinout

    Thanks



  • No, looking it again, it's vice versa, so yours is for Raspi2, right?




  • Code Contributor

    @ikkeT yes, these are the default pins.
    (SCK = 23, MISO = 21, MOSI = 19, CS = 24, CE = 22)



  • Yahooo! It works, finally. I bet my problem was Raspi1 all along. I never realized the pinouts in github were for raspi with 40 pins, b+/2/3. Thanks!


  • Code Contributor

    @ikkeT it should also work for Raspi1, I got one running fine here.



  • OK, then I just screwed up something. Thanks for the info, so I know I can do this also with my old raspi one day.


  • Code Contributor

    Update: Added support for status leds (RX/TX/ERR), you can enable it in examples_linux/mysGateway.cpp file.



  • Continuing the learning here, new questions... Thanks so far, I've now got the temp/hum/door messages sent and received from sensebender micro to raspi2. The next thing I would like to do is to send the messages as mqtt to the next box hosting some controller.

    How to get the mysGateway to send the stuff forward as mqtt? I tried to look into Makefile, MyConfig.h and such, but didn't quite figure out yet how to do that. Any pointers?

    So I'd like to have the following: sensebender -> radio -> raspi2 -> some box hosting the controller. Perhaps even outside of home, so routable traffic e.g. to OpenShift.com.

    Should I now somehow configure and build mysGateway to send stuff as MQTT, or pipe the traffic somehow to mqtt like mosqitto? How is this normally done if the controller server is not running on the gateway Raspi?

    Thanks for the patience, I'm just getting into all this interesting stuff 🙂


  • Mod

    @ikkeT I haven't tried but using nodered should be fairly simple and very flexible. This discussion might be useful: https://forum.mysensors.org/topic/2802/flow-to-turn-serialgateway-into-mqtt-serialgateway/



  • @ikkeT you can build the Raspberry Pi mysGateway as either Serial, Ethernet or MQTT by using appropriate commandline parameters with the configure script. Just do ./configure --help and you'll get a list of all the options available. Once you've chosen your options and run configure then you 'make'. An example of a set of options that will generate an MQTT Gateway is:
    ./configure --my-debug=enable --my-gateway=mqtt --my-rf24-channel=100 --my-rf24-pa-level=RF24_PA_LOW --my-controller-ip-address=127,0,0,1 --my-port=1883
    --my-mqtt-client-id=MyGW2 --my-mqtt-publish-topic-prefix="MyGW2out" --my-mqtt-subscribe-topic-prefix="MyGW2in"

    In this case my MQTT Broker is Mosquitto and is on the same Raspberry Pi hence the use of 127,0,0,1 for the specified --my-controller-ip-address. Change that as appropriate to your intended setup.

    Hope that helps.



  • @marceloaqno I have been trying to build this out by first building the RF24 library using the following:

    git clone https://github.com/TMRh20/RF24.git
    cd RF24
    make
    sudo make install
    

    However, this fails on the make command:

    Makefile:17: Makefile.inc: No such file or directory
    [Running configure]
    [SECTION] Detecting arm compilation environment.
      [OK] arm-linux-gnueabihf-gcc detected.
      [OK] arm-linux-gnueabihf-g++ detected.
    [SECTION] Detecting target machine.
    [OK] machine detected: SoC=BCM2836, Type=RPi2, CPU=armv7l.
    [SECTION] Detecting DRIVER
      [OK] DRIVER detected:RPi.
    [SECTION] Detecting OS.
      [INFO] OS detected:LINUX.
    [SECTION] Preparing configuration.
    [SECTION] Saving configuration.
    [OK] Finished.
    arm-linux-gnueabihf-g++ -fPIC -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -Ofast -Wall -pthread  -c RF24.cpp
    cc1plus: error: bad value (cortex-a7) for -mtune switch
    Makefile:40: recipe for target 'RF24.o' failed
    make: *** [RF24.o] Error 1
    

    I am not sure what to do here. Looks like the gcc does not support the cortex-a7? I am trying to run this on my RPi 2 B.


  • Code Contributor

    @wergeld I'm not sure why you are having this error, perhaps your version of gcc it's old? Did you try to update it?
    You can skip the installation of TMRh20/RF24, it is no longer necessary to build RPi port.



  • @marceloaqno said:

    @wergeld I'm not sure why you are having this error, perhaps your version of gcc it's old? Did you try to update it?
    You can skip the installation of TMRh20/RF24, it is no longer necessary to build RPi port.

    I have tried to update gcc but apt-get says it is already at latest version. I am upgrading to Jessie now as it has gcc 4.9 (I was running Wheezy with gcc 4.6).
    Is there an updated build instruction set? I am planning on using this as a serial gateway with Domoticz on same RPi.



  • @hawk_2050 thanks for the reminder! I recalled it was somehow configurable, but I forgot it was through . /configure options. I'll try after getting pir working also.


  • Code Contributor



  • @marceloaqno said:

    @wergeld I updated the building instructions:
    https://forum.mysensors.org/topic/2759/mysensors-raspberry-port-suggestions/26

    Success! Upgraded to Jessie and build worked fine. Now to reconnect my radio to the RPi pins directly to test.



  • @wergeld said:

    @marceloaqno said:

    @wergeld I updated the building instructions:
    https://forum.mysensors.org/topic/2759/mysensors-raspberry-port-suggestions/26

    Success! Upgraded to Jessie and build worked fine. Now to reconnect my radio to the RPi pins directly to test.

    Okay, using an RPi2B upgraded to Jessie from Wheezy I have successfully built and set the mysGateway as a daemon. My configuration was:

    ./configure --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyUSBMySensorsGateway --my-rf24-pa-level=RF24_PA_LOW
    

    This was immediately available in Domoticz under Hardware. I re-added the 2 nodes and away I went!

    Full command list:

    git clone https://github.com/marceloaqno/MySensors.git
    cd MySensors
    ./configure --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyUSBMySensorsGateway --my-rf24-pa-level=RF24_PA_LOW
    make
    sudo make install
    sudo mysGateway -b
    

    In Domoticz it lists this gateway as running:
    MySensors Gateway USB
    Version: 2.0.1-beta

    So far very happy with this setup. No wires and no extra arduino needed for serial gateway. Just the NRF+RPi interfacing via:
    https://www.openhardware.io/view/100/Raspberry-PI-NRF24l01-hat



  • @marceloaqno

    what am I doing wrong here?

    root@raspberrypi:/downloads/MySensors# ./configure --my-gateway=mqtt --my-mqtt-client-id=msgw --my-mqtt-publish-topic-prefix=mspub --my-mqtt-subscribe-topic-prefix=mssub --my-controller-ip-address=10.0.10.4 --my-port=1883
    [SECTION] Detecting target machine.
    [OK] machine detected: SoC=BCM2835, Type=RPi, CPU=armv6l, REV=000d.
    [OK] init system detected: systemd
    [SECTION] Saving configuration.
    [SECTION] Cleaning previous builds.
    [OK] Finished.
    root@raspberrypi:/downloads/MySensors# make
    cc  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/log.o drivers/Linux/log.c
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_LINUX -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=1883 -DMY_CONTROLLER_IP_ADDRESS=10,0,10,4 -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=\"mssub\" -DMY_MQTT_PUBLISH_TOPIC_PREFIX=\"mspub\" -DMY_MQTT_CLIENT_ID=\"msgw\"  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/noniso.o drivers/Linux/noniso.cpp
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_LINUX -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=1883 -DMY_CONTROLLER_IP_ADDRESS=10,0,10,4 -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=\"mssub\" -DMY_MQTT_PUBLISH_TOPIC_PREFIX=\"mspub\" -DMY_MQTT_CLIENT_ID=\"msgw\"  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/Print.o drivers/Linux/Print.cpp
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_LINUX -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=1883 -DMY_CONTROLLER_IP_ADDRESS=10,0,10,4 -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=\"mssub\" -DMY_MQTT_PUBLISH_TOPIC_PREFIX=\"mspub\" -DMY_MQTT_CLIENT_ID=\"msgw\"  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/EthernetClient.o drivers/Linux/EthernetClient.cpp
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_LINUX -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=1883 -DMY_CONTROLLER_IP_ADDRESS=10,0,10,4 -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=\"mssub\" -DMY_MQTT_PUBLISH_TOPIC_PREFIX=\"mspub\" -DMY_MQTT_CLIENT_ID=\"msgw\"  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/SerialPort.o drivers/Linux/SerialPort.cpp
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_LINUX -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=1883 -DMY_CONTROLLER_IP_ADDRESS=10,0,10,4 -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=\"mssub\" -DMY_MQTT_PUBLISH_TOPIC_PREFIX=\"mspub\" -DMY_MQTT_CLIENT_ID=\"msgw\"  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/Stream.o drivers/Linux/Stream.cpp
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_LINUX -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=1883 -DMY_CONTROLLER_IP_ADDRESS=10,0,10,4 -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=\"mssub\" -DMY_MQTT_PUBLISH_TOPIC_PREFIX=\"mspub\" -DMY_MQTT_CLIENT_ID=\"msgw\"  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/IPAddress.o drivers/Linux/IPAddress.cpp
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_LINUX -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=1883 -DMY_CONTROLLER_IP_ADDRESS=10,0,10,4 -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=\"mssub\" -DMY_MQTT_PUBLISH_TOPIC_PREFIX=\"mspub\" -DMY_MQTT_CLIENT_ID=\"msgw\"  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/compatibility.o drivers/Linux/compatibility.cpp
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_LINUX -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=1883 -DMY_CONTROLLER_IP_ADDRESS=10,0,10,4 -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=\"mssub\" -DMY_MQTT_PUBLISH_TOPIC_PREFIX=\"mspub\" -DMY_MQTT_CLIENT_ID=\"msgw\"  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/EthernetServer.o drivers/Linux/EthernetServer.cpp
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_LINUX -DMY_GATEWAY_MQTT_CLIENT -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=1883 -DMY_CONTROLLER_IP_ADDRESS=10,0,10,4 -DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=\"mssub\" -DMY_MQTT_PUBLISH_TOPIC_PREFIX=\"mspub\" -DMY_MQTT_CLIENT_ID=\"msgw\"  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o examples_linux/mysGateway.o examples_linux/mysGateway.cpp
    In file included from ./MySensors.h:287:0,
                     from examples_linux/mysGateway.cpp:60:
    ./core/MyTransport.cpp: In function âvoid transportProcessMessage()â:
    ./core/MyTransport.cpp:535:61: error: no matching function for call to âmin(uint8_t, unsigned int)â
      const uint8_t msgLength = min(mGetLength(_msg), MAX_PAYLOAD);
                                                                 ^
    ./core/MyTransport.cpp:535:61: note: candidates are:
    In file included from /usr/include/c++/4.9/bits/char_traits.h:39:0,
                     from /usr/include/c++/4.9/ios:40,
                     from /usr/include/c++/4.9/ostream:38,
                     from /usr/include/c++/4.9/iostream:39,
                     from examples_linux/mysGateway.cpp:20:
    /usr/include/c++/4.9/bits/stl_algobase.h:240:5: note: template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
         min(const _Tp& __a, const _Tp& __b, _Compare __comp)
         ^
    /usr/include/c++/4.9/bits/stl_algobase.h:240:5: note:   template argument deduction/substitution failed:
    In file included from ./MySensors.h:287:0,
                     from examples_linux/mysGateway.cpp:60:
    ./core/MyTransport.cpp:535:61: note:   deduced conflicting types for parameter âconst _Tpâ (âunsigned charâ and âunsigned intâ)
      const uint8_t msgLength = min(mGetLength(_msg), MAX_PAYLOAD);
                                                                 ^
    In file included from /usr/include/c++/4.9/bits/char_traits.h:39:0,
                     from /usr/include/c++/4.9/ios:40,
                     from /usr/include/c++/4.9/ostream:38,
                     from /usr/include/c++/4.9/iostream:39,
                     from examples_linux/mysGateway.cpp:20:
    /usr/include/c++/4.9/bits/stl_algobase.h:194:5: note: template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)
         min(const _Tp& __a, const _Tp& __b)
         ^
    /usr/include/c++/4.9/bits/stl_algobase.h:194:5: note:   template argument deduction/substitution failed:
    In file included from ./MySensors.h:287:0,
                     from examples_linux/mysGateway.cpp:60:
    ./core/MyTransport.cpp:535:61: note:   deduced conflicting types for parameter âconst _Tpâ (âunsigned charâ and âunsigned intâ)
      const uint8_t msgLength = min(mGetLength(_msg), MAX_PAYLOAD);
                                                                 ^
    ./core/MyTransport.cpp: In function âbool transportSendWrite(uint8_t, MyMessage&)â:
    ./core/MyTransport.cpp:826:82: error: no matching function for call to âmin(unsigned int, const uint8_t&)â
      bool result = transportSend(to, &message, min(MAX_MESSAGE_LENGTH, totalMsgLength));
                                                                                      ^
    ./core/MyTransport.cpp:826:82: note: candidates are:
    In file included from /usr/include/c++/4.9/bits/char_traits.h:39:0,
                     from /usr/include/c++/4.9/ios:40,
                     from /usr/include/c++/4.9/ostream:38,
                     from /usr/include/c++/4.9/iostream:39,
                     from examples_linux/mysGateway.cpp:20:
    /usr/include/c++/4.9/bits/stl_algobase.h:240:5: note: template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
         min(const _Tp& __a, const _Tp& __b, _Compare __comp)
         ^
    /usr/include/c++/4.9/bits/stl_algobase.h:240:5: note:   template argument deduction/substitution failed:
    In file included from ./MySensors.h:287:0,
                     from examples_linux/mysGateway.cpp:60:
    ./core/MyTransport.cpp:826:82: note:   deduced conflicting types for parameter âconst _Tpâ (âunsigned intâ and âuint8_t {aka unsigned char}â)
      bool result = transportSend(to, &message, min(MAX_MESSAGE_LENGTH, totalMsgLength));
                                                                                      ^
    In file included from /usr/include/c++/4.9/bits/char_traits.h:39:0,
                     from /usr/include/c++/4.9/ios:40,
                     from /usr/include/c++/4.9/ostream:38,
                     from /usr/include/c++/4.9/iostream:39,
                     from examples_linux/mysGateway.cpp:20:
    /usr/include/c++/4.9/bits/stl_algobase.h:194:5: note: template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)
         min(const _Tp& __a, const _Tp& __b)
         ^
    /usr/include/c++/4.9/bits/stl_algobase.h:194:5: note:   template argument deduction/substitution failed:
    In file included from ./MySensors.h:287:0,
                     from examples_linux/mysGateway.cpp:60:
    ./core/MyTransport.cpp:826:82: note:   deduced conflicting types for parameter âconst _Tpâ (âunsigned intâ and âuint8_t {aka unsigned char}â)
      bool result = transportSend(to, &message, min(MAX_MESSAGE_LENGTH, totalMsgLength));
                                                                                      ^
    Makefile:46: recipe for target 'examples_linux/mysGateway.o' failed
    make: *** [examples_linux/mysGateway.o] Error 1
    root@raspberrypi:/downloads/MySensors#
    

  • Code Contributor

    @ericvdb update your files from mysensors repository, this was fixed in #594



  • @marceloaqno said:

    Update: Added support for status leds (RX/TX/ERR), you can enable it in examples_linux/mysGateway.cpp file.

    // Flash leds on rx/tx/err
    //#define MY_DEFAULT_ERR_LED_PIN 12 // Error LED pin
    //#define MY_DEFAULT_RX_LED_PIN 16 // Receive LED pin
    //#define MY_DEFAULT_TX_LED_PIN 18 // Transmit LED pin

    What do I put there? RPi pin numbers or GPIO numbers?


  • Code Contributor

    @ericvdb In any type of pin configuration for the RPi, always use the physical pin number.


  • Code Contributor

    The RPi port was merged into mysensors official repository 🎉 (thank you to everyone who helped with this process 👏 ). For future discussion, please use this this topic.


Log in to reply
 

Suggested Topics

  • 1
  • 10
  • 2
  • 2
  • 2
  • 3

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts