💬 Building a Raspberry Pi Gateway


  • Admin

    This thread contains comments for the article "Building a Raspberry Pi Gateway" posted on MySensors.org.



  • Does this page imply that RFM69 and Rasp Pi as a gateway/controller is possible?! 🙂


  • Admin

    @marceloaqno has been working on a PR for RPI/Linux.

    https://github.com/mysensors/MySensors/pull/537

    It hasn't been merged into development yet.



  • Or NRF24L01+ and Rasp PI also as gateway/controller possible ???


  • Admin

    Yes, NRF24L01+ will also be supported.



  • When do you think the install and build instructions will come up? 🙂 Will this work with a B-model? (bought 2013)


  • Admin

    I'm not sure, @marceloaqno will finish the page when he feels the configuration options is stable enough.



  • Yes, can I use my Rasp Pi as a GW/Controller all in one? I have setup Domoticz on my Rasp Pi so could i do this and add an NRF??



  • RFM69 will work on RPi.
    @marceloaqno PR works fine more me on my RPi3 so it will work on RPi2 or below, but this is still beta and has not been merged into development branch yet.
    yes, it is possible to have 3-in-1 (nrf24l01+ RPi and Domoticz or any other combination).



  • I just saw that the PR537 was merged
    @marceloaqno great job, do you now plan to write some build instructions ? I've had a look at the file, but I don't want to mess it all up


  • Code Contributor

    @frencho I hope to write something this weekend, at least a draft.


  • Hardware Contributor

    @marceloaqno
    looking forward to upgrading my gateway to v2 🙂



  • @marceloaqno just wondering because I could figure it out looking at your code : does it work with nrf24 And rfm69 or just nrf24?!

    Regardless of your answer you did a great job, that awesome thanks


  • Code Contributor

    @frencho thanks. Sorry no support for rfm69 yet. I order some rfm69 modules from ebay to play with but they haven't arrived. So I'm waiting to finish some tests.



  • @marceloaqno I second @frencho's comment, excellent job on getting mainline support for the Raspberry Pi into the MySensors codebase. Thank you for your efforts.



  • Hello, I just installed @marceloaqno wonderful port of the mySensors 2.0 to the raspberry pi MyGatewaySerial. Thank you very much for that! I'm very glad to be using my boards that connect my radio directly to my Raspi! The installation went very smoothly.

    I am having an issue with a few of my messages from my sensor node. My sensor node sends 6 messages. 3 are V-STATUS, 1 is V-TEMP, 1 is V-VAR1, and one is the battery voltage level. The V-TEMP and the 3 V-STATUS messages go through perfectly but the V-VAR1 and the Battery voltage are not reaching the Raspi. This is the output of the node:

    Starting sensor (RNNNA-, 2.0.0)
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=3)
    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-3 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=3)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:READ 0-0-3 s=255,c=3,t=25,pt=1,l=1,sg=0:1
    TSP:MSG:PONG RECV (hops=1)
    TSP:CHKUPL:OK
    TSM:UPL:OK
    TSM:READY
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
    TSP:MSG:SEND 3-3-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=ok:2.0.0
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=ok:0
    TSP:MSG:READ 0-0-3 s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=11,pt=0,l=11,sg=0,ft=0,st=ok:Sensor Node
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:1.0
    TSP:MSG:SEND 3-3-0-0 s=1,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=ok:
    TSP:MSG:SEND 3-3-0-0 s=2,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=ok:
    TSP:MSG:SEND 3-3-0-0 s=3,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    TSP:MSG:SEND 3-3-0-0 s=4,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    TSP:MSG:SEND 3-3-0-0 s=5,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    Request registration...
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
    TSP:MSG:READ 0-0-3 s=255,c=3,t=27,pt=1,l=1,sg=0:1
    Node registration=1
    Init complete, id=3, parent=0, distance=1, registration=1
      Data = 0 0 0 0 0 0 0 0 0 0  CRC=0
      Temperature = 0.00 Celsius, 32.00 Fahrenheit
    TSP:MSG:SEND 3-3-0-0 s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=ok:32.00
    !TSP:MSG:SEND 3-3-0-0 s=2,c=1,t=24,pt=3,l=2,sg=0,ft=0,st=fail:0
    TSP:MSG:SEND 3-3-0-0 s=3,c=1,t=2,pt=1,l=1,sg=0,ft=1,st=ok:1
    TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:SEND 3-3-0-0 s=5,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=ok:1
    !TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=fail:44
    No SensorTSP:MSG:SEND 3-3-0-0 s=1,c=1,t=0,pt=7,l=5,sg=0,ft=1,st=ok:0.00
    !TSP:MSG:SEND 3-3-0-0 s=2,c=1,t=24,pt=3,l=2,sg=0,ft=0,st=fail:0
    TSP:MSG:SEND 3-3-0-0 s=3,c=1,t=2,pt=1,l=1,sg=0,ft=1,st=ok:1
    TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:SEND 3-3-0-0 s=5,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=ok:1
    !TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=fail:60
    

    Notice the failed messages on the "s=2" and "s=255" lines.

    This is what the Raspi receives:

    mysGateway: TSF:MSG:BC
    mysGateway: TSF:MSG:FPAR REQ,ID=3
    mysGateway: TSF:PNG:SEND,TO=0
    mysGateway: TSF:CKU:OK
    mysGateway: TSF:MSG:GWL OK
    mysGateway: TSF:MSG:SEND,0-0-3-3,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    mysGateway: TSF:MSG:READ,3-3-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    mysGateway: TSF:MSG:PINGED,ID=3,HP=1
    mysGateway: TSF:MSG:SEND,0-0-3-3,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1
    mysGateway: TSF:MSG:READ,3-3-0,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    mysGateway: TSF:MSG:SEND,0-0-3-3,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    mysGateway: TSF:MSG:READ,3-3-0,s=255,c=0,t=17,pt=0,l=5,sg=0:2.0.0
    mysGateway: TSF:MSG:READ,3-3-0,s=255,c=3,t=6,pt=1,l=1,sg=0:0
    mysGateway: TSF:MSG:READ,3-3-0,s=255,c=3,t=11,pt=0,l=11,sg=0:Sensor Node
    mysGateway: TSF:MSG:READ,3-3-0,s=255,c=3,t=12,pt=0,l=3,sg=0:1.0
    mysGateway: TSF:MSG:READ,3-3-0,s=1,c=0,t=6,pt=0,l=0,sg=0:
    mysGateway: TSF:MSG:READ,3-3-0,s=2,c=0,t=6,pt=0,l=0,sg=0:
    mysGateway: TSF:MSG:READ,3-3-0,s=3,c=0,t=3,pt=0,l=0,sg=0:
    mysGateway: TSF:MSG:READ,3-3-0,s=4,c=0,t=3,pt=0,l=0,sg=0:
    mysGateway: TSF:MSG:READ,3-3-0,s=5,c=0,t=3,pt=0,l=0,sg=0:
    mysGateway: TSF:MSG:READ,3-3-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2
    mysGateway: TSF:MSG:SEND,0-0-3-3,s=255,c=3,t=27,pt=1,l=1,sg=0,ft=0,st=OK:1
    mysGateway: TSF:MSG:READ,3-3-0,s=1,c=1,t=0,pt=7,l=5,sg=0:32.00
    mysGateway: TSF:MSG:READ,3-3-0,s=3,c=1,t=2,pt=1,l=1,sg=0:1
    mysGateway: TSF:MSG:READ,3-3-0,s=4,c=1,t=2,pt=1,l=1,sg=0:1
    mysGateway: TSF:MSG:READ,3-3-0,s=5,c=1,t=2,pt=1,l=1,sg=0:1
    mysGateway: TSF:MSG:READ,3-3-0,s=1,c=1,t=0,pt=7,l=5,sg=0:0.00
    mysGateway: TSF:MSG:READ,3-3-0,s=3,c=1,t=2,pt=1,l=1,sg=0:1
    mysGateway: TSF:MSG:READ,3-3-0,s=4,c=1,t=2,pt=1,l=1,sg=0:1
    mysGateway: TSF:MSG:READ,3-3-0,s=5,c=1,t=2,pt=1,l=1,sg=0:1
    

    This is the code running on the sensor node:

    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    #define MY_NODE_ID 3
    #define MY_RF24_CE_PIN 9
    #define MY_RF24_PA_LEVEL RF24_PA_HIGH
    
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <prescaler.h>
    #include <OneWire.h>
    
    #define SKETCH_NAME "Sensor Node"
    #define SKETCH_MAJOR_VER "1"
    #define SKETCH_MINOR_VER "0"
    
    #define TEMPERATURE_SENSOR 1
    #define STATUS 2
    #define HIGH_SWITCH 3
    #define FILL_SWITCH 4
    #define LOW_SWITCH 5
    
    const byte EN = 17; //turns on the boost converter to get 3.3v
    const byte PER = 14; //peripherals (DS18B20, nRF24L01)
    const byte High_sw = 5;
    const byte Fill_sw = 6;
    const byte Low_sw = 7;
    const byte Wake_pin = 2;  //wake from sleep mode powerdown
    OneWire  ds(9);  // on pin 10 (a 4.7K resistor is necessary)
    unsigned int node_status = 0;
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(TEMPERATURE_SENSOR, V_TEMP);
    MyMessage msg2(STATUS, V_VAR1);
    MyMessage msg3(HIGH_SWITCH, V_STATUS);
    MyMessage msg4(FILL_SWITCH, V_STATUS);
    MyMessage msg5(LOW_SWITCH, V_STATUS);
    
    
    void before(){
    
      pinMode(EN,OUTPUT);
      digitalWrite(EN,LOW);  //give us 3.3v
      
      pinMode(PER, OUTPUT);   //for turning on peripherals
      digitalWrite(PER,LOW);  //peripherals on - P Chan FET
      
      digitalWrite (Wake_pin, HIGH);  //will wake with falling edge
      
    }
    void setup()  
    {  
      
    }
    
    void presentation() {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
    
      // Register binary input sensor to sensor_node (they will be created as child devices)
      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
      present(TEMPERATURE_SENSOR, S_TEMP);
      present(STATUS, S_TEMP);
      present(HIGH_SWITCH, S_BINARY);
      present(FILL_SWITCH, S_BINARY);
      present(LOW_SWITCH, S_BINARY);  
     
    }
    
    // Loop will iterate on changes on the BUTTON_PINs
    void loop() 
    {     
          send(msg.set(get_temperature(),2));
          send(msg2.set(node_status));
          send(msg3.set(switch_status(High_sw)));
          send(msg4.set(switch_status(Fill_sw)));
          send(msg5.set(switch_status(Low_sw)));
          sendBatteryLevel(get_battery());
          
          //this worked when I was using the SerialGateway on the Raspi but 
          //isn't working using the MySerialGateway (mysgateway)
          if(isTransportOK()){
            sleep(30000);  // transport is OK, node can sleep
          } 
          else {
            Serial.println("Fixing Transport Layer");
            node_status+=1;
            wait(5000); // transport is not operational, allow the transport layer to fix this
          }
          //sleep(60000);  //interrupt on pin 2
        
    
    
    } 
    
    bool switch_status(int digitalPin){
      bool stat = 1;
      pinMode(digitalPin,INPUT);
      digitalWrite(digitalPin,HIGH);  //enable pullup
      sleep(5); //not sure if we need to wait for the line to settle
      stat = digitalRead(digitalPin);
      digitalWrite(digitalPin,LOW);  //save power when off
      return stat;
    }
    
    float get_temperature(){
    
      byte i;
      byte ds_present = 0;
      byte type_s = 0;
      byte data[12];
      byte addr[8];
      float celsius, fahrenheit;
      
      
      if (!ds.reset())
      {
        Serial.print("No Sensor");
        return (0);
        }
      ds.skip();
      ds.write(0x44, 1);        // start conversion, with parasite power on at the end
      
      sleep(1000);     // maybe 750ms is enough, maybe not
      // we might do a ds.depower() here, but the reset will take care of it.
      
      ds_present = ds.reset();
      ds.skip();    
      ds.write(0xBE);         // Read Scratchpad
    
      Serial.print("  Data = ");
      Serial.print(ds_present, HEX);
      Serial.print(" ");
      for ( i = 0; i < 9; i++) {           // we need 9 bytes
        data[i] = ds.read();
        Serial.print(data[i], HEX);
        Serial.print(" ");
      }
      Serial.print(" CRC=");
      Serial.print(OneWire::crc8(data, 8), HEX);
      Serial.println();
    
      // Convert the data to actual temperature
      // because the result is a 16 bit signed integer, it should
      // be stored to an "int16_t" type, which is always 16 bits
      // even when compiled on a 32 bit processor.
      int16_t raw = (data[1] << 8) | data[0];
      if (type_s) {
        raw = raw << 3; // 9 bit resolution default
        if (data[7] == 0x10) {
          // "count remain" gives full 12 bit resolution
          raw = (raw & 0xFFF0) + 12 - data[6];
        }
      } else {
        byte cfg = (data[4] & 0x60);
        // at lower res, the low bits are undefined, so let's zero them
        if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
        else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
        else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
        //// default is 12 bit resolution, 750 ms conversion time
      }
      celsius = (float)raw / 16.0;
      fahrenheit = celsius * 1.8 + 32.0;
      Serial.print("  Temperature = ");
      Serial.print(celsius);
      Serial.print(" Celsius, ");
      Serial.print(fahrenheit);
      Serial.println(" Fahrenheit");
      return(fahrenheit);
    }
    //battery empty at .8v so 1.5 - .8 = .7
    //(465-battery)/248
    //.0032226562
    float get_battery(){
      unsigned int battery = analogRead(A1);
      //float volts = 3.3/1024.0*(float)battery;
      float percent = (217.0-(465.0-(float)battery))/217.0;
      return(max(0,min(100,(percent * 100))));
    }
    

    Can you see anything that may be causing my issue?



  • I've connected the radio using gpio pinnumbers to my rpi using this schema:
    alt text
    but when I run it gives the following errors:

    what did I do wrong?

    mysGateway: Starting gateway...
    mysGateway: Protocol version - 2.0.1-beta
    mysGateway: MCO:BGN:INIT GW,CP=RNNG--Q,VER=2.0.1-beta
    mysGateway: TSF:LRT:OK
    mysGateway: TSM:INIT
    mysGateway: !TSM:INIT:TSP FAIL
    mysGateway: TSM:FAIL:CNT=1
    mysGateway: TSM:FAIL:PDT
    mysGateway: TSM:FAIL:RE-INIT
    mysGateway: TSM:INIT
    mysGateway: !TSM:INIT:TSP FAIL
    mysGateway: TSM:FAIL:CNT=2
    mysGateway: TSM:FAIL:PDT
    mysGateway: TSM:FAIL:RE-INIT
    mysGateway: TSM:INIT
    mysGateway: !TSM:INIT:TSP FAIL
    mysGateway: TSM:FAIL:CNT=3
    mysGateway: TSM:FAIL:PDT
    mysGateway: TSM:FAIL:RE-INIT
    mysGateway: TSM:INIT
    mysGateway: !TSM:INIT:TSP FAIL
    mysGateway: TSM:FAIL:CNT=4
    mysGateway: TSM:FAIL:PDT
    mysGateway: TSM:FAIL:RE-INIT
    mysGateway: TSM:INIT
    mysGateway: !TSM:INIT:TSP FAIL
    mysGateway: TSM:FAIL:CNT=5
    mysGateway: TSM:FAIL:PDT
    mysGateway: TSM:FAIL:RE-INIT
    mysGateway: TSM:INIT
    mysGateway: !TSM:INIT:TSP FAIL
    mysGateway: TSM:FAIL:CNT=6
    mysGateway: TSM:FAIL:PDT
    mysGateway: TSM:FAIL:RE-INIT
    mysGateway: TSM:INIT
    mysGateway: !TSM:INIT:TSP FAIL
    mysGateway: TSM:FAIL:CNT=7
    mysGateway: TSM:FAIL:PDT
    mysGateway: TSM:FAIL:RE-INIT
    mysGateway: TSM:INIT
    mysGateway: !TSM:INIT:TSP FAIL
    mysGateway: TSM:FAIL:CNT=7
    

    make output:

    pi@raspberrypi:~/MySensors$ make
    Makefile:12: Makefile.inc: Bestand of map bestaat niet
    [Running configure]
    [SECTION] Detecting target machine.
    [OK] machine detected: SoC=BCM2835, Type=RPi, CPU=armv6l, REV=0010.
    [OK] init system detected: systemd
    [SECTION] Saving configuration.
    [OK] Finished.
    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_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -D__RPI_BPLUS -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_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -D__RPI_BPLUS -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_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -D__RPI_BPLUS -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_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -D__RPI_BPLUS -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_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -D__RPI_BPLUS -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_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -D__RPI_BPLUS -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_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -D__RPI_BPLUS -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_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -D__RPI_BPLUS -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_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -D__RPI_BPLUS -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o examples_linux/mysGateway.o examples_linux/mysGateway.cpp
    cc  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/RPi/piHiPri.o drivers/RPi/piHiPri.c
    cc  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/RPi/bcm2835.o drivers/RPi/bcm2835.c
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -D__RPI_BPLUS -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/RPi/rpi_util.o drivers/RPi/rpi_util.cpp
    g++ -DMY_RADIO_NRF24 -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -D__RPI_BPLUS -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/RPi/SPI.o drivers/RPi/SPI.cpp
    g++ -pthread  -o examples_linux/mysGateway drivers/Linux/log.o drivers/Linux/noniso.o drivers/Linux/EthernetClient.o drivers/Linux/SerialPort.o drivers/Linux/Stream.o drivers/Linux/Print.o drivers/Linux/IPAddress.o drivers/Linux/compatibility.o drivers/Linux/EthernetServer.o examples_linux/mysGateway.o drivers/RPi/piHiPri.o drivers/RPi/bcm2835.o drivers/RPi/rpi_util.o drivers/RPi/SPI.o
    

  • Code Contributor

    @hawk_2050 same for you guys who helped, thank you for all the feedback.

    @jerseyguy1996 I don't see anything wrong with your config.Try to add a small delay() after the first send() and before the sendBattery().

    @annegerben This looks like a wire problem. I updated the guide, check the wire section again.



  • @marceloaqno thanks for the updated in the guide, I've now successfully connected the radio to the RPI.



  • Would it be possible to connect a I2C display to display some information, and drive that display from within mysGatway.cpp ?


  • Code Contributor

    @ericvdb I2C is the next thing I'll do as soon as I finished adding support for signing.



  • @marceloaqno Amazing....adding the short delay fixed it! I'm curious why that is the case. Do you have an explanation for that?


  • Code Contributor



  • Just installed MySensors on one of my Raspberry. Works really great! 🙂 Picks up the other node I have over NRF without trouble. Next I will try and add some sensors directly on the Raspberry.
    Big thanks for this!



  • @marceloaqno Oh that makes sense 🙂 I'm wondering if that is also what is causing my problem with reconnecting when the node loses contact with the gateway. The node connects perfectly when the gateway is running but if it loses the connection for any reason it can't seem to be able to reconnect and just goes into a loop of attempts. Here is the debug info from the node:

    This is the initialization output

    Starting sensor (RNNNA-, 2.0.0)
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=3)
    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-3 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=3)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:READ 0-0-3 s=255,c=3,t=25,pt=1,l=1,sg=0:1
    TSP:MSG:PONG RECV (hops=1)
    TSP:CHKUPL:OK
    TSM:UPL:OK
    TSM:READY
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
    TSP:MSG:SEND 3-3-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=ok:2.0.0
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=ok:0
    TSP:MSG:READ 0-0-3 s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=11,pt=0,l=11,sg=0,ft=0,st=ok:Sensor Node
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:1.0
    TSP:MSG:SEND 3-3-0-0 s=1,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=ok:
    TSP:MSG:SEND 3-3-0-0 s=2,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=ok:
    TSP:MSG:SEND 3-3-0-0 s=3,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    TSP:MSG:SEND 3-3-0-0 s=4,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    TSP:MSG:SEND 3-3-0-0 s=5,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    Request registration...
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
    TSP:MSG:READ 0-0-3 s=255,c=3,t=27,pt=1,l=1,sg=0:1
    Node registration=1
    Init complete, id=3, parent=0, distance=1, registration=1
    TSP:MSG:SEND 3-3-0-0 s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=ok:32.00
    TSP:MSG:SEND 3-3-0-0 s=2,c=1,t=24,pt=3,l=2,sg=0,ft=0,st=ok:0
    TSP:MSG:SEND 3-3-0-0 s=3,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:SEND 3-3-0-0 s=5,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=ok:39
    TSP:MSG:SEND 3-3-0-0 s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=ok:32.00
    TSP:MSG:SEND 3-3-0-0 s=2,c=1,t=24,pt=3,l=2,sg=0,ft=0,st=ok:0
    TSP:MSG:SEND 3-3-0-0 s=3,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:SEND 3-3-0-0 s=5,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=ok:76
    

    So far so good!

    Next I shutdown the gateway to simulate a lost connection:

    TSP:MSG:SEND 3-3-0-0 s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=ok:32.00
    TSP:MSG:SEND 3-3-0-0 s=2,c=1,t=24,pt=3,l=2,sg=0,ft=0,st=ok:0
    TSP:MSG:SEND 3-3-0-0 s=3,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=ok:1
    !TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=fail:1
    !TSP:MSG:SEND 3-3-0-0 s=5,c=1,t=2,pt=1,l=1,sg=0,ft=1,st=fail:1
    !TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,ft=2,st=fail:74
    !TSP:MSG:SEND 3-3-0-0 s=1,c=1,t=0,pt=7,l=5,sg=0,ft=3,st=fail:32.00
    !TSP:MSG:SEND 3-3-0-0 s=2,c=1,t=24,pt=3,l=2,sg=0,ft=4,st=fail:0
    !TSP:MSG:SEND 3-3-0-0 s=3,c=1,t=2,pt=1,l=1,sg=0,ft=5,st=fail:1
    !TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=2,pt=1,l=1,sg=0,ft=6,st=fail:1
    !TSP:MSG:SEND 3-3-0-0 s=5,c=1,t=2,pt=1,l=1,sg=0,ft=7,st=fail:1
    !TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,ft=8,st=fail:72
    

    Its still doing what I expect it to do. It begins attempting to reconnect:

    !TSM:UPL FAIL, SNP
    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    Fixing Transport Layer
    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    Fixing Transport Layer
    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    

    Still working as intended. Next I start the gateway back up to see if it will reconnect. Here is where I have problems.

    Fixing Transport Layer
    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-3 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=3)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    !TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=fail:1
    TSP:CHKUPL:FAIL (hops=255)
    !TSM:UPL:FAIL
    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    Fixing Transport Layer
    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-3 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=3)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    !TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=fail:1
    TSP:CHKUPL:FAIL (hops=255)
    !TSM:UPL:FAIL
    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    

    It looks like the first few messages to initialize the reconnect go through okay and then it misses everything afterwards. If I reset the node it will connect again with no problems.
    What do you think might be happening here?



  • A tiny hint for the users of domoticz :
    ./configure --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyUSB20
    make
    sudo ./examples_linux/mysGateway -d

    🙂 i hope this helps
    then in the hardware setup
    MySensors Gateway USB
    serial port: /dev/ttyUSB20



  • I'm a bit confused about gateway and controller. Can I use a Pi as both gateway and controller?


  • Admin

    @gvorster said:

    I'm a bit confused about gateway and controller. Can I use a Pi as both gateway and controller?

    Yes!



  • I'm using the virtual serial port option and one of the things that I notice is that the port gets created where the tty group only has write access.

    pi@raspberrypi:/dev/pts $ ls -l
    total 0
    crw--w---- 1 root tty  136, 0 Oct 10 18:49 0
    

    I can change it manually but if I reboot the raspberry pi it goes back to write access only. How do I get it to be created with 'rw' access?



  • Nevermind....When I set "--my-serial-groupname=tty" in ./configure it works.



  • Where do I put the security stuff for the signing?


  • Hardware Contributor

    @NiklasO

    Signing is not yet supported in the current Raspi Gateway.



  • @GertSanders said:

    @NiklasO

    Signing is not yet supported in the current Raspi Gateway.

    Ok, thanks.
    I now see that in this thread. Did not see the earlier discussion in the comments on the main page. Hope to see support soon.

    I have disabled signing for the time being but I want it on ofc. 😉



  • what's about RS485 transport on raspberry pi? especially from wired RS485 mysensors network to MQTT



  • Can you use the RP as gateway and also as controller?



  • @raulandresmoch
    Sure. I use this with Domoticz on my Pi.
    "MySensors Gateway with LAN interface" as hardware pointing to 127.0.0.1:5003
    Also, I can connect with other controller software like MYSController from my other computers to my Pi-IP at port 5003.


  • Code Contributor

    @b0rmann I could add support for RS485, but I'll need your help to test because I don't have the hardware.



  • The line above
    ./examples_linux/mysGatewaymsyGateway -h
    needs to be corrected to
    ./examples_linux/mysGateway -h
    Thanks for all the hard work! Awesome!


  • Mod

    @DrJeff Thanks for noticing. It should be fixed now.



  • @marceloaqno

    i am ready. after compiled and upload example node sketch i have on rs485 to usb convertor (/dev/ttyUSB0) output nice mysensors data:

    01 FF 00 58 07 02 FF FF - FF 02 03 07 FF 03 66 04
    01 FF 00 58 07 02 FF FF - FF 02 03 07 FF 03 66 04
    01 FF 00 58 07 02 FF FF - FF 02 03 07 FF 03 66 04
    01 FF 00 58 07 02 FF FF - FF 02 03 07 FF 03 66 04
    01 FF 00 58 07 02 FF FF - FF 02 03 07 FF 03 66 04
    01 FF 00 58 07 02 FF FF - FF 02 03 07 FF 03 66 04
    01 FF 00 58 07 02 FF FF - FF 02 03 07 FF 03 66 04
    01 FF 00 58 07 02 FF FF - FF 02 03 07 FF 03 66 04
    

    testing playground photo: 0_1476563966730_playground.jpg



  • I noticed the "improve rf24" section was added. and it mentioned high cpu.
    i set mine up a few weeks ago and am not using an interrupt on my radio.
    my cpu is only 2-3%
    I'm curious if the high cpu problem is seen by many?

    also a 2nd question.
    if i were to add an interrupt. how can i "re-configure" my setup to include that new -switch
    or do i have to remove everything and re-clone from git hub and start over?



  • Thanks for this excellent port. I'm having an issue running it as an MQTT gateway on the RPi (Model A). It compiles without hassles, but cant make a successful MQTT connection. I get the following:

    mysGateway: Starting gateway...
    mysGateway: Protocol version - 2.0.1-beta
    mysGateway: MCO:BGN:INIT GW,CP=RNNG---,VER=2.0.1-beta
    mysGateway: TSF:LRT:OK
    mysGateway: TSM:INIT
    mysGateway: TSM:INIT:TSP OK
    mysGateway: TSM:INIT:GW MODE
    mysGateway: TSM:READY
    mysGateway: MCO:REG:NOT NEEDED
    mysGateway: MCO:BGN:STP
    mysGateway: MCO:BGN:INIT OK,ID=0,PAR=0,DIS=0,REG=1
    mysGateway: Attempting MQTT connection...
    mysGateway: connected to 127.0.0.1
    mysGateway: Attempting MQTT connection...
    mysGateway: connected to 127.0.0.1
    mysGateway: Attempting MQTT connection...
    mysGateway: connected to 127.0.0.1

    ... those attempts recurring every 15 seconds or so, and in that time, no other activity is processed.
    From the code, I would have expected 'MQTT connected' rather than 'connected to 127.0.0.1'?

    I have mosquitto running on the pi in this case - which is working perfectly in other tests. Both serial and ethernet gateway modes compile and run perfectly, only the mqtt mode not working.
    Has anyone else had a similar issue?



  • @marceloaqno what about gpio interrupts, is that supported?

    I'm thinking to use a RPi as a pulse counter for water, electricity and gas with no radio, just ethernet or mqtt.
    In combination with a I2C display, this could be a nice project 😉

    Greetz,
    Eric



  • Hi,

    I have a raspberry Pi 2 that I've installed MyController on. This works fine, I can access it via the browser. I have also wired up an NRF24L01+ module to the GPIO pins on the Raspberry Pi. And I have followed the steps under "install and build", which seem to have worked fine. I didn't make any changes to the conf file. However now Im stuck. How do I setup the Raspberry Pi with the NRF24L01+ as a gateway in the MyController Gateway setup page in Safari?


  • Code Contributor

    @shfg There were some reports about this problem in the past, do you see any error messages in your mosquitto log?

    @ericvdb yes, you can attach a function to handle an interruption like this:

    uint8_t mode = FALLING;	// Valid options are: CHANGE, FALLING, RISING
    uint8_t physPin = 16;	// Choose a pin that fits your needs
    
    void irqHandler(void)
    {
    	// Process the interrupt
    }
    
    void setup() {
    	attachInterrupt(physPin, irqHandler, mode);
    }
    

    Support for I2C was added in the latest version.


  • Code Contributor

    @Christian-Simonsen If you are using the default build options for the RPi gateway, in MyController (Resources -> Add gateway) choose Ethernet for the type and enter your RPi ip address in the Host name field.



  • Is it compatible with pre-2.0 versions eg 1.5?



  • @Christian-Simonsen said:

    I have a raspberry Pi 2 that I've installed MyController on. This works fine, I can access it via the browser. I have also wired up an NRF24L01+ module to the GPIO pins on the Raspberry Pi. And I have followed the steps under "install and build", which seem to have worked fine. I didn't make any changes to the conf file. However now Im stuck. How do I setup the Raspberry Pi with the NRF24L01+ as a gateway in the MyController Gateway setup page in Safari?

    Thanks that did the trick



  • Hi,

    Background: I have a raspberry Pi 2 that I've installed MyController on. This works fine, I can access it via the browser. I have also wired up an NRF24L01+ module to the GPIO pins on the Raspberry Pi. I have also set up the raspberry pi as a gateway in the MyController Gateway setup page in Safari. It found it and it seem to work.

    However to my question. How do I know if the Raspberry Pi gateway with NRF24L01 work? How can I monitor what the Raspberry Pi gateway receive? Is there a similar way as the "Serial Monitor" that I use in the Arduino application, when accessing Arduino Uno via USB?

    If there is I need to monitor this via OSX Terminal.



  • @marceloaqno

    Today i tried to use the sketch Water Meter Pulse Sensor in mysGateway.cpp but i run into alot of errors, you have any idea?

    mysGateway.cpp:

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Marcelo Aquino <marceloaqno@gmail.org>
     * Copyleft (c) 2016, Marcelo Aquino
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     */
     
    #include <iostream>
    #include <cstdio>
    #include <unistd.h>
    
    // For more options run ./configure --help
    
    // Config file
    //#define MY_LINUX_CONFIG_FILE "/etc/mysensors.dat"
    
    // How many clients should be able to connect to this gateway (default 1)
    #define MY_GATEWAY_MAX_CLIENTS 10
    
    // Serial config
    // Enable this if you are using an Arduino connected to the USB
    //#define MY_LINUX_SERIAL_PORT "/dev/ttyACM0"
    // Enable this if you need to connect to a controller running on the same device
    //#define MY_IS_SERIAL_PTY
    // Choose a symlink name for the PTY device
    //#define MY_LINUX_SERIAL_PTY "/dev/ttyMySensorsGateway"
    // Grant access to the specified system group for the serial device
    //#define MY_LINUX_SERIAL_GROUPNAME "tty"
    
    // MQTT options
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
    //#define MY_PORT 1883
    //#define MY_MQTT_CLIENT_ID "mysensors-1"
    //#define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
    //#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
    
    // Enable these if your MQTT broker requires usenrame/password
    //#define MY_MQTT_USER "username"
    //#define MY_MQTT_PASSWORD "password"
    
    // 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
    // Inverse the blinking feature
    //#define MY_WITH_LEDS_BLINKING_INVERSE
    
    #include <MySensors.h>
    
    #define DIGITAL_INPUT_SENSOR 26                  // The digital input you attached your sensor.  (Only 2 and 3 generates interrupt!)
    
    #define PULSE_FACTOR 1000                       // Nummber of blinks per m3 of your meter (One rotation/liter)
    
    #define SLEEP_MODE false                        // flowvalue can only be reported when sleep mode is false.
    
    #define MAX_FLOW 40                             // Max flow (l/min) value to report. This filters outliers.
    
    #define CHILD_ID 1                              // Id of the sensor child
    
    unsigned long SEND_FREQUENCY = 30000;           // Minimum time between send (in milliseconds). We don't want to spam the gateway.
    
    MyMessage flowMsg(CHILD_ID,V_FLOW);
    MyMessage volumeMsg(CHILD_ID,V_VOLUME);
    MyMessage lastCounterMsg(CHILD_ID,V_VAR1);
    
    double ppl = ((double)PULSE_FACTOR)/1000;        // Pulses per liter
    
    volatile unsigned long pulseCount = 0;   
    volatile unsigned long lastBlink = 0;
    volatile double flow = 0;  
    bool pcReceived = false;
    unsigned long oldPulseCount = 0;
    unsigned long newBlink = 0;   
    double oldflow = 0;
    double volume =0;                     
    double oldvolume =0;
    unsigned long lastSend =0;
    unsigned long lastPulse =0;
    
    void onPulse()     
    {
      if (!SLEEP_MODE)
      {
        unsigned long newBlink = micros();   
        unsigned long interval = newBlink-lastBlink;
    
        if (interval!=0)
        {
          lastPulse = millis();
          if (interval<500000L) {
            // Sometimes we get interrupt on RISING,  500000 = 0.5sek debounce ( max 120 l/min)
            return;   
          }
          flow = (60000000.0 /interval) / ppl;
        }
        lastBlink = newBlink;
      }
      pulseCount++; 
    }
    
    void setup() {
      attachInterrupt(DIGITAL_INPUT_SENSOR, onPulse, FALLING); 
    }
    
    void presentation() {
      // Present locally attached sensors here  
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Water Meter", "1.1");
    
      // Register this device as Waterflow sensor
      present(CHILD_ID, S_WATER);  
    }
    
    void loop() {
      // Send locally attached sensors data here
      unsigned long currentTime = millis();
    
        // Only send values at a maximum frequency or woken up from sleep
      if (SLEEP_MODE || (currentTime - lastSend > SEND_FREQUENCY))
      {
        lastSend=currentTime;
    
        if (!pcReceived) {
          //Last Pulsecount not yet received from controller, request it again
          request(CHILD_ID, V_VAR1);
          return;
        }
    
        if (!SLEEP_MODE && flow != oldflow) {
          oldflow = flow;
    
          Serial.print("l/min:");
          Serial.println(flow);
    
          // Check that we dont get unresonable large flow value. 
          // could hapen when long wraps or false interrupt triggered
          if (flow<((unsigned long)MAX_FLOW)) {
            send(flowMsg.set(flow, 2));                   // Send flow value to gw
          }  
        }
    
        // No Pulse count received in 2min 
        if(currentTime - lastPulse > 120000){
          flow = 0;
        } 
    
        // Pulse count has changed
        if ((pulseCount != oldPulseCount)||(!SLEEP_MODE)) {
          oldPulseCount = pulseCount;
    
          Serial.print("pulsecount:");
          Serial.println(pulseCount);
    
          send(lastCounterMsg.set(pulseCount));                  // Send  pulsecount value to gw in VAR1
    
          double volume = ((double)pulseCount/((double)PULSE_FACTOR));     
          if ((volume != oldvolume)||(!SLEEP_MODE)) {
            oldvolume = volume;
    
            Serial.print("volume:");
            Serial.println(volume, 3);
    
            send(volumeMsg.set(volume, 3));               // Send volume value to gw
          } 
        }
      }
      if (SLEEP_MODE) {
        sleep(SEND_FREQUENCY);
      }
    }
    

    ./configure --my-debug=enable --my-gateway=ethernet --my-radio=none --my-port=5003

    [SECTION] Detecting target machine.
    [OK] machine detected: SoC=BCM2835, Type=RPi, CPU=armv6l, REV=000e.
    [OK] init system detected: systemd
    [SECTION] Saving configuration.
    [SECTION] Cleaning previous builds.
    [OK] Finished.
    

    make:

    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_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/noniso.o drivers/Linux/noniso.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/Print.o drivers/Linux/Print.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/EthernetClient.o drivers/Linux/EthernetClient.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/SerialPort.o drivers/Linux/SerialPort.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/Stream.o drivers/Linux/Stream.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/IPAddress.o drivers/Linux/IPAddress.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/compatibility.o drivers/Linux/compatibility.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/SoftEeprom.o drivers/Linux/SoftEeprom.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/EthernetServer.o drivers/Linux/EthernetServer.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o examples_linux/mysGateway.o examples_linux/mysGateway.cpp
    examples_linux/mysGateway.cpp: In function âvoid onPulse()â:
    examples_linux/mysGateway.cpp:96:37: error: âmicrosâ was not declared in this scope
         unsigned long newBlink = micros();
                                         ^
    examples_linux/mysGateway.cpp: In function âvoid loop()â:
    examples_linux/mysGateway.cpp:166:41: error: call of overloaded âset(volatile long unsigned int&)â is ambiguous
           send(lastCounterMsg.set(pulseCount));                  // Send  pulsecount value to gw in VAR1
                                             ^
    examples_linux/mysGateway.cpp:166:41: note: candidates are:
    In file included from ./MySensors.h:319:0,
                     from examples_linux/mysGateway.cpp:60:
    ./core/MyMessage.cpp:222:12: note: MyMessage& MyMessage::set(const char*) <near match>
     MyMessage& MyMessage::set(const char* value) {
                ^
    ./core/MyMessage.cpp:222:12: note:   no known conversion for argument 1 from âvolatile long unsigned intâ to âconst char*â
    ./core/MyMessage.cpp:234:12: note: MyMessage& MyMessage::set(bool)
     MyMessage& MyMessage::set(bool value) {
                ^
    ./core/MyMessage.cpp:241:12: note: MyMessage& MyMessage::set(uint8_t)
     MyMessage& MyMessage::set(uint8_t value) {
                ^
    ./core/MyMessage.cpp:256:12: note: MyMessage& MyMessage::set(uint32_t)
     MyMessage& MyMessage::set(uint32_t value) {
                ^
    ./core/MyMessage.cpp:263:12: note: MyMessage& MyMessage::set(int32_t)
     MyMessage& MyMessage::set(int32_t value) {
                ^
    ./core/MyMessage.cpp:270:12: note: MyMessage& MyMessage::set(uint16_t)
     MyMessage& MyMessage::set(uint16_t value) {
                ^
    ./core/MyMessage.cpp:277:12: note: MyMessage& MyMessage::set(int16_t)
     MyMessage& MyMessage::set(int16_t value) {
                ^
    examples_linux/mysGateway.cpp:180:25: error: call of overloaded âsleep(long unsigned int&)â is ambiguous
         sleep(SEND_FREQUENCY);
                             ^
    examples_linux/mysGateway.cpp:180:25: note: candidates are:
    In file included from examples_linux/mysGateway.cpp:22:0:
    /usr/include/unistd.h:444:21: note: unsigned int sleep(unsigned int)
     extern unsigned int sleep (unsigned int __seconds);
                         ^
    In file included from ./MySensors.h:320:0,
                     from examples_linux/mysGateway.cpp:60:
    ./core/MySensorsCore.cpp:543:8: note: int8_t sleep(uint32_t, bool)
     int8_t sleep(const uint32_t sleepingMS, const bool smartSleep) {
            ^
    Makefile:46: recipe for target 'examples_linux/mysGateway.o' failed
    make: *** [examples_linux/mysGateway.o] Error 1
    


  • @marceloaqno

    i was able to get a bit further by replacing all "unsigned long" declarations with "uint"

    Remains unsolved:

    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_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/noniso.o drivers/Linux/noniso.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/Print.o drivers/Linux/Print.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/EthernetClient.o drivers/Linux/EthernetClient.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/SerialPort.o drivers/Linux/SerialPort.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/Stream.o drivers/Linux/Stream.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/IPAddress.o drivers/Linux/IPAddress.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/compatibility.o drivers/Linux/compatibility.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/SoftEeprom.o drivers/Linux/SoftEeprom.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o drivers/Linux/EthernetServer.o drivers/Linux/EthernetServer.cpp
    g++ -DMY_GATEWAY_LINUX -DMY_DEBUG -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI -Ofast -g -Wall -Wextra -DMY_PORT=5003  -I. -I./core -I./drivers/Linux -I./drivers/RPi -MMD -c -o examples_linux/mysGateway.o examples_linux/mysGateway.cpp
    examples_linux/mysGateway.cpp: In function âvoid onPulse()â:
    examples_linux/mysGateway.cpp:96:28: error: âmicrosâ was not declared in this scope
         uint newBlink = micros();
                                ^
    examples_linux/mysGateway.cpp: In function âvoid loop()â:
    examples_linux/mysGateway.cpp:180:25: error: call of overloaded âsleep(uint&)â is ambiguous
         sleep(SEND_FREQUENCY);
                             ^
    examples_linux/mysGateway.cpp:180:25: note: candidates are:
    In file included from examples_linux/mysGateway.cpp:22:0:
    /usr/include/unistd.h:444:21: note: unsigned int sleep(unsigned int)
     extern unsigned int sleep (unsigned int __seconds);
                         ^
    In file included from ./MySensors.h:320:0,
                     from examples_linux/mysGateway.cpp:60:
    ./core/MySensorsCore.cpp:543:8: note: int8_t sleep(uint32_t, bool)
     int8_t sleep(const uint32_t sleepingMS, const bool smartSleep) {
            ^
    Makefile:46: recipe for target 'examples_linux/mysGateway.o' failed
    make: *** [examples_linux/mysGateway.o] Error 1
    


  • I probably miss something, but why are trying to compile the arduino sketch on Raspberry Pi???


  • Admin

    @ericvdb

    As @Toyman implies, we haven't ported the full Arduino environment here. This should mainly be used for running the Serial/Ethernet gateway directly on your RPi.

    You cannot just run any MySensors example without risking to make heavy adaptations/implementation on your own.


  • Code Contributor

    @ericvdb micros() hasn't been ported, use:

    millis() /1000;
    

    for sleep(), replace:

    sleep(SEND_FREQUENCY);
    

    with

    sleep(SEND_FREQUENCY, false);
    

    Also, if you want to print something don't use Serial.print() or Serial.println(), use printf() or debug().

    Serial.print("l/min:");
    Serial.println(flow);
    

    should be:

    debug("l/min: %f\n", flow);
    

    as @hek said, the main focus now is to be used as a gateway, with time adding sensors will become less problematic.



  • @marceloaqno
    I have it almost working. Regarding the interrupt, I have to pull-up to 3.3V the io pin through a resistor of 10k?
    Right now the interrupt isn't firing



  • @marceloaqno thanks, turned on mosquitto logging and am getting this error on mosquitto:

    1476724216: Invalid protocol "MQTT" in CONNECT from 127.0.0.1.
    1476724216: Socket read error on client (null), disconnecting.

    Tried an alternative mosquitto broker on another server too - same error.



  • @marceloaqno

    I have it working 😃 only need to play with the debounce value



  • @marceloaqno I finally have the MQTT gateway working after upgrading mosquitto to the latest build... I had installed mosquitto with apt-get under Wheezy which apparently pulled an older version. In retrospect probably should have just upgraded to Jessie from the outset! Working perfectly now (still under wheezy though FWIW)... thanks!



  • This post is deleted!

  • Code Contributor

    @Christian-Simonsen start the gateway with debug enabled:

    mysGateway -d
    


  • @Christian-Simonsen If you don't have debug enabled you could also just use:

    tail -f /dev/ttyUSB20
    

    My port is named ttyUSB20. You should substitute whatever you have named your port.



  • @jerseyguy1996

    Thanks I'll test it. But it seems like I've jumped over a step or two. Or something isn't working. Nothing happened when I wrote "Make" in Terminal, so I jumped over this step. I guess that might be the problem.

    Do I have to configure (./configure -help) or can I use the default values when I connect the NRF24L01 to the GPIO pins?


  • Code Contributor

    @b0rmann what happened? Did you fixed the problem you described in your last message?



  • @marceloaqno

    it's my problem. accidentally disconnected power from nrf24 on running gw



  • @marceloaqno I have it completely working now. 😆 A Raspberry Pi PulseCounter for water/gas/electricity consumption measurements with ethernet/mqtt. I can post my code here if you want.

    Minor detail:

    millis() / 1000;
    

    should be

    millis() * 1000;
    

    to get micros() 😉


  • Code Contributor

    @ericvdb Congrats! oops, sorry about my mistake.



  • This post is deleted!


  • Seems I'm closing in to working solution. I didn't understand how to use the ./configure element before now. However I ended up with these configurations

    pi@raspberrypi:~ $ ./MySensors/configure --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyMySensorsGateway --my-radio=nrf24 --my-rf24-irq-pin=15
    [SECTION] Detecting target machine.
    [OK] machine detected: SoC=BCM2836, Type=Rpi2, CPU=armv7l, REV=a01041.
    [OK] init system detected: systemd
    [SECTION] Saving configuration.
    [SECTION] Cleaning previous builds.
    make: *** No rule to make target 'clean'.  Stop.
    [OK] Finished.
    pi@raspberrypi:~ $ sudo ./MySensors/examples_linux/mysGateway -d
    mysGateway: Starting gateway...
    mysGateway: Protocol version - 2.0.1-beta
    mysGateway: MCO:BGN:INIT GW,CP=RNNG--Q,VER=2.0.1-beta
    mysGateway: TSF:LRT:OK
    mysGateway: TSM:INIT
    mysGateway: TSM:INIT:TSP OK
    mysGateway: TSM:INIT:GW MODE
    mysGateway: TSM:READY
    mysGateway: MCO:REG:NOT NEEDED
    mysGateway: MCO:BGN:STP
    mysGateway: MCO:BGN:INIT OK,ID=0,PAR=0,DIS=0,REG=1
    mysGateway: TSM:READY:NWD REQ
    mysGateway: TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
    mysGateway: TSF:SRT:OK
    
    

    Based on this it seem to all be ok on the Raspberry Pi side.. So I uploaded the "MockMySensors" sketch to my Arduino Uno with NRF24 connected. Below is the code and failure message I get from the Arduino. Do I need to set a gateway address or something?

    Starting sensor (RNNNA-, 2.0.0)
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=254)
    TSM:FPAR
    TSP:MSG:SEND 254-254-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 254-254-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 254-254-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 254-254-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT```


  • Thanks for adding signing.

    I want to use my rPi to generate random soft serials for my sensors.
    Could all three "gen" commands output the line to put in SecurityPersonalizer.ino like it does when using the "set" commands?


  • Code Contributor

    @Christian-Simonsen you need to be within the MySensors folders to execute commands configure and make.
    I recommend you to test that everything is working before using the option --my-rf24-irq-pin=15

    Like this:

    cd MySensors
    ./configure --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyMySensorsGateway --my-radio=nrf24
    make
    sudo ./examples_linux/mysGateway -d
    

  • Code Contributor

    @NiklasO Done (#622). Thanks for the sugestion.



  • @marceloaqno said:

    cd MySensors
    ./configure --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyMySensorsGateway --my

    Thanks for letting me know, didn't know that not running it from the specific folder would have an impact.

    I reconfigured it as you recommended. and restarted the gateway, with the result below.

    pi@raspberrypi:~/MySensors $ sudo ./examples_linux/mysGateway -d
    mysGateway: Starting gateway...
    mysGateway: Protocol version - 2.0.1-beta
    mysGateway: MCO:BGN:INIT GW,CP=RNNG---,VER=2.0.1-beta
    mysGateway: TSF:LRT:OK
    mysGateway: TSM:INIT
    mysGateway: TSM:INIT:TSP OK
    mysGateway: TSM:INIT:GW MODE
    mysGateway: TSM:READY
    mysGateway: MCO:REG:NOT NEEDED
    mysGateway: MCO:BGN:STP
    mysGateway: MCO:BGN:INIT OK,ID=0,PAR=0,DIS=0,REG=1
    mysGateway: TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
    mysGateway: !TSF:MSG:LEN,0!=7
    mysGateway: TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
    mysGateway: !TSF:MSG:LEN,0!=7
    mysGateway: TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
    mysGateway: !TSF:MSG:LEN,0!=7
    mysGateway: TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
    mysGateway: !TSF:MSG:LEN,0!=7
    mysGateway: TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
    mysGateway: !TSF:MSG:LEN,0!=7
    mysGateway: TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
    mysGateway: !TSF:MSG:LEN,14!=7
    mysGateway: TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
    mysGateway: !TSF:MSG:LEN,0!=7
    mysGateway: TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
    mysGateway: !TSF:MSG:LEN,0!=7
    mysGateway: TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
    mysGateway: !TSF:MSG:LEN,14!=7
    mysGateway: TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
    mysGateway: !TSF:MSG:LEN,0!=7
    

    What is the best way to test if the gateway work? What sketch should I use on the arduino? and how do I see in Terminal that the mysGateway receive the transfer successfully?



  • very interesting data...

    journalctl -u mysgateway --since 13:15 | grep MSG:READ

    Oct 21 13:16:30 pi mysGateway[30406]: TSF:MSG:READ,3-3-0,s=3,c=1,t=23,pt=2,l=2,sg=0:97
    Oct 21 13:16:30 pi mysGateway[30406]: TSF:MSG:READ,3-3-0,s=4,c=1,t=23,pt=2,l=2,sg=0:6
    Oct 21 13:16:30 pi mysGateway[30406]: TSF:MSG:READ,3-10-0,s=3,c=1,t=23,pt=2,l=2,sg=0:97
    Oct 21 13:16:30 pi mysGateway[30406]: TSF:MSG:READ,3-10-0,s=0,c=1,t=0,pt=7,l=5,sg=0:24.6
    Oct 21 13:16:30 pi mysGateway[30406]: TSF:MSG:READ,3-10-0,s=4,c=1,t=23,pt=2,l=2,sg=0:6
    Oct 21 13:16:30 pi mysGateway[30406]: TSF:MSG:READ,3-10-0,s=3,c=1,t=23,pt=2,l=2,sg=0:97
    Oct 21 13:16:30 pi mysGateway[30406]: TSF:MSG:READ,3-3-0,s=0,c=1,t=0,pt=7,l=5,sg=0:12.7
    Oct 21 13:16:31 pi mysGateway[30406]: TSF:MSG:READ,3-10-0,s=0,c=1,t=0,pt=7,l=5,sg=0:12.7
    Oct 21 13:16:31 pi mysGateway[30406]: TSF:MSG:READ,3-10-0,s=4,c=1,t=23,pt=2,l=2,sg=0:6
    Oct 21 13:17:17 pi mysGateway[30406]: TSF:MSG:READ,2-2-0,s=251,c=1,t=0,pt=7,l=5,sg=0:24.5
    Oct 21 13:17:17 pi mysGateway[30406]: TSF:MSG:READ,2-2-0,s=167,c=1,t=0,pt=7,l=5,sg=0:24.6
    Oct 21 13:17:18 pi mysGateway[30406]: TSF:MSG:READ,2-10-0,s=251,c=1,t=0,pt=7,l=5,sg=0:24.5
    Oct 21 13:17:18 pi mysGateway[30406]: TSF:MSG:READ,3-10-0,s=0,c=1,t=0,pt=7,l=5,sg=0:12.7
    Oct 21 13:17:18 pi mysGateway[30406]: TSF:MSG:READ,2-10-0,s=167,c=1,t=0,pt=7,l=5,sg=0:24.6
    Oct 21 13:17:18 pi mysGateway[30406]: TSF:MSG:READ,2-10-0,s=251,c=1,t=0,pt=7,l=5,sg=0:24.5
    Oct 21 13:17:19 pi mysGateway[30406]: TSF:MSG:READ,10-10-0,s=12,c=1,t=0,pt=7,l=5,sg=0:34
    Oct 21 13:17:19 pi mysGateway[30406]: TSF:MSG:READ,10-10-0,s=14,c=1,t=0,pt=7,l=5,sg=0:24
    

    node 2
    sensor 167 - dht18b20 indoor
    sensor 251 - dht18b20 indoor

    node 3
    sensor 0 - dht18b20 outdoor
    sensor 3 - light (0..100)
    sensor 4 - light (0..100)

    questions:
    why node 2 and node 3 send messages directly and via node 10?

    24.6 - is actual value from 2/251, but gateway receive this value from 3/0 How is it possible?

    Oct 21 13:16:30 pi mysGateway[30406]: TSF:MSG:READ,3-10-0,s=0,c=1,t=0,pt=7,l=5,sg=0:24.6
    


  • Hi,

    Is there anyone here that can give me some one-to-one support this evening to setup the Raspberry Pi + NRF24L01 as a gateway with MyController, and a Arduino Uno + NRF24L01 as Sensor node. I'm stuck after trying various things over the past week, so looks like I need some additional skills/knowledge to get the first setup working.

    Maybe we can use Skype or some other medium. I will gladly pay a bit for this support if anyone is interested. I have some free time from 18:00 CET - 23:30 CET today...



  • hi, the gateway works but how display sensors in domoticz?
    Thank you very much



  • @nico you need a sensor to send data to GW and assuming you have GW added to Domoticz, Domoticz will add up corresponding values to "Devices"



  • I have a gateway and 1 sensor ,obviously.
    I have added serial GW but anyone sensor appear, i'm sure that the sensor works, and the gateway also (see with the command mysGateway -d).
    Can you have any idea ? Thank you



  • @nico I would suggest you open up a different post in the Troubleshooting section regarding this matter
    1 post GW and sensor logs
    2. How do you know that the GW was added to Domoticz? Logs please?



  • @Christian-Simonsen

    You can pretty much test out using any of the arduino examples here:

    https://github.com/mysensors/MySensors/tree/development/examples

    Each one will present itself to the gateway when it starts up and you will see the presentation in the debug log. Make sure to run:

    https://github.com/mysensors/MySensors/tree/development/examples/ClearEepromConfig

    on the arduino first to make sure it starts with a fresh eeprom. After you select an Arduino sketch to test it with (seriously it doesn't matter which one you try) make sure to look at the sketch and add:

    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    #define MY_NODE_ID 4
    

    For MY_NODE_ID you can select any number. Just make sure that each new sensor node that you create has a different node number so like start out at MY_NODE_ID 1 and when you make another sensor node you can #define MY_NODE_ID 2 and so on.

    Next load it up to the Arduino, open the serial monitor, and see what happens. If you watch the serial monitor on the arduino you will see it present itself to the gateway and then you can confirm it in the debug log on the raspberry pi.

    I think it is pretty normal to have the problems you are having. I uninstalled and reinstalled the gateway 3 times on the Raspberry Pi before I finally got it all figured out. Once you get it running it is a glorious thing.


  • Code Contributor

    @Christian-Simonsen

    mysGateway: TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
    mysGateway: !TSF:MSG:LEN,0!=7
    

    looks like a power issue with the nrf24 module.


  • Code Contributor

    @b0rmann Can you provide a full debug log of all involved nodes?



  • Can I attach one or more DallasTemp sensors on the Raspberry Pi gateway?



  • @marceloaqno said:

    @Christian-Simonsen

    mysGateway: TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
    mysGateway: !TSF:MSG:LEN,0!=7
    

    looks like a power issue with the nrf24 module.

    Ok,

    I've tested with the Voltmeter and the NRF24L01 module do get a steady 3.26 V. Both the gateway module and the Arduino sensor node...

    Im now building a few extra sensor nodes, so I can test without the Raspberry pi. Hopefully I can atleast get them talking based on Arduinos first. Before testing the Raspberry Pi.


  • Mod

    @Patrik-Söderström said:

    Can I attach one or more DallasTemp sensors on the Raspberry Pi gateway?

    I haven't seen anyone doing anything similar so it might require some work. But almost anything is possible given enough work 🙂



  • Has anyone else had an issue with getting a sensor node to reconnect after a lost connection? I can see it attempting to reconnect but even though it is back within range of the gateway it won't reestablish the connection. If I reset the node it re-establishes the connection without any problem. This is the cycle that it gets stuck in:

    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-3 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=3)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    !TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=fail:1
    TSP:CHKUPL:FAIL (hops=255)
    !TSM:UPL:FAIL
    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-3 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=3)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    !TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=fail:1
    TSP:CHKUPL:FAIL (hops=255)
    !TSM:UPL:FAIL
    TSM:FPAR
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR
    !TSP:SEND:TNR```


  • @Christian-Simonsen multimeter will not detect issues with the power feed (noise or unstable). It just says that you voltage under zero load is 3.3V.



  • Appears things are changing, please update wiki:
    Warning: --my-radio is deprecated, please use --my-transport



  • @mfalkvidd Alright 🙂 The thing is that I have my Raspberry Pi as a Gateway today near my server rack and would like to measure the temperatur. Maybe I just get a Nano to do the work for me. Just would have been great to use the Raspberry.


  • Mod

    @Patrik-Söderström You can probably connect a temperature sensor to the gpio pins and have your controller read the sensor (without using MySensors)


  • Code Contributor

    @carlyler Thanks for pointing that out.


  • Code Contributor



  • @marceloaqno Yes its 220 uF. It was all I had handy. I read somewhere that this may be a problem specific to the arduino nano. I may give it a try with the pro mini. Although I'm not sure what that may have to do with it.

    Edit: I tried the same sketch on an arduino pro mini and it worked fine. When I simulated a loss of connection by walking out of range of the gateway it immediately reestablished the connection when I got back within range. The only difference is that the pro mini is running at 8 mhz whereas the nano runs at 16 mhz. Not sure how that affects things.



  • Hello everyone. Is there a way to reduce the number of Heartbeat messages the gateway produces by itself? Using MYSController to analyze the data traffic, I see every 10 seconds a Heartbeat - would like to reduce this once everything is working as expected to maybe every 5 or 10 minutes...


  • Admin

    @Velo17

    Just sleep longer. It sends one heartbeat every time the node wakes up.



  • @Christian-Simonsen

    I have exactly the same error

    mysGateway: !TSF:MSG:LEN,0!=7

    Have you been able to resolve that problem yet? I have tried multiple radios with different capacitors and powersources grounded to the Raspberry Pi.

    thanks



  • @dopeeye

    Sadly not. I ended up creating an serial gateway (arduino with NRF24L01 and a USB connector) and connected this to the Raspberry Pi, rather than connecting the NRF24L01 directly to the GPIO pins. This worked perfectly straight away.



  • @Christian-Simonsen

    Too stubborn to give up, yet.
    If i find a resolution I will let you know



  • I would like to try this, but my pins19-23 are already used by other hardware. Has anyone tried using the SPI1 Pins?



  • @dopeeye I had this issue and unfortunately changed several things at once and got rid of it. However, one thing I noticed was I had different versions of mySensors in my library directory since I downloaded the examples package. Therefore the sensor was likely compiling on a different version than the Gateway. You might want to check that.

    If you could post more of your logs (sensor and gateway) it might help.



  • @marceloaqno

    When running as a service, is there a way to watch the debug log?


Log in to reply
 

Suggested Topics

  • 3
  • 5
  • 110
  • 347
  • 164
  • 2

20
Online

11.4k
Users

11.1k
Topics

112.7k
Posts