gw.sleep issues



  • Got about 5 of my nodes up and running, most are just temp/hum. They all work great, as long as the (gw.sleep) is removed (happens on all the nodes). In the code below, its almost directly from the example code, but with the gw.sleep uncommented it reports once, and then went two days without another report (until i hit reset). Then the same happened again. I guarantee the room temp changed in that time. It's not just one node, it's any that sleep. Just want to know if I am doing something wrong, or how I can troubleshoot. I dont want to keep spamming the GW with the data from the nodes, for no reason.

    I also noticed, and this kind of makes sense, that any node set to listen for incoming messages, cant have the sleep. It causes it to miss the message.

    TIA.

        #include <MySensor.h>
        #include <SPI.h>
        #include <DHT.h>  
    
        #define CHILD_ID_HUM 0
        #define CHILD_ID_TEMP 1
    
        #define HUMIDITY_SENSOR_DIGITAL_PIN 2
    
        MySensor gw;
        
        DHT dht;
        float lastTemp;
        float lastHum;
        boolean metric = false; 
        MyMessage msgHum(CHILD_ID_HUM, V_HUM);
        MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
        unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
        void setup() {
    
          // Spin up MySensors
          gw.begin(NULL,22);
    
          dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
          // Let the controller know about our children
          gw.present(CHILD_ID_HUM, S_HUM);
          gw.present(CHILD_ID_TEMP, S_TEMP);
      
          metric = gw.getConfig().isMetric;
    metric=false;
          // Sensor is on wall power, so peg battery level at 100%
          gw.sendBatteryLevel(100);
        }
    
        void loop() {
        gw.process();  
        updateHumTemp();
    
        //gw.sleep(SLEEP_TIME); //sleep a bit
    
        }
        
    void updateHumTemp(){
      delay(dht.getMinimumSamplingPeriod());
    
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temperature != lastTemp) {
        lastTemp = temperature;
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        gw.send(msgTemp.set(temperature, 1));
        Serial.print("T: ");
        Serial.println(temperature);
      }
      
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          gw.send(msgHum.set(humidity, 1));
          Serial.print("H: ");
          Serial.println(humidity);
      }
    }```

  • Admin

    What does the serial log say? If you wait 30 seconds, does it wake up and send anything or just continue sleeping?



  • The log on the GW or the arduino? The GW, doesnt say anything, since nothing is received. I waited about 40 hours before hitting reset, which then sent a message once or twice, then never again until next reset.



  • @gigaguy
    Your node is not setup as a repeater yet you call gw.process(); in the loop?

    Could this be causing the node conflict?


  • Admin

    @gigaguy said:

    The log on the GW or the arduino?

    The node...

    @gigaguy
    Calling gw.process shouldn't matter.



  • ok, ill leave it plugged into computer and let you know about the log.

    Update: The arduino seems to be acting like there is no change in temp, and therefore, nothing to send. I am going to try removing the "temp != lastTemp" and see what happens. no errors or fails though, since it doesnt have anything to send.



  • Still nothing, as far as errors. It seems the nodes set up as relay are the ones that stop reporting. Should there be sensors on a relay node? maybe that is my issue?



  • @gigaguy

    I have sensors on relay nodes without problems, just use milis and sleep time, not the gw.sleep(SLEEP_TIME) to keep the relay node processing the messages.

    Something like this:

    if((lastMillis+SLEEP_TIME) < millis()) {
     // <code to read and send temp>
      lastMillis = millis();
    }
    gw.process();
    

    I have a similar set up, but I always send the temperature and humidity every 15 minutes.

    Puzeling issue, if you always print the temperature and last temperature what you get? is it really chaging?

    If your sensor node needs the relay node to reach the gateway and these are sleeping then you would get a buch of st:fail on the serial debug on the node.



  • @barduino Yeah the Temp bounces around since I removed the sleep, it is far less variable with the sleep. I am going to try with the gw.wait, i think this is the one that still processes while it waits. If not, I will try millis.


Log in to reply
 

Suggested Topics

14
Online

11.4k
Users

11.1k
Topics

112.7k
Posts