[SOLVED] Ethernet gateway and node communication issue, 8221 !TSM:UPL:FAIL



  • Hello,
    I have MQTT ethernet gateway based on W5500 with attached relay connected to OpenHAB. I am able to control the relay and it works fine. The code of the gateway:

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    // Enable gateway ethernet module type
    //#define MY_GATEWAY_W5100
    #define MY_GATEWAY_ENC28J60
    
    
    #define MY_GATEWAY_MQTT_CLIENT
    
    // Set this nodes subscripe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "P"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "S"
    
    #define MY_CONTROLLER_IP_ADDRESS 192,168,0,50
    #define MY_PORT 1883
    
    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "M1"
    
    
    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4
    
    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with
    // radio on the same spi bus.
    #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
    #define MY_SOFTSPI
    #define MY_SOFT_SPI_SCK_PIN 14
    #define MY_SOFT_SPI_MISO_PIN 16
    #define MY_SOFT_SPI_MOSI_PIN 15
    #endif
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN
    #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN
    #define MY_RF24_CS_PIN 6
    #endif
    
    // Enable UDP communication
    //#define MY_USE_UDP  // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    #define MY_IP_ADDRESS 192,168,0,33
    
    // If using static ip you can define Gateway and Subnet address as well
    //#define MY_IP_GATEWAY_ADDRESS 192,168,0,100
    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // Renewal period if using DHCP
    //#define MY_IP_RENEWAL_INTERVAL 60000
    
    // The port to keep open on node server mode / or port to contact in client mode
    //#define MY_PORT 5003
    
    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
    
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Arduino examples use  "DEAD BEEF FEED" for the MAC address.
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
    
    
    #if defined(MY_USE_UDP)
    #include <EthernetUdp.h>
    #endif
    
    #include <Ethernet2.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 CHILD_ID_SWITCH 2
    #define RELAY_ON 1
    #define RELAY_OFF 0
    
    //DeviceAddress addrTemp1 = { 0x28, 0xFF, 0x57, 0x98, 0x80, 0x15, 0x42, 0x17 };
    //Bounce debouncer = Bounce(); 
    int oldValue=0;
    bool state;
    unsigned long t0;
    
    MyMessage msgButton(CHILD_ID_SWITCH, V_VAR1);
    MyMessage msg(CHILD_ID,V_STATUS);
    
    
    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);
      Serial.println("MY_NODE_ID: ");
      Serial.print(MY_NODE_ID);
      t0=millis();
    }
    
    
    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, V_STATUS);
      present(CHILD_ID_SWITCH, V_VAR1);
    }
    
    
    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;
      if ((millis()-t0) > 5000) ServerUpdate();
      delay(100);
    }
    
    
    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());
       } 
    }
    
    void ServerUpdate() {
      
      
      send(msgButton.set(133));
      send(msg.set(133));
      t0=millis();
    }
    
    

    Now I'm trying to connect the node through NRF24L01+. Just for test with another relay and switch. The code:

    #define MY_DEBUG 
    
    
    
    #define MY_NODE_ID 6
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enabled repeater feature for this node
    //#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 22   // Id of the sensor child
    #define RELAY_ON 1
    #define RELAY_OFF 0
    
    
    
    Bounce debouncer = Bounce(); 
    int oldValue=0;
    bool state;
    unsigned long t0;
    
    MyMessage msg(CHILD_ID,V_LIGHT);
    MyMessage msg2(CHILD_ID,V_STATUS);
    
    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);
        t0=millis();
    }
    
    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);
      present(CHILD_ID, V_STATUS);
    }
    
    /*
    *  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;
      
      if ((millis()-t0) > 5000) ServerUpdate();
      delay(100);
    } 
     
    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());
       } 
    }
    
    void ServerUpdate() {
      
      send(msg2.set(122));
      t0=millis();
    }
    

    But the messages are not going to MQTT broker, I use MQTT.fx, only when the node is started, there are only initiation messages:

    P/0/255/0/0/18 2.3.1
    P/0/255/3/0/11 Relay & Button
    P/0/255/3/0/12 1.0
    

    There are some debug errors in gateway output:

    0 MCO:BGN:INIT GW,CP=RNNGA---,REL=255,VER=2.3.1
    4 TSM:INIT
    5 TSF:WUR:MS=0
    11 TSM:INIT:TSP OK
    13 TSM:INIT:GW MODE
    15 TSM:READY:ID=0,PAR=0,DIS=0
    17 MCO:REG:NOT NEEDED
    1019 GWT:TPC:IP=192.168.0.33
    2023 MCO:BGN:STP
    MY_NODE_ID: 
    72024 MCO:BGN:INIT OK,TSP=1
    3028 GWT:TPC:IP=192.168.0.33
    4031 GWT:RMQ:MQTT RECONNECT
    4287 GWT:RMQ:MQTT CONNECTED
    4289 GWT:TPS:TOPIC=P/0/255/0/0/18,MSG SENT
    4294 GWT:TPS:TOPIC=P/0/255/3/0/11,MSG SENT
    4298 GWT:TPS:TOPIC=P/0/255/3/0/12,MSG SENT
    4303 GWT:TPS:TOPIC=P/0/1/0/0/2,MSG SENT
    4307 GWT:TPS:TOPIC=P/0/2/0/0/24,MSG SENT
    4312 TSM:READY:NWD REQ
    4349 TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
    4356 TSF:MSG:READ,6-6-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    4361 TSF:MSG:PINGED,ID=6,HP=1
    4399 !TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=NACK:1
    4406 TSF:MSG:READ,6-6-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    4411 TSF:MSG:PINGED,ID=6,HP=1
    4449 !TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=NACK:1
    6161 TSF:MSG:READ,6-6-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    6166 TSF:MSG:PINGED,ID=6,HP=1
    6204 !TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=NACK:1
    7112 GWT:TPS:TOPIC=P/0/2/1/0/24,MSG SENT
    7116 GWT:TPS:TOPIC=P/0/1/1/0/2,MSG SENT
    8222 TSF:MSG:READ,6-6-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    8227 TSF:MSG:PINGED,ID=6,HP=1
    8266 !TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=NACK:1
    10276 TSF:MSG:READ,6-6-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    10281 TSF:MSG:PINGED,ID=6,HP=1
    10319 !TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=NACK:1
    12130 GWT:TPS:TOPIC=P/0/2/1/0/24,MSG SENT
    12134 GWT:TPS:TOPIC=P/0/1/1/0/2,MSG SENT
    12339 TSF:MSG:READ,6-6-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    12344 TSF:MSG:PINGED,ID=6,HP=1
    12382 !TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=NACK:1
    14392 TSF:MSG:READ,6-6-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    14397 TSF:MSG:PINGED,ID=6,HP=1
    14436 !TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=NACK:1
    16446 TSF:MSG:READ,6-6-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    16451 TSF:MSG:PINGED,ID=6,HP=1
    16489 !TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=NACK:1
    17198 GWT:TPS:TOPIC=P/0/2/1/0/24,MSG SENT
    17202 GWT:TPS:TOPIC=P/0/1/1/0/2,MSG SENT
    18508 TSF:MSG:READ,6-6-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    18513 TSF:MSG:PINGED,ID=6,HP=1
    18551 !TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=NACK:1
    20563 TSF:MSG:READ,6-6-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    20568 TSF:MSG:PINGED,ID=6,HP=1
    20606 !TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=NACK:1
    22216 GWT:TPS:TOPIC=P/0/2/1/0/24,MSG SENT
    22220 GWT:TPS:TOPIC=P/0/1/1/0/2,MSG SENT
    22726 TSF:MSG:READ,6-6-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    22730 TSF:MSG:PINGED,ID=6,HP=1
    22769 !TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=NACK:1
    

    And the node output:

     
     __  __       ____
    |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
            |___/                      2.3.1
    
    16 MCO:BGN:INIT NODE,CP=RNNNA---,REL=255,VER=2.3.1
    26 TSM:INIT
    27 TSF:WUR:MS=0
    33 TSM:INIT:TSP OK
    35 TSM:INIT:STATID=6
    37 TSF:SID:OK,ID=6
    39 TSM:FPAR
    40 TSM:FPAR:STATP=0
    43 TSM:ID
    44 TSM:ID:OK
    45 TSM:UPL
    80 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=NACK:1
    2089 TSM:UPL
    2125 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=1,st=NACK:1
    4133 TSM:UPL
    4169 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=2,st=NACK:1
    6177 TSM:UPL
    6213 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=3,st=NACK:1
    8221 !TSM:UPL:FAIL
    8222 TSM:FPAR
    8224 TSM:FPAR:STATP=0
    8226 TSM:ID
    8227 TSM:ID:OK
    8228 TSM:UPL
    8265 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=4,st=NACK:1
    10272 TSM:UPL
    10308 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=5,st=NACK:1
    12316 TSM:UPL
    12352 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=6,st=NACK:1
    14360 TSM:UPL
    14396 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=7,st=NACK:1
    
    

    I'm not sure what 8221 !TSM:UPL:FAIL means. An "Uplink check failed, i.e. GW could not be pinged" ? Any ideas ?


  • Mod

    Welcome to the forum @ivosch

    st=NACK means that the sending node did not receive acknowledgement from the recipient.
    The most common cause is unstable power. The nrf24 is extremely sensitive to unstable power.

    Which capacitors are you using, and how is the nrf24 powered on the gateway and on the node?
    https://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help/ has a flowchart for efficient troubleshooting, check it out if you haven't already.

    There is a delay() call in the loop of the gateway. During delay, the gateway can not receive anything. Change the delay() call to wait() instead. Wait will process incoming messages.

    In the receive() function in the gateway, the code needs to check the sender. receive() will be triggered every time a node sends a message so with the current implementation the gateway will think that all V_LIGHT messages are intended for the gateway.



  • I use USB 3.0 HUB power with 10uF attached capacitors for gateway and node



  • I increased the capacity to 100uF and replaced delay() for wait() but no difference. Thanks for the hint about sender in receive() method, I will fix the functionality when the communication works. Any other idea?


  • Mod

    @ivosch Did you test with different power supplies?



  • hello,
    my bad. The second capacitor has not been properly attached, now the node is communicating! 🙂
    Thank you for the help.

    note: 10uF wasn't enough, 110uF works fine for me


Log in to reply
 

Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts