Node to Node Communication via Gatreway


  • Plugin Developer

    My topology is as follows,
    Node-1 <--> Gateway <--> Node-2.

    When I send message from Node-1 to Node-2 (or) Node-2 to Node-1 is not working,
    Node-1 and Node-2 are repeater nodes.

    Gateway does not route packets to another node in the network?


  • Admin

    That's strange. You probably have to look at the serial output from the nodes and gateway to find the cause.


  • Plugin Developer

    @hek Thank you I did serial debug, I'm not clear about route (to) address
    https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/MySensor.cpp#L401

    Node-1:
    send: 1-1-0-0 s=255,c=0,t=18,pt=0,l=6,sg=0,st=ok:1.5 b1
    send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    repeater started, id=1, parent=0, distance=1
    send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=16,sg=0,st=ok:LevelSensor
    send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
    send: 1-1-0-0 s=1,c=0,t=15,pt=0,l=6,sg=0,st=ok:1.5 b1
    send: 1-1-0-0 s=1,c=1,t=13,pt=2,l=2,sg=0,st=ok:0
    send: 1-1-3-3 s=1,c=1,t=13,pt=2,l=2,sg=0,st=fail:0

    above '3' is 'to' (route) address, I do not understand what is '3' and how it was calculated, I hope here 'to' should be a parent address, which is 0

    Gateway:
    0;0;3;0;9;gateway started, id=0, parent=0, distance=0
    0;0;3;0;14;Gateway startup complete.
    0;0;3;0;9;read: 1-1-0 s=255,c=0,t=18,pt=0,l=6,sg=0:1.5 b1
    1;255;0;0;18;1.5 b1
    0;0;3;0;9;read: 1-1-0 s=255,c=3,t=6,pt=1,l=1,sg=0:0
    1;255;3;0;6;0
    0;0;3;0;9;read: 1-1-0 s=255,c=3,t=11,pt=0,l=16,sg=0:LevelSensor

    1;255;3;0;11;LevelSensor
    0;0;3;0;9;read: 1-1-0 s=255,c=3,t=12,pt=0,l=3,sg=0:1.0
    1;255;3;0;12;1.0
    0;0;3;0;9;read: 1-1-0 s=1,c=0,t=15,pt=0,l=6,sg=0:1.5 b1
    1;1;0;0;15;1.5 b1
    0;0;3;0;9;read: 1-1-0 s=1,c=1,t=13,pt=2,l=2,sg=0:0
    1;1;1;0;13;0

    0;0;3;0;9;read: 3-3-0 s=255,c=0,t=18,pt=0,l=6,sg=0:1.5 b1
    3;255;0;0;18;1.5 b1
    0;0;3;0;9;read: 3-3-0 s=255,c=3,t=6,pt=1,l=1,sg=0:0
    3;255;3;0;6;0
    0;0;3;0;9;read: 3-3-0 s=255,c=3,t=11,pt=0,l=19,sg=0:LevelIndicator
    3;255;3;0;11;LevelIndicator
    0;0;3;0;9;read: 3-3-0 s=255,c=3,t=12,pt=0,l=3,sg=0:1.0
    3;255;3;0;12;1.0
    0;0;3;0;9;read: 3-3-0 s=1,c=0,t=15,pt=0,l=6,sg=0:1.5 b1
    3;1;0;0;15;1.5 b1

    Node-2:
    send: 3-3-0-0 s=255,c=0,t=18,pt=0,l=6,sg=0,st=ok:1.5 b1
    send: 3-3-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    repeater started, id=3, parent=0, distance=1
    send: 3-3-0-0 s=255,c=3,t=11,pt=0,l=19,sg=0,st=ok:LevelIndicator
    send: 3-3-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
    send: 3-3-0-0 s=1,c=0,t=15,pt=0,l=6,sg=0,st=ok:1.5 b1
    send: 3-3-1-1 s=1,c=1,t=13,pt=2,l=2,sg=0,st=fail:0


  • Admin

    What does your code look like on the sending node (1)?


  • Plugin Developer

    #define NODE_ID (int8_t) 1
    #define N_LEVEL_DISPLAY_ID (int8_t) 3
    #define S_LEVEL_DISPLAY_ID (int8_t) 1
    
    MySensor gw;
     gw.begin(incomingMessage, NODE_ID, true);
    MyMessage levelDisplayBoard(S_LEVEL_DISPLAY_ID, V_DISTANCE);
    levelDisplayBoard.setDestination(N_LEVEL_DISPLAY_ID);
    int dist = getDistance();
    gw.send(levelDisplayBoard.set(dist));
    

  • Admin

    I think node 1 has a corrupt routing table (it thinks node 3 is a child).

    Try clearing eeprom and re-upload your sketch. Or disable repeater-mode on it.


  • Plugin Developer

    How to print routing table in serial console?


  • Admin

    You have to read it from eeprom.
    It starts at position: EEPROM_ROUTES_ADDRESS (defined in MySensors.h)

    http://www.arduino.cc/en/Tutorial/EEPROMRead


  • Plugin Developer

    @hek you are right! There was an entry for Node-2 in Node-1 routing table, As it has direct access to Node-2, was trying to send directly. I removed the entry and now it's going throw gateway. All node works well. Perfect!

    I thing we have to add code to remove routing table entry dynamically if it face some N number of failures. It will make life easier for those who is shifting node from one location to another location often.



  • Hello,

    Sorry to resort to an old topic ...
    I am currently using mysensors RS485, and I would like to extend my installation with this protocol.
    and I would like to make the nodes communicate with each other through the gateway.
    But I can't do what I want ... help!
    on my node 4, I have an input and 1 output, the input activates and deactivates the output. (here no worries).
    On my node 5, I have an input to activate the output of node 4, so I can turn it off but not turn it on, and I don't see any frames towards the gateway

    here is the code for my node 5:

    // MySensors 
    #define MY_PARENT_NODE_ID 0                   // define if fixed parent
    #define MY_PARENT_NODE_IS_STATIC
    #undef MY_REGISTRATION_FEATURE                  // sketch moves on if no registration
    #define MY_NODE_ID 5                     // fixed node number
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable RS485 transport layer
    #define MY_RS485
    
    // Define this to enables DE-pin management on defined pin
    #define MY_RS485_DE_PIN 2
    
    // Set RS485 baud rate to use
    #define MY_RS485_BAUD_RATE 9600
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  5  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  6  // the PCB, on board LED
    
    
    // Enable this if RS485 is connected to a hardware serial port
    //#define MY_RS485_HWSERIAL Serial1
    //#include <MqttClient.h>
    #include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    
    #define CHILD_ID 4
    #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
    
    Bounce debouncer = Bounce(); 
    int oldValue=0;
    bool state;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_LIGHT);
    
    void setup()  
    {  
      // Setup the button
      pinMode(BUTTON_PIN,INPUT_PULLUP);
      // Activate internal pull-up
      //digitalWrite(BUTTON_PIN,HIGH);
      
      // After setting up the button, setup debouncer
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
      
    }
    
    void presentation() {
      // Register binary input sensor to gw (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.
      sendSketchInfo("Button", "1.1");
    
      
      present(CHILD_ID, S_LIGHT);  
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop() 
    {
      debouncer.update();
      // Get the update value
      int value = debouncer.read();
      if (value != oldValue && value==0) {
          msg.setDestination(4);
          send(msg.set(state?false:true), false);// Send new state and request ack back
      }
      oldValue = value;
    }  
    


  • @FullMetal Imo, you have to specify all send-settings in one line, e.g. like this:

    send(buttonMsg.setDestination(MY_SISTER_NODE_ID).setSensor(CHILD_ID_RESET).set( button[i] ? "1" : "0"));
    


  • @rejoe2
    thank you for your return,
    but I have the same problem, I manage to activate the relay of node 4 from node 5, but I cannot deactivate it. and when I act on node 5 the gateway does not receive frames since it calls node 4.
    I think that node 4 should send the relay status to node 5 so that it knows whether it is activated or not.


  • Admin

    @FullMetal Please post a full debug log of both nodes showing the observed behaviour.



  • @FullMetal Pls add also code from node 4.

    In general:

    • if you want also info from node 5 to be sent to your controller/gateway, you have to add a second (normal) send command.
    • wrt. to how node 4 reacts on the messages, you may better use sth. like a toggle logic.


  • @tekka @rejoe2
    Désolé de revenir si tard ..
    J'ai modifié mon code sur mes nœuds, mais le résultat n'est toujours pas là!

    Voici mes codes:

    node 4:

    // MySensors 
    #define MY_PARENT_NODE_ID 0                   // define if fixed parent
    #define MY_PARENT_NODE_IS_STATIC
    #undef MY_REGISTRATION_FEATURE                  // sketch moves on if no registration
    #define MY_NODE_ID 4                    // fixed node number
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable RS485 transport layer
    #define MY_RS485
    
    // Define this to enables DE-pin management on defined pin
    #define MY_RS485_DE_PIN 2
    
    // Set RS485 baud rate to use
    #define MY_RS485_BAUD_RATE 9600
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  5  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  6  // the PCB, on board LED
    
    
    
    #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 SYSTER_ID 5
    #define RELAY_ON 1
    #define RELAY_OFF 0
    
    Bounce debouncer = Bounce(); 
    int oldValue=0;
    bool state;
    
    MyMessage msg(CHILD_ID,V_LIGHT);
    //MyMessage msgconf(CHILD_ID,V_VAR1);
    
    void setup()  
    {  
      // Setup the button
      pinMode(BUTTON_PIN,INPUT_PULLUP);
      // 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);
    }
    
    /*
    *  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.setDestination(MY_PARENT_NODE_ID).setSensor(CHILD_ID).set(state?false:true), true); // Send new state and request ack back
          wait(100);
          send(msg.setDestination(SYSTER_ID).setSensor(CHILD_ID).set(state?false:true), true);
      }
      oldValue = value;
    } 
     
    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());
       } 
    
    }
    

    node 5:

    // MySensors 
    #define MY_PARENT_NODE_ID 0                   // define if fixed parent
    #define MY_PARENT_NODE_IS_STATIC
    #undef MY_REGISTRATION_FEATURE                  // sketch moves on if no registration
    #define MY_NODE_ID 5                     // fixed node number
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable RS485 transport layer
    #define MY_RS485
    
    // Define this to enables DE-pin management on defined pin
    #define MY_RS485_DE_PIN 2
    
    // Set RS485 baud rate to use
    #define MY_RS485_BAUD_RATE 9600
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  5  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  6  // the PCB, on board LED
    
    
    // Enable this if RS485 is connected to a hardware serial port
    //#define MY_RS485_HWSERIAL Serial1
    //#include <MqttClient.h>
    #include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    
    #define CHILD_ID 1
    #define SYSTER_ID 4
    #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
    
    Bounce debouncer = Bounce(); 
    int oldValue=0;
    bool state;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_LIGHT);
    
    void setup()  
    {  
      // Setup the button
      pinMode(BUTTON_PIN,INPUT_PULLUP);
      // Activate internal pull-up
      //digitalWrite(BUTTON_PIN,HIGH);
      
      // After setting up the button, setup debouncer
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
      
    }
    
    void presentation() {
      // Register binary input sensor to gw (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.
      sendSketchInfo("Button", "1.1");
    
      
      present(CHILD_ID, S_LIGHT);  
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop() 
    {
      debouncer.update();
      // Get the update value
      int value = debouncer.read();
      if (value != oldValue && value==0) {
          send(msg.setDestination(MY_PARENT_NODE_ID).setSensor(CHILD_ID).set(state?false:true), false);// Send new state and request ack back
          Serial.println("wait 1/10sec");
          wait(100);
          send(msg.setDestination(SYSTER_ID).setSensor(CHILD_ID).set(state?false:true), false);
      }
      oldValue = value;
    }  
    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(SYSTER_ID, state);
           
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       } 
    
    }
    

    From node 4, my output is activated and deactivated immediately, due to double sending

    from node 5, I can activate or deactivate if I launch the command from node 4 before otherwise.


  • Admin

    @FullMetal said in Node to Node Communication via Gatreway: Please upload the debug logs for further troubleshooting.



  • @tekka said in Node to Node Communication via Gatreway:

    @FullMetal said in Node to Node Communication via Gatreway: Please upload the debug logs for further troubleshooting.

    Sorry

    Debug logs node 4
    Press button node 4

    08:16:01.668 -> 13555 TSF:MSG:SEND,4-4-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
    08:16:01.701 -> 13582 TSF:MSG:READ,0-0-4,s=1,c=1,t=2,pt=1,l=1,sg=0:0
    08:16:01.701 -> 13586 TSF:MSG:ECHO
    08:16:01.701 -> This is an ack from gateway

    08:16:01.701 -> Incoming change for sensor:1, New status: 0

    08:16:01.800 -> 13678 TSF:MSG:SEND,4-4-5-5,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
    08:16:01.800 -> 13684 TSF:RTE:N2N OK
    08:16:01.800 -> 13703 TSF:MSG:READ,5-5-4,s=1,c=1,t=2,pt=1,l=1,sg=0:1
    08:16:01.833 -> 13708 TSF:MSG:ECHO
    08:16:01.833 -> This is an ack from gateway

    08:16:01.833 -> Incoming change for sensor:1, New status: 1

    Press button node 5

    08:21:01.371 -> 313012 TSF:MSG:READ,5-5-4,s=1,c=1,t=2,pt=1,l=1,sg=0:0
    08:21:01.371 -> Incoming change for sensor:1, New status: 0

    second press node 5

    08:21:06.238 -> 317865 TSF:MSG:READ,5-5-4,s=1,c=1,t=2,pt=1,l=1,sg=0:0
    08:21:06.238 -> Incoming change for sensor:1, New status: 0

    Debug logs node 5
    Press button node 4

    08:23:59.955 -> 51752 TSF:MSG:READ,4-4-5,s=1,c=1,t=2,pt=1,l=1,sg=0:1
    08:23:59.955 -> 51757 TSF:MSG:ECHO REQ
    08:23:59.988 -> 51777 TSF:MSG:SEND,5-5-4-4,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
    08:23:59.988 -> 51783 TSF:RTE:N2N OK
    08:23:59.988 -> Incoming change for sensor:1, New status: 1

    Press button node 5

    08:24:36.929 -> 88704 TSF:MSG:SEND,5-5-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
    08:24:36.929 -> wait 1/10sec

    08:24:37.062 -> 88827 TSF:MSG:SEND,5-5-4-4,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
    08:24:37.062 -> 88834 TSF:RTE:N2N OK

    Debug logs gateway
    Press button node 4 and node 5

    08:26:19.261 -> 0;255;3;0;9;79078 TSF:MSG:READ,4-4-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
    08:26:19.261 -> 0;255;3;0;9;79084 TSF:MSG:ACK REQ
    08:26:19.294 -> 0;255;3;0;9;79105 TSF:MSG:SEND,0-0-4-4,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
    08:26:19.294 -> 4;1;1;0;2;0
    08:26:20.321 -> 0;255;3;0;9;80116 TSF:MSG:READ,5-5-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
    08:26:20.321 -> 5;1;1;0;2;0



  • @tekka @rejoe2
    I just found!

    ask the gateway not to send back acq
    send(msg.setDestination(MY_PARENT_NODE_ID).setSensor(CHILD_ID).set(state?false:true), false); // Send new state and request ack back
    wait(100);
    send(msg.setDestination(SYSTER_ID).setSensor(CHILD_ID).set(state?false:true), true);



  • Good to her you found that point 😄.
    Imo you'd better change also your receive functions to not react on "ack" messages (via "else" prior to message.type-comparison).


Log in to reply
 

Suggested Topics

13
Online

11.4k
Users

11.1k
Topics

112.7k
Posts