Consistent NACK + RPI Gateway



  • Hi all,

    Since I moved to RPI gateway (which I prefer), I've been having consistent NACK on some messages. I suspect it is related (but maybe not the cause) with some node reboots / battery drain.

    On one node, I always (and I ran multiple tests) NACK when sending the RSSI message, despite temperature and humidity never get NACK.

    I already tried sending RSSI before Temp and Hum, but it always get NACK.

    The MQTT server still receives the information.

    Any insight on why this is happening?

    Node debug log

    17:31:35.480 -> 32362 TSF:MSG:SEND,2-2-0-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=1,st=OK:24.00
    17:31:35.580 -> 32467 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:95.00
    17:31:37.836 -> 34721 !TSF:MSG:SEND,2-2-0-0,s=2,c=1,t=48,pt=2,l=2,sg=0,ft=0,st=NACK:-61
    

    Gateway log

    Jun 15 17:31:35 DEBUG TSF:MSG:READ,2-2-0,s=1,c=1,t=0,pt=7,l=5,sg=0:24.00
    Jun 15 17:31:35 DEBUG GWT:TPS:TOPIC=mygateway1-out/2/1/1/0/0,MSG SENT
    Jun 15 17:31:35 DEBUG TSF:MSG:READ,2-2-0,s=0,c=1,t=1,pt=7,l=5,sg=0:95.00
    Jun 15 17:31:35 DEBUG GWT:TPS:TOPIC=mygateway1-out/2/0/1/0/1,MSG SENT
    Jun 15 17:31:36 DEBUG TSF:MSG:READ,2-2-0,s=2,c=1,t=48,pt=2,l=2,sg=0:-61
    Jun 15 17:31:36 DEBUG TSF:MSG:ECHO REQ
    Jun 15 17:31:39 DEBUG !TSF:MSG:SEND,0-0-2-2,s=2,c=1,t=48,pt=2,l=2,sg=0,ft=0,st=NACK:-61
    Jun 15 17:31:39 DEBUG GWT:TPS:TOPIC=mygateway1-out/2/2/1/0/48,MSG SENT
    

    Node code

    
    /**
     * 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 Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * 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.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0: Henrik EKblad
     * Version 1.1 - 2016-07-20: Converted to MySensors v2.0 and added various improvements - Torben Woltjen (mozzbozz)
     * 
     * DESCRIPTION
     * This sketch provides an example of how to implement a humidity/temperature
     * sensor using a DHT11/DHT-22.
     *  
     * For more information, please visit:
     * http://www.mysensors.org/build/humidity
     * 
     */
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Atualizar para nรณ esperado
    #define MY_NODE_ID 2
    
    // Novo driver para gateway RPI
    #define MY_RFM69_NEW_DRIVER
    
    // Enable and select radio type attached 
    //#define MY_RADIO_RF24
    #define MY_RADIO_RFM69
    //#define MY_RS485
    
    #define MY_RFM69_FREQUENCY RFM69_433MHZ  // Define for frequency setting. Needed if you're radio module isn't 868Mhz (868Mhz is default in lib)
    #define MY_IS_RFM69HW  // Mandatory if you radio module is the high power version (RFM69HW and RFM69HCW), Comment it if it's not the case
    
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <DHT.h>
    
    // Set this to the pin you connected the DHT's data pin to
    #define DHT_DATA_PIN 3
    
    // select the input pin for the battery sense point
    int BATTERY_SENSE_PIN = A0;
    int oldBatteryPcnt = 0;
    
    // Set this offset if the sensor has a permanent small offset to the real temperatures.
    // In Celsius degrees (as measured by the device)
    #define SENSOR_TEMP_OFFSET 0
    
    // Sleep time between sensor updates (in milliseconds)
    // Must be >1000ms for DHT22 and >2000ms for DHT11
    static const uint64_t UPDATE_INTERVAL = 600000;
    
    // Force sending an update of the temperature after n sensor reads, so a controller showing the
    // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
    // the value didn't change since;
    // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
    static const uint8_t FORCE_UPDATE_N_READS = 5;
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_RSSI 2               //RSSI
    #define CHILD_ID_BAT 3               //BATTERY
    
    
    float lastTemp;
    float lastHum;
    uint8_t nNoUpdatesTemp;
    uint8_t nNoUpdatesHum;
    bool metric = true;
    int8_t rssiVal;               //RSSI
    char rssiStr[10];             //RSSI
    
    
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgRSSI(CHILD_ID_RSSI,V_CUSTOM);
    DHT dht;
    
    
    
    
    
    void presentation()  
    { 
      // Send the sketch version information to the gateway
      sendSketchInfo("TemperatureAndHumidity", "1.1");
      sendSketchInfo("Battery Meter", "1.0");
    ///  sendSketchInfo("DHT11-v05");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP);
      present(CHILD_ID_RSSI, S_CUSTOM);
    
    
      metric = getControllerConfig().isMetric;
    }
    
    
    void setup()
    {
      // Battery
      // use the 1.1 V internal reference
      #if defined(__AVR_ATmega2560__)
        analogReference(INTERNAL1V1);
      #else
        analogReference(INTERNAL);
      #endif
      
      dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
      if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
        Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
      }
      // Sleep for the time of the minimum sampling period to give the sensor time to power up
      // (otherwise, timeout errors might occure for the first reading)
      sleep(dht.getMinimumSamplingPeriod());
    }
    
    
    void loop()      
    {  
      // Force reading sensor, so it works also after sleep()
      dht.readSensor(true);
    
      // Get temperature from DHT library
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
        Serial.println("Failed reading temperature from DHT!");
      } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
        // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
        lastTemp = temperature;
    
        // apply the offset before converting to something different than Celsius degrees
        temperature += SENSOR_TEMP_OFFSET;
    
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        // Reset no updates counter
        nNoUpdatesTemp = 0;
        send(msgTemp.set(temperature, 2));
    
        #ifdef MY_DEBUG
        Serial.print("T: ");
        Serial.println(temperature);
        #endif
      } else {
        // Increase no update counter if the temperature stayed the same
        nNoUpdatesTemp++;
      }
    
      // Get humidity from DHT library
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
        Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
        // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
        lastHum = humidity;
        // Reset no updates counter
        nNoUpdatesHum = 0;
        send(msgHum.set(humidity, 2));
    
        #ifdef MY_DEBUG
        Serial.print("H: ");
        Serial.println(humidity);
        #endif
      } else {
        // Increase no update counter if the humidity stayed the same
        nNoUpdatesHum++;
      }
    
    //  rssiVal = _radio.readRSSI();  // Old Driver
      rssiVal = RFM69_getReceivingRSSI();  // New Driver
      send(msgRSSI.set(rssiVal), true);
      #ifdef MY_DEBUG
      Serial.print("RSSI: ");
      Serial.println(rssiVal);
      #endif
    
      // Sleep for a while to save energy
      sleep(UPDATE_INTERVAL); 
    }
    

  • Mod

    @Oumuamua nice work on troubleshooting.

    The clear difference I see is that you request echo of the rssi message, but not for temp and hum.

    Could you try turning off the echo request and see if the NACK goes away? The behavior might give a clue to what the problem is.



  • Thanks for the hint @mfalkvidd

    After much research (mainly here and here), it does look like RFM69+RPI+Mysensors 2.3.x don't like each other very much.

    However, I updated my RPI code to the latest version (at RPI, move to MySensors directory, then "git pull", then make+install gateway again) and the NACK problem was completely solved. I also had many NACK during presentation, which all went away. Problem solved and it seems that the radio is performing faster (probably less time waiting ACK).

    I also tried to address the low RSSI at gateway (again, it seems a recurring problem for RFM69+RPI) using this code, but it didn't "make".

    Would you have any insight on the RSSI issue as well? It seems that you participated in some part of the discussion (here ๐Ÿ˜‰ ).

    Thanks!


  • Mod

    Sorry, I don't have any insights for the rssi issue.



  • Hi all,

    Should any one need, the fix mentioned in this page actually works.

    Thanks,


Log in to reply
 

Suggested Topics

  • 3
  • 5
  • 2
  • 6
  • 8

49
Online

11.4k
Users

11.1k
Topics

112.6k
Posts