💬 Building a Raspberry Pi Gateway


  • Mod

    @marceloaqno and the same from the controller to the gateway gives the same error on that port 😞


  • Code Contributor

    @Reza Yes, you can use rs485 in the RPi.

    ./configure --my-transport=rs485 --my-rs485-serial-port=<YOUR_SERIAL_PORT>
    

    For more options, run:

    ./configure -h
    

  • Code Contributor

    @LaMB95 No, I meant the options you used when you ran ./configure


  • Code Contributor

    @tiana
    "The Broadcom SoC has three independant SPI interfaces, however only one of these is brought out to the GPIO connector, and that one SPI interface has 2 Chip enable lines."
    More info here: https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=22608


  • Mod

    @marceloaqno from the docs I assume it is the gateway that has to open up port 5003 but I guess it does not because it can't connect to the ethernet (for some reason) or am I wrong?



  • @marceloaqno
    i means that without arduino and usb port, similar to raspberry gateway ( raspberry +nrf24)
    i means connect rs485 module to GPIO raspberry pi 🙂 with domoticz



  • @marceloaqno 0_1484505404805_Screen Shot 2017-01-15 at 10.36.17 PM.png

    I m sorry I m new to using a raspberry pi and its for a project.
    But if this is not what you asked for could you be a little more specific :$1_1484506047866_Screen Shot 2017-01-15 at 10.46.49 PM.png 0_1484506047866_Screen Shot 2017-01-15 at 10.46.35 PM.png



  • use sudo 😉


  • Mod

    Oh and one other thing, when I set the gateway up for MQTT it works.


  • Code Contributor

    @marceltrapman

    If you use the --my-controller-ip-address= option, the gateway will act as a client and attempt to conect to the supplied ip and port. If you want the gateway to open port 5003, omit this option.


  • Code Contributor

    @Reza You could connect the rs485 to the RPi UART and use the option --my-rs485-serial-port=/dev/ttyAMA0, but you need to turning off the UART functioning as a serial console.

    Or, to make things easier:
    rs485 <==> TTL/USB <==> RPi



  • @marceloaqno
    i am beginner and i can not turning off the UART functioning. . . also on some board usb port after power off/on lost and i should disconnect/connect cable... i test your steps serial gateway with raspberry and GPIO with virtual usb serial . and i see this problem solve and after power off/on gateway is connect .
    i suggest that you add this commands to page of rs485 gateway step by step and update this .
    (https://www.mysensors.org/build/rs485)

    I thank you for hard working and trying



  • @Reza

    if you want use rpi /dev/ttyAMA0 for rs485 gateway -

    1. remove string "console=serial0,115200" from /boot/cmdline.txt
    2. add strings "enable_uart=1" and "dtoverlay=pi3-disable-bt" to /boot/config.txt (only on rpi3)
    3. reboot raspi

  • Mod

    @marceloaqno nice, working now 👍

    Thank you...



  • @b0rmann
    thank you friend , but i am sorry i am very beginner in raspberry pi . because i use vera before and with raspberry and orange pi i use recently. so i need a full steps for a rs485 gateway(wiring and commands . . .) i dont know what is ttyAMA0 ! i use a serial gateway with usb port with raspberrypi 3 but i have some problem , but with a raspberrypi gateway and use a virtual serial port (ttyUSB020) all of my problem resolve. but i have problem with wireless. so i want have a wiring network. i want a full steps for setup a rs485 module with raspberrypi 3(wiring and steps for install...) thank you for help



  • Do I read that correctly, does this gateway also gives a ethernet link to a serial-only controller? How do I have to configure ip and port? In the build section I see no option to set them.



  • @LaMB95 said:

    @ericvdb

    0_1484579303843_Screen Shot 2017-01-16 at 7.08.05 PM.png

    Okay what could be the problem? :3


  • Code Contributor

    @Reza There are many guides on the web teaching how to connect and use rs485 with the RPi. I recommend you start with them and when you are sure it is working, you add MySensors to the equation.



  • @marceloaqno said:

    There are many guides on the web teaching how to connect and use rs485 with the RPi. I recommend you start with them and when you are sure it is working, you add MySensors to the equation.

    ok thank you 😞



  • @Anduril
    you will get all the build options for the mysgw with the command

    ./configure -help
    

    Here you can configure all options like serial and ethernet



  • just cloned and read the --help, but still I don't know how to use.
    To make it a litte less abstract: I have a ethernet gateway (ESP8266) running at 192.168.38.19 with port 5003 to connect to. I want to have this accessible by a serial-only controller on the raspberry.

    I tried to do this config and make afterwards, but starting gave only FAILs...

    ./configure --my-gateway=ethernet --my-controller-ip-address=192.168.38.19 --my-serial-is-pty --my-serial-pty=/dev/ttyMySensorsGateway
    
    ~/MySensors$ sudo ./bin/mysgw -d
    mysgw: Starting gateway...
    mysgw: Protocol version - 2.1.0
    mysgw: MCO:BGN:INIT GW,CP=RNNG---,VER=2.1.0
    mysgw: TSF:LRT:OK
    mysgw: TSM:INIT
    mysgw: TSF:WUR:MS=0
    mysgw: !TSM:INIT:TSP FAIL
    mysgw: TSM:FAIL:CNT=1
    mysgw: TSM:FAIL:PDT
    mysgw: TSM:FAIL:RE-INIT
    mysgw: TSM:INIT
    mysgw: !TSM:INIT:TSP FAIL
    mysgw: TSM:FAIL:CNT=2
    mysgw: TSM:FAIL:PDT
    mysgw: TSM:FAIL:RE-INIT
    mysgw: TSM:INIT
    mysgw: !TSM:INIT:TSP FAIL
    mysgw: TSM:FAIL:CNT=3
    mysgw: TSM:FAIL:PDT
    mysgw: TSM:FAIL:RE-INIT
    mysgw: TSM:INIT
    mysgw: !TSM:INIT:TSP FAIL
    mysgw: TSM:FAIL:CNT=4
    mysgw: TSM:FAIL:PDT
    

    I think my config is wrong and it tries to connect to a nrf24 at the rpi. So what's the correct config for my case?

    Thanks in advance.


  • Mod

    @Anduril
    Why are you using an esp8266 as a serial gateway? Wouldn't it be easier to use a normal UNO?



  • I'm using a ESP8266 as ethernet gateway and want to have this connected as virtuall serial port to my raspberry pi so my controller can connect to that.



  • I using RPi2 and NRF24 for this. I followed the instructions, to clone the repo, and then added config
    ./configure --my-gateway=mqtt --my-controller-ip-address=127.0.0.1 --my-mqtt-publish-topic-prefix=mysensors-out --my-mqtt-subscribe-topic-prefix=mysensors-in --my-mqtt-client-id=mygateway1 --my-transport=nrf24

    make

    when i run with sudo ./bin/mysgw -d, it is failing to connect to MQTT. Can you please help?

    mysgw: Starting gateway...
    mysgw: Protocol version - 2.1.0
    mysgw: MCO:BGN:INIT GW,CP=RNNG---,VER=2.1.0
    mysgw: TSF:LRT:OK
    mysgw: TSM:INIT
    mysgw: TSF:WUR:MS=0
    mysgw: TSM:INIT:TSP OK
    mysgw: TSM:INIT:GW MODE
    mysgw: TSM:READY:ID=0,PAR=0,DIS=0
    mysgw: MCO:REG:NOT NEEDED
    mysgw: MCO:BGN:STP
    mysgw: MCO:BGN:INIT OK,TSP=1
    mysgw: Attempting MQTT connection...
    mysgw: connect: Connection refused
    mysgw: failed to connect
    mysgw: Attempting MQTT connection...
    mysgw: connect: Connection refused
    mysgw: failed to connect
    mysgw: Attempting MQTT connection...
    mysgw: connect: Connection refused
    mysgw: failed to connect
    mysgw: Attempting MQTT connection...
    mysgw: connect: Connection refused
    mysgw: failed to connect


  • Mod

    @Anduril

    Have you aver considered Using the GatewayESP8266MQTTClient? What controller are you trying to connect?



  • I use pimatic which does not have a native compatibility to ethernet or mqtt. Thats why my question came up on how to configure it to do this...

    Building a Raspberry Pi Gateway:

    If you are running a controller on the Raspberry Pi that doesn't support communication with the gateway through ethernet, you can use a virtual serial port:
    ./configure --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyMySensorsGateway


  • Mod

    @Anduril you might be able to use nodered or socat to convert the tcp connection to a serial port.
    https://linux.die.net/man/1/socat
    https://nodered.org/



  • that's what I tried in the past and am using now (socat), but it does not reconnect and has some other drawbacks. Reading of an officially supported way sounded interesting



  • @lakshmc Make sure you don't have the daemon running already

    If not, I'm getting the same problem on the 2.1.1 that was just released. 2.1.0 was working "fine"(besides my suspecting a bug that doesn't let any inclusion happen, hence I tried the new version). Time to go back to the serial gateway right into the vera.


  • Code Contributor

    @pete1450 @lakshmc
    Make sure you are not using an old version of mosquitto (or any other broker you're using):

    $ mosquitto -h
    mosquitto version 1.4.10 (build date 2016-09-20 11:02:07-0600)
    

    It's working fine with the 2.1.1 release:

    [alarm@pi3 mysgw]$ sudo ./bin/mysgw -d
    mysgw: Starting gateway...
    mysgw: Protocol version - 2.1.1
    mysgw: MCO:BGN:INIT GW,CP=RNNG---,VER=2.1.1
    mysgw: TSF:LRT:OK
    mysgw: TSM:INIT
    mysgw: TSF:WUR:MS=0
    mysgw: TSM:INIT:TSP OK
    mysgw: TSM:INIT:GW MODE
    mysgw: TSM:READY:ID=0,PAR=0,DIS=0
    mysgw: MCO:REG:NOT NEEDED
    mysgw: MCO:BGN:STP
    mysgw: MCO:BGN:INIT OK,TSP=1
    mysgw: Attempting MQTT connection...
    mysgw: connected to 127.0.0.1
    mysgw: MQTT connected
    mysgw: Sending message on topic: mysensors-out/0/255/0/0/18
    mysgw: TSF:MSG:READ,2-2-0,s=1,c=1,t=17,pt=7,l=5,sg=0:108.12
    mysgw: TSF:MSG:ACK REQ
    mysgw: TSF:MSG:SEND,0-0-2-2,s=1,c=1,t=17,pt=7,l=5,sg=0,ft=0,st=OK:108.12
    mysgw: Sending message on topic: mysensors-out/2/1/1/0/17
    mysgw: TSF:MSG:READ,2-2-0,s=2,c=1,t=17,pt=7,l=5,sg=0:48.31
    mysgw: TSF:MSG:ACK REQ
    mysgw: TSF:MSG:SEND,0-0-2-2,s=2,c=1,t=17,pt=7,l=5,sg=0,ft=0,st=OK:48.31
    mysgw: Sending message on topic: mysensors-out/2/2/1/0/17
    mysgw: TSF:MSG:READ,2-2-0,s=3,c=1,t=17,pt=7,l=5,sg=0:362.86
    mysgw: TSF:MSG:ACK REQ
    mysgw: TSF:MSG:SEND,0-0-2-2,s=3,c=1,t=17,pt=7,l=5,sg=0,ft=0,st=OK:362.86
    mysgw: Sending message on topic: mysensors-out/2/3/1/0/17
    


  • @marceloaqno I should have specified, I'm getting the connection errors with the ethernet gateway.


  • Code Contributor

    @pete1450 Could you send the debug log with the connection errors?



  • @marceloaqno After installing broker and gateway fresh, seems to be working. Thanks for your help.



  • @marceloaqno
    Ran as root and made sure I didn't have mysgw already running:

    rm -r MySensors/
    git clone https://github.com/mysensors/MySensors.git --branch master
    cd MySensors/
    ./configure --my-controller-ip-address=192.168.1.136 --my-port=5003 --my-rf24-irq-pin=15
    make
    
    
    root@raspberrypi:~/downloads/MySensors# ./bin/mysgw -d
    mysgw: Starting gateway...
    mysgw: Protocol version - 2.1.1
    mysgw: MCO:BGN:INIT GW,CP=RNNG--Q,VER=2.1.1
    mysgw: TSF:LRT:OK
    mysgw: TSM:INIT
    mysgw: TSF:WUR:MS=0
    mysgw: TSM:INIT:TSP OK
    mysgw: TSM:INIT:GW MODE
    mysgw: TSM:READY:ID=0,PAR=0,DIS=0
    mysgw: MCO:REG:NOT NEEDED
    mysgw: connect: Connection refused
    mysgw: failed to connect
    mysgw: Eth: connect
    


  • every few days mysgw randomly dies 😞

    Jan 19 06:40:01 pi mysgw[17960]: TSF:MSG:READ,5-5-0,s=255,c=3,t=21,pt=1,l=1,sg=0:0
    Jan 19 06:40:01 pi mysgw[17960]: Sending message on topic: mysensors/out/1/5/255/3/0/21
    Jan 19 06:40:01 pi mysgw[17960]: TSF:MSG:READ,0-5-255,s=255,c=3,t=20,pt=0,l=0,sg=0:
    Jan 19 06:40:01 pi mysgw[17960]: TSF:MSG:BC
    Jan 19 06:40:01 pi systemd[1]: mysgw.service: main process exited, code=killed, status=11/SEGV
    Jan 19 06:40:01 pi systemd[1]: Unit mysgw.service entered failed state.
    
    

  • Code Contributor

    @pete1450 If you use the --my-controller-ip-address= option, the gateway will act as a client and attempt to conect to the supplied ip and port. If you want the gateway to open port 5003, omit this option.



  • @marceloaqno what is the correct configure option to make this gatway connect to an ethernet gateway and let a serial-only-controller connect to it. I suppose to use the pty option, but didn't got this working. As said above, socat and nodered are no option.



  • @marceloaqno Well that fixed the connection issue. Now I'm just back to square one where pressing start doesn't do anything. Why do I not need to specify my controllers ip? That is the ip for my veralite. Whats the use case for that option.


  • Code Contributor

    @b0rmann Could you provide the following information?

    • Your RPi model and which linux distribution you are using.
    • gcc version
    • The version and options you used to build the gateway (./configure --option)
    • The number of nodes on your network that sends messages to the gateway.
    • The broker you are using for MQTT and its version

  • Code Contributor

    @Anduril Sorry, the gateway does not support what you're trying to do.


  • Code Contributor

    @pete1450
    I can't help you with this, I've never used the Vera controller. You need to search in the Vera settings where you set this option. If Vera supports being a server and opening a port for the gateway to connect, then you use the --my-controller-ip-address option.



  • Does anyone know if the Raspberry implementation have a UserPassword option for ./configure MQTT



  • @Michael-Curtis Nevermind, I fixed it.... you ned to add :

    --my-mqtt-password=<PASS>   MQTT password
    --my-mqtt-client-id=<ID>    MQTT client id.
    

    Under "cat"

    And for the actual options under "opt do"

    --my-mqtt-user=*)
        CPPFLAGS="-DMY_MQTT_USER=\\\"${optarg}\\\" $CPPFLAGS"
        ;;
    --my-mqtt-password=*)
        CPPFLAGS="-DMY_MQTT_PASSWORD=\\\"${optarg}\\\" $CPPFLAGS"
        ;;
    

    then just add those option flags to the ./configure and run make



  • what means "5VReg -> 3.3V" in raspberry? can connect directly to 3.3V or if requied connecto to 5V with regulator to obtain 3.3v?



  • Hi 🙂 Does anybody know how to use MY_SIGNING_NODE_WHITELISTING in gateway raspbery pi? Where I must create/edit white list with my nodes?



  • first sorry about the basics question but I think many people have the same questions and can't find the answers:
    After connecting the radio (including IRQ on 15pin) and the info LEDs to the GPIO, how to config it?

    1. Do I need to configure all the info on the same command, or can I send the command "./configure --" many times for different configs?
    2. Do I need to configure it as a MQTT gateway?
    3. Where did the 127.0.0.1 IP come from?
    4. Does MQTT use internet connection?
    5. Why do you talk about Serial Gateway here, once we have a specific type for it? this type is about using GPIO only, isn't it? That is confusing!!!


  • trying to config on a Home Assistant Rpi.
    Sorry again for the newbie questions...!!!



  • Hi,
    Can I use pin 18 (GPIO 24) on my RPi3 for IRQ usage? Should I?
    If I compile with --my-rf24-irq-pin=18, no date is received when the gateway starts.
    I Cannot use pin 15 because that pin is covered by my Z-wave.me board.
    Regards,
    Erik


  • Code Contributor

    @Roberto-Mo-Ca If you are using the nrf24 PA/LNA version you need to use a 5V->3.3V regulator otherwise you can connect to the 3.3v pin.


  • Code Contributor

    @macvictor For the MY_SIGNING_NODE_WHITELISTING, you can uncomment and edit it in MyConfig.h or add it to the examples/mysgw.cpp.


  • Code Contributor

    @OliverDog

    You execute ./configure once with all your options to set your gateway.

    You need to decide what type of gateway you want to build: ethernet, serial or mqtt:
    https://www.mysensors.org/build/select_gateway

    Take a look at the link and let me know if you still have any questions.



  • thaks @marceloaqno but I was wondering there was a new type of gateway named Raspberry Gateway, were we could connect the radio directly on the GPIO and config it locally, without internet, because of that I also would like to know if MQTT uses internet connection.
    I actually use a serial gateway connected to Pi USG and it works without internet...
    I just want to have only one device...
    Thanks


  • Code Contributor

    @OliverDog You can configure the RPi to be any of the 3 types: ethernet, serial or mqtt, with the nrf24 attached to it.



  • @marceloaqno WOWWW
    now I understood... but I think this is not clear on the build steps...
    I choose a Serial Gateway, but on that lines, they say:
    "If for some reason you can't use the GPIO pins of the Raspberry Pi, you could connect the radio to a arduino with the GatewaySerial sketch and feed the pi through a serial port:"

    So I assumed the serial gateway is the same I already use...
    So, where do I get directions to config a serial gateway with the radio attached to the GPIO?

    Thanks


  • Code Contributor

    @OliverDog Which controller are you using(or are planning to use)?


  • Code Contributor

    @Erik-Tamminga Some pins may have some restrictions, I couldn't find any good info about that. Try using another pin (GPIO 25).



  • @marceloaqno I already use Home Assistant with a Serial Gateway connected on pi USB.


  • Code Contributor

    @OliverDog Home Assistant supports ethernet gateways, I recommend you go with that.

    ./configure --my-gateway=ethernet --my-transport=nrf24
    

    (The default settings is to use ethernet and nrf24, so you could omit them)

    and add to it any of your custom options.



  • I have a question regarding the --my-serial-groupname option: since I start the gateway under an user account with sudo, the gateway device ([EDIT] symlink) will be created with ownership root:root. Shouldn't it be created with root:dialout (as I chose dialout as group in my case)?

    [DELETED]


  • Code Contributor

    @Madhias /dev/pts/2 it's the one who holds the specified group ownership



  • @marceloaqno OK, many thanks for that hint!

    I was wrong from the beginning on, since I thought my configuration for the gateway was correct because of --my-serial-groupname=dialout - but that was not compiled. I edited now the mysgw.cpp manually (there was tty instead of dialout; and of course there was all the time the warning when compiling...). Now it works! Without chmod, or chowning anything later!



  • @marceloaqno Thank's for you help. I have other question.. general I try configure my gateway to work with security & signing, but they doesn't work. Where is problem? On the bottom i send point what it do it:

    Gateway:

    1. ./configure --my-gateway=mqtt --my-controller-ip-address=127.0.0.1 --my-mqtt-publish-topic-prefix=mysensors-out --my-mqtt-subscribe-topic-prefix=mysensors-in --my-mqtt-client-id=mygateway1 --my-mqtt-password=PASS --my-mqtt-user=USER --my-rf24-encryption-enabled --my-signing=software --my-signing-request-signatures --my-signing-request-gw-signatures-from-all
    2. make
    3. sudo make install
    4. sudo systemctl enable mysgw.service
    5. sudo systemctl start mysgw.service
    6. sudo mysgw --gen-soft-hmac-key
    7. sudo mysgw --set-soft-hmac-key=02417628BC1573CC380...
    8. sudo mysgw --gen-soft-serial-key
    9. sudo mysgw --set-soft-serial-key=00762CD152B868F7EB
    10. sudo mysgw --gen-aes-key
    11. sudo mysgw --set-aes-key= A790AD78B2D8B4DBBB5B2C4B9DD6DAF3

    Node:

    1. Load script SecurityPersonalizer.ino
    2. Uncomment and send sketch to arduino
    #define USE_SOFT_SIGNING
    #define STORE_SOFT_KEY
    #define USER_SOFT_KEY
    #define STORE_SOFT_SERIAL
    #define STORE_AES_KEY
    #define USER_AES_KEY
    
    #define MY_SOFT_HMAC_KEY 0X2,0X41,0X76,0X28,0XBC,0X15,0X73,0XCC,0X38...
    #define MY_AES_KEY 0XA7,0X90,0XAD,0X78,0XB2,0XD8...
    
    1. Read all value from EPROM (test save):
    Personalization sketch for MySensors usage.
    -------------------------------------------
    EEPROM configuration:
    SOFT_HMAC_KEY | 02417628BC1573CC380DE0FADF7C87D7D3C77272A783E6E438786A07C3A8C6CF
    SOFT_SERIAL   | 39BB1370C289643251
    AES_KEY       | A790AD78B2D8B4DBBB5B2C4B9DD6DAF3
    --------------------------------
    Personalization is now complete.
    
    1. Send sample sketch to arduino:
    //!< Enable debug prints to serial monitor
    #define MY_DEBUG
    //!< Enable signing related debug prints to serial monitor
    #define MY_DEBUG_VERBOSE_SIGNING
    // Enable NRF24L01 radio type
    #define MY_RADIO_NRF24
    
    // Select soft signing
    #define MY_SIGNING_SOFT
    
    // Enable lockdown of node if suspicious activity is detected
    //-->> #define MY_NODE_LOCK_FEATURE
    
    // Enable node whitelisting
    //#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
    
    // Enable this if you want destination node to sign all messages sent to this node.
    #define MY_SIGNING_REQUEST_SIGNATURES
    
    // SETTINGS FOR MY_SIGNING_SOFT
    #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7 //!< Unconnected analog pin for random seed
    
    // Add repeater function to this sensor
    #define MY_REPEATER_FEATURE
    
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    
    #define RELAY_PIN  4    // Arduino Digital I/O pin number for relay 
    #define BUTTON_PIN  3   // Arduino Digital I/O pin number for button 
    #define CHILD_ID 1      // Id of the sensor child
    #define RELAY_ON 1
    #define RELAY_OFF 0
    
    Bounce debouncer = Bounce();
    int oldValue = 0;
    bool state;
    
    MyMessage msg(CHILD_ID, V_LIGHT);
    
    void setup()
    {
      // Setup the button
      pinMode(BUTTON_PIN, INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN, HIGH);
    
      // After setting up the button, setup debouncer
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
    
      // Make sure relays are off when starting up
      digitalWrite(RELAY_PIN, RELAY_OFF);
      // Then set relay pins in output mode
      pinMode(RELAY_PIN, OUTPUT);
    
      // Set relay to last known state (using eeprom storage)
      state = loadState(CHILD_ID);
      digitalWrite(RELAY_PIN, state ? RELAY_ON : RELAY_OFF);
    }
    
    void presentation()  {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Relay & Button", "1.0");
      
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID, S_LIGHT, "Switch Secure Sensor", false);
    }
    
    /*
       Example on how to asynchronously check for new messages from gw
    */
    void loop()
    {
      debouncer.update();
      // Get the update value
      int value = debouncer.read();
    //  if (value != oldValue && value == 0) {
        send(msg.set(state ? false : true), true); // Send new state and request ack back
    //  }
    //  oldValue = value;
      delay(5000);
    }
    
    void receive(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.isAck()) {
        Serial.println("This is an ack from gateway");
      }
    
      if (message.type == V_LIGHT) {
        // Change relay state
        state = message.getBool();
        digitalWrite(RELAY_PIN, state ? RELAY_ON : RELAY_OFF);
        // Store state in eeprom
        // saveState(CHILD_ID, state);
    
        // Write some debug info
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    }
    

    And finally in Arduino Serial Monitor I see:

    0 MCO:BGN:INIT REPEATER,CP=RNNRAS-,VER=2.1.1
    4 TSM:INIT
    5 TSF:WUR:MS=0
    11 TSM:INIT:TSP OK
    13 TSF:SID:OK,ID=105
    15 TSM:FPAR
    16 Will not sign message for destination 255 as it does not require it
    58 TSF:MSG:SEND,105-105-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2065 !TSM:FPAR:NO REPLY
    2067 TSM:FPAR
    2068 Will not sign message for destination 255 as it does not require it
    2110 TSF:MSG:SEND,105-105-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    4117 !TSM:FPAR:NO REPLY
    4119 TSM:FPAR
    4120 Will not sign message for destination 255 as it does not require it
    4162 TSF:MSG:SEND,105-105-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    6169 !TSM:FPAR:NO REPLY
    6171 TSM:FPAR
    6172 Will not sign message for destination 255 as it does not require it
    6214 TSF:MSG:SEND,105-105-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    8221 !TSM:FPAR:FAIL
    8222 TSM:FAIL:CNT=1
    8224 TSM:FAIL:PDT
    

    and in gateway i see:

    sudo mysgw -d
    mysgw: Starting gateway...
    mysgw: Protocol version - 2.1.1
    mysgw: MCO:BGN:INIT GW,CP=RNNG-S-,VER=2.1.1
    mysgw: TSF:LRT:OK
    mysgw: TSM:INIT
    mysgw: TSF:WUR:MS=0
    mysgw: TSM:INIT:TSP OK
    mysgw: TSM:INIT:GW MODE
    mysgw: TSM:READY:ID=0,PAR=0,DIS=0
    mysgw: MCO:REG:NOT NEEDED
    mysgw: MCO:BGN:STP
    mysgw: MCO:BGN:INIT OK,TSP=1
    mysgw: Attempting MQTT connection...
    mysgw: connected to 127.0.0.1
    mysgw: MQTT connected
    mysgw: Sending message on topic: mysensors-out/0/255/0/0/18
    mysgw: TSF:MSG:READ,171-107-54,s=221,c=2,t=131,pt=4,l=25,sg=0:-1418183441
    mysgw: !TSF:MSG:PVER,3=2
    mysgw: TSF:MSG:READ,135-23-172,s=20,c=3,t=200,pt=7,l=25,sg=0:-0.00000178
    mysgw: !TSF:MSG:PVER,1=2
    mysgw: TSF:MSG:READ,34-66-89,s=168,c=1,t=9,pt=1,l=25,sg=0:56
    mysgw: !TSF:MSG:PVER,1=2
    mysgw: TSF:MSG:READ,223-46-240,s=112,c=5,t=192,pt=5,l=11,sg=1:1407647670
    mysgw: TSF:MSG:REL MSG
    mysgw: !TSF:RTE:240 UNKNOWN
    mysgw: !TSF:MSG:SEND,223-0-240-240,s=112,c=5,t=192,pt=5,l=11,sg=1,ft=0,st=NACK:1407647670
    mysgw: TSF:MSG:READ,183-139-129,s=37,c=6,t=155,pt=1,l=21,sg=0:48
    mysgw: !TSF:MSG:PVER,0=2
    mysgw: TSF:MSG:READ,139-214-233,s=61,c=3,t=193,pt=7,l=0,sg=1:0.00000000
    mysgw: TSF:MSG:REL MSG
    mysgw: !TSF:RTE:233 UNKNOWN
    mysgw: !TSF:MSG:SEND,139-0-233-233,s=61,c=3,t=193,pt=7,l=0,sg=1,ft=0,st=NACK:0.00000000
    mysgw: TSF:MSG:READ,83-33-7,s=179,c=2,t=27,pt=4,l=25,sg=1:-2057270722
    mysgw: !TSF:MSG:PVER,3=2
    mysgw: TSF:MSG:READ,110-148-67,s=113,c=0,t=158,pt=1,l=9,sg=1:251
    mysgw: !TSF:MSG:PVER,1=2
    mysgw: TSF:MSG:READ,75-209-102,s=204,c=7,t=25,pt=1,l=11,sg=1:52
    mysgw: !TSF:MSG:PVER,0=2
    mysgw: TSF:MSG:READ,184-209-235,s=58,c=1,t=140,pt=6,l=23,sg=1:1DC404A5401119FACF0000000000000000000000000000
    mysgw: !TSF:MSG:PVER,3=2
    mysgw: TSF:MSG:READ,172-203-51,s=140,c=2,t=173,pt=0,l=1,sg=1:?
    mysgw: TSF:MSG:REL MSG
    mysgw: !TSF:RTE:51 UNKNOWN
    mysgw: !TSF:MSG:SEND,172-0-51-51,s=140,c=2,t=173,pt=0,l=1,sg=1,ft=0,st=NACK:?
    

    Where is problem?


  • Code Contributor

    @macvictor Did you also enable encryption on your node? (#define MY_RF24_ENABLE_ENCRYPTION)



  • @marceloaqno Thanks for help 👍 This was my problem 😀


  • Mod

    how do I set user and password to access the mqtt broker? I tried do add --my-mqtt-password=PASS --my-mqtt-user=USER other parameters but they get ignored



  • @gohan edit configure file and add this code:

    --my-mqtt-user=*)
        CPPFLAGS="-DMY_MQTT_USER=\\\"${optarg}\\\" $CPPFLAGS"
        ;;
    --my-mqtt-password=*)
        CPPFLAGS="-DMY_MQTT_PASSWORD=\\\"${optarg}\\\" $CPPFLAGS"
        ;;
    

    after this code:

    --my-signing-request-gw-signatures-from-all*)
            signing_request_signatures=true
            CPPFLAGS="-DMY_SIGNING_GW_REQUEST_SIGNATURES_FROM_ALL $CPPFLAGS"
            ;;
    

    this is about 408 number line and use flag --my-mqtt-password and --my-mqtt-client-id when you run configure, thats all. 😃


  • Admin

    @macvictor It would be great if you would submit this as a GitHub Pull Request. If you aren't comfortable with that, then I would encourage you to at least open a MySensors issue to add these RPI configuration options.



  • When using RPI as a GW for MySensors, the CPU load increases from 18% to around 80 %. I am using a RPI II model B. I'd love the have the GW running on the Raspberry, and avoid a USB connected Arduino.

    Does somebody else experience the same?



  • @Teknor I use RPI III as GW and all node connect with gw used nRF24L01. My CPU now usage 5-10%, but I installed "Home Assistance" + homebridge + some plugins.



  • @macvictor Thanks. My RPI 2 is running Domoticz, RFXcom GW and 2x 3MP cameras with motion detection using Motioneye. Might be something wrong with my MySensors GW setup...



  • @Teknor I tend to agree something is wrong, but I think it really on depends how many nodes and how often you're sending data.
    rpi3 + GPIO nrf24l01 + openhab2 + 8 nodes + packet received, on average 1 / 5s :

    top - 06:29:37 up 2 days, 22:33,  2 users,  load average: 0.26, 0.24, 0.19
    KiB Mem:    947732 total,   903420 used,    44312 free,   175364 buffers
    KiB Swap:   102396 total,     4496 used,    97900 free.   391360 cached Mem
    
      PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                               
      681 root      20   0  208840  56532  23684 S   8.9  6.0 214:23.60 Xorg                                                                  
      527 root      20   0   39448  21532  11264 S   4.3  2.3  69:34.28 vncserver-x11-c                                                       
     1154 pi        20   0   50548  17628  12196 S   3.0  1.9  64:05.96 lxterminal                                                            
    30426 openhab   20   0  441764 197592  14960 S   1.6 20.8 284:18.70 java                                                                  
     2467 root      20   0   20024   2456   2300 S   1.3  0.3  62:55.17 mysgw                                                                 
    25634 root      20   0       0      0      0 S   1.0  0.0   0:00.21 kworker/u8:0                                                          
      688 root      20   0   13720   9432   8828 S   0.7  1.0   2:04.96 vncagent                                                              
    25855 pi        20   0    5232   2584   2140 R   0.7  0.3   0:00.49 top                                                                   
        7 root      20   0       0      0      0 S   0.3  0.0   9:15.35 rcu_sched                                                             
       78 root     -51   0       0      0      0 S   0.3  0.0   5:16.50 irq/92-mmc1                                                           
      967 pi        20   0   95656  17716  12028 S   0.3  1.9   6:41.87 lxpanel                                                               
        1 root      20   0   24620   4688   2716 S   0.0  0.5   0:13.08 systemd                                                               
        2 root      20   0       0      0      0 S   0.0  0.0   0:00.27 kthreadd                                                              
    

  • Mod

    @macvictor
    That worked, thanks. But to configure channel, power, AES key, and so on, do you think it is better to use command line like you posted above or customize myconfig.h?


  • Code Contributor

    @gohan You can also set mqtt username and password in examples_linux/mysgw.cpp


  • Mod

    @marceloaqno
    I'm trying to understand where is the best place to avoid file gets overwritten in case of upgrades


  • Code Contributor

    @gohan There is a open github pull request very similar to what @macvictor proposed, but for now I recommend using the examples_linux/mysgw.cpp file.


  • Mod

    @marceloaqno
    Ok I can you that file, but where is the best place to set Power Level and channel ?


  • Code Contributor

    @gohan There isn't exactly the best place to set things, it really depends on your preferences.


  • Mod

    I just copied the myconfig file from the arduino and set the rest from the command line and from debug it looks like it's working, the problem is now to get domoticz talk to the mqtt.


  • Mod

    After updating domoticz to beta version I finally have the MQTT working with controller and I can see the sensor node seding in data: my question now is how to I debug the gateway if it is running as a service on the RPI without messing things up?



  • @marceloaqno I am trying to get a Pi 3 working with MySensors 2.1.1 and nrf24l01 and using your updated wire guide, but all I get as output is the following:
    mysgw: Starting gateway...
    mysgw: Protocol version - 2.1.1
    mysgw: MCO:BGN:INIT GW,CP=RNNG--Q,VER=2.1.1
    mysgw: TSF:LRT:OK
    mysgw: TSM:INIT
    mysgw: TSF:WUR:MS=0
    mysgw: !TSM:INIT:TSP FAIL
    mysgw: TSM:FAIL:CNT=1
    mysgw: TSM:FAIL:PDT
    [The output repeats itself, increasing the CNT every time, while at the same time one of the cores on the Pi 3 is running at full CPU utilization.]

    By reading earlier comments I assume this is a wiring problem. One possible cause is inconsistency between
    0_1488723559852_upload-e3165792-1f42-4663-8e68-efd96bd275f8

    and

    0_1488723638471_upload-d7048ef8-8a33-4214-9935-0356cf9291c2

    where the first picture indicates that pin 24 and pin 26 should be used, while the second indicates pins 22 and 24 should be used. However, I have tried both options but I still get the same output (I used different nrf24's for the different setups, in case the nrf24 got burned from the first setup).

    I have VCC from nrf24 connected to pin 17 on the Pi 3 and GND connect to pin 25.

    Any suggestions on what to try next?
    [The Pi 3 is running Raspbian with Pixel. For information, I already have a running Arduino with MySensors MQTT GW and a simple node with MySensors and DHT22. From this I know that by nrf24 chips works when being fed with 3.3V.]


  • Mod

    I have connected my nrf24 like the secon table you posted and it is working but I am using an "adapter" for nrf24 with a socket and has voltage regulator + capacitors, so if you don't have any cap on the radio module, I'd suggest you put one on (try from a 4.7 uF up to 47 and see if anything changes)



  • @gohan Thanks! You were correct. I also had one of those "adapters" lying around which I did not need for my Arduino nodes with MySensors, though it came into use for the Rp3.



  • @gohan said in 💬 Building a Raspberry Pi Gateway:

    After updating domoticz to beta version I finally have the MQTT working with controller and I can see the sensor node seding in data: my question now is how to I debug the gateway if it is running as a service on the RPI without messing things up?

    I have my gateway on a headless pi 3, no monitor, GUI or keyboard. (I don't care for the nest of wires connection to the pi.) I also use MQTT which is very reliable.

    An easy way to see the full MQTT traffic is to not start (or kill if it starts on boot) the MQTT server in the background, and start it in the console you can monitor. This won't impact Domotics one bit. In my case I do this by invoking "mosquitto -d" in the terminal

    A simple way to monitor MQTT once its up and running is to look at the Domotics Log on the Setup menu.

    Another way to watch it is to, in a terminal window such as running ssh from your computer, use MQTT "sub" in your terminal to see the MQTT traffic both ways to and from Domotics. If this isn't familiar, you need to learn it, (read the MQTT docs) and it's quite simple. Example might be "ssh pi@rpi.local" or "ssh <IP address>" from a computer on the local network, assuming the user is named pi and the pi is named "rpi"

    Your MQTT topic must match what is in the sensor node sketch, the gateway sketch, and the domotics MQTT config. In my case I use "mosquitto_sub -d -v -t domoticz" and everything starts showing in real time in the terminal window.

    MQTT is a bit more fiddly to set up but it's nice that different environments can push sensor data into the same MQTT server, in my case MySensors and ESP Easy.

    Tim



  • @marlin said in 💬 Building a Raspberry Pi Gateway:

    where the first picture indicates that pin 24 and pin 26 should be used, while the second indicates pins 22 and 24 should be used.

    Be careful because the wiring page shows two pinout diagrams, one for the Pi 1, another for the Pi 2&3, but which is which is not inside the graphic itself. Please don't ask how I know. 😉

    Tim


  • Mod

    @Grubstake
    I am using mqtt fx from pc and subscribing to topic # so I get the full traffic of what is going on, but I haven't had time lately to compare if you get same log details as the myscontroller connected to ethernet gateway or starting the gateway on rpi with debug flag



  • @marlin Got the same issue, Did you solve yours and if so how?



  • @keldandorin Yes. See the response by @gohan. I used a "adapter" with a voltage regulator on it etc. Though, at the moment I don't recall the model number.


  • Mod

    @keldandorin just add a capacitor between vcc and gnd on the radio module as I suggested above.



  • I am trying to connect NRF24L01+ and Raspberry Pi 2 (Model B+). I am confuse about pin 22/24 too. In the diagram it shows "SPI0 CS0" and "SPI0 CS1" but these two pins aren't exist in NRF24L01+. How should I connect the pin? I connect Pi2 pin 24 to CS and Pi2 pin 26 to CE (Not sure it is correct)? Here is the message from mysgw:

    [root@alarmpi bin]# ./mysgw -d
    mysgw: Starting gateway...
    mysgw: Protocol version - 2.1.1
    mysgw: MCO:BGN:INIT GW,CP=RNNG---,VER=2.1.1
    mysgw: TSM:INIT
    mysgw: TSF:WUR:MS=0
    mysgw: !TSM:INIT:TSP FAIL
    mysgw: TSM:FAIL:CNT=1
    mysgw: TSM:FAIL:PDT
    mysgw: TSM:FAIL:RE-INIT
    mysgw: TSM:INIT
    mysgw: !TSM:INIT:TSP FAIL
    mysgw: TSM:FAIL:CNT=2
    mysgw: TSM:FAIL:PDT
    mysgw: TSM:FAIL:RE-INIT
    mysgw: TSM:INIT
    mysgw: !TSM:INIT:TSP FAIL
    mysgw: TSM:FAIL:CNT=3
    mysgw: TSM:FAIL:PDT
    


  • @ccy Look at the chart below "NRF24L01+ Radio". That shows the PIN numbers on the Pi and the pin labels on the radio to interconnect. Pay no attention to the labels on the RPi generic pinout diagram except the PIN numbers. The RPi SPIO labels are not what you are looking for. And be sure to use the chart for the correct RPi model.


  • Mod

    Exactly, I was about to write pretty much the same 😀



  • @gohan I beat you to it! 😃



  • @Grubstake: Thanks. I have tried to follow "NRF24L01+ Radio" pin out connection. I have double / triple check my wiring is correct. But I still get the same fail message in mysgw debug mode:

    [root@alarmpi bin]# ./mysgw -d
    mysgw: Starting gateway...
    mysgw: Protocol version - 2.1.1
    mysgw: MCO:BGN:INIT GW,CP=RNNG---,VER=2.1.1
    mysgw: TSM:INIT
    mysgw: TSF:WUR:MS=0
    mysgw: !TSM:INIT:TSP FAIL
    mysgw: TSM:FAIL:CNT=1
    mysgw: TSM:FAIL:PDT
    mysgw: TSM:FAIL:RE-INIT
    mysgw: TSM:INIT
    mysgw: !TSM:INIT:TSP FAIL
    mysgw: TSM:FAIL:CNT=2
    mysgw: TSM:FAIL:PDT
    mysgw: TSM:FAIL:RE-INIT
    mysgw: TSM:INIT
    mysgw: !TSM:INIT:TSP FAIL
    mysgw: TSM:FAIL:CNT=3
    mysgw: TSM:FAIL:PDT
    mysgw: Received SIGINT
    

    Here is my /boot/config.txt:

    gpu_mem=64
    initramfs initramfs-linux.img followkernel
    dtparam=spi=on
    

    and the spi dev:

    # ls /dev/spidev0.*
    /dev/spidev0.0  /dev/spidev0.1
    

    I am using ArchLinuxARM:

    # uname -a
    Linux alarmpi 4.9.13-3-ARCH #1 SMP Fri Mar 3 18:45:16 MST 2017 armv7l GNU/Linux
    

    I only wiring 7 pins (1-7) on NRF24l01+.

    Raspberry Pi 2 hardware information:

    # cat /proc/cpuinfo
    processor       : 0
    model name      : ARMv7 Processor rev 5 (v7l)
    BogoMIPS        : 38.40
    Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
    CPU implementer : 0x41
    CPU architecture: 7
    CPU variant     : 0x0
    CPU part        : 0xc07
    CPU revision    : 5
    
    processor       : 1
    model name      : ARMv7 Processor rev 5 (v7l)
    BogoMIPS        : 38.40
    Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
    CPU implementer : 0x41
    CPU architecture: 7
    CPU variant     : 0x0
    CPU part        : 0xc07
    CPU revision    : 5
    
    processor       : 2
    model name      : ARMv7 Processor rev 5 (v7l)
    BogoMIPS        : 38.40
    Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
    CPU implementer : 0x41
    CPU architecture: 7
    CPU variant     : 0x0
    CPU part        : 0xc07
    CPU revision    : 5
    
    processor       : 3
    model name      : ARMv7 Processor rev 5 (v7l)
    BogoMIPS        : 38.40
    Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
    CPU implementer : 0x41
    CPU architecture: 7
    CPU variant     : 0x0
    CPU part        : 0xc07
    CPU revision    : 5
    
    Hardware        : BCM2835
    Revision        : a21041
    Serial          : 00000000475d18a4
    
    # cat /sys/firmware/devicetree/base/model
    Raspberry Pi 2 Model B Rev 1.1
    

    Output from MySensors configure:

    # ./configure
    [SECTION] Detecting target machine.
    ./configure: line 111: warning: command substitution: ignored null byte in input
      [OK] machine detected: SoC=unknown, Type=unknown, CPU=armv7l.
    [SECTION] Checking GPIO Sysfs.
      [OK] /sys/class/gpio/export found
    [SECTION] Detecting SPI driver.
      [OK] SPI driver detected:SPIDEV.
    [SECTION] Detecting init system.
      [OK] init system detected: systemd.
    [SECTION] Saving configuration.
    [SECTION] Cleaning previous builds.
    [OK] Finished.
    

    I finally find out my raspberry pi board isn't detected properly in configure. I change the function detect_machine:

    function detect_machine {
    ...
        case $hardware in
    ...
        BCM2835)
            soc="BCM2835"
            if [[ $machine == "Raspberry"* ]]; then
                local rev=($(detect_rpi_revision))
                if [[ $rev == "a02082" || $rev == "a22082" ]]; then
                    tp="RPi3"
                else
                    tp="Rpi2"
                fi
            fi
            ;;
    ...
    

    make mysgw again, and I get this finally:

    # ./mysgw -d
    mysgw: Starting gateway...
    mysgw: Protocol version - 2.1.1
    mysgw: MCO:BGN:INIT GW,CP=RNNG---,VER=2.1.1
    mysgw: TSF:LRT:OK
    mysgw: TSM:INIT
    mysgw: TSF:WUR:MS=0
    mysgw: TSM:INIT:TSP OK
    mysgw: TSM:INIT:GW MODE
    mysgw: TSM:READY:ID=0,PAR=0,DIS=0
    mysgw: MCO:REG:NOT NEEDED
    mysgw: Listening for connections on 0.0.0.0:5003
    mysgw: MCO:BGN:STP
    mysgw: MCO:BGN:INIT OK,TSP=1
    


  • I can run mysgw. But what can I use it for? I want to make it control my light with 2.4G RF. But I don't know what to do next. Please advice Thank you.


  • Mod

    @ccy
    You need to provide some more details about your hw and general setup, what have you done so far, log messages, etc.



  • @gohan Sorry for my typo mistake. I can now run mysgw. But what can I use it for? I am trying to control my light with 2.4G RF.


  • Mod

    Do you mean your light has already 2.4G RF or do you need to make a relay node with NRF24 that can switch on and of that light? But this is going a little OT in this thread.



  • @gohan Yes. I want to do that. I am sure my LED controller is 2.4G RF. But I can't detect any signal yet from my nrf24l01+ on raspberry pi. I am not sure what's wrong. Still trying now...


  • Mod

    @ccy
    Being 2.4G RF doesn't mean it is NRF24L01 compatible also without knowing what channel is using will make it even more difficult. So, unless you want to make a Mysensors LED Controller, I think you are out of luck if you want to directly control your existing one with a RPI and the mysensors gateway. Either way this is OT.



  • @gohan Is there a way to know the channel by doing some sort of scan? If the channel is known, what are the setting to fix the channel for mysgw?


Log in to reply
 

Suggested Topics

  • 3
  • 584
  • 109
  • 110
  • 10
  • 5

49
Online

11.4k
Users

11.1k
Topics

112.7k
Posts