Can't tell if time is set with TimeAwareSensor Sketch



  • I am running the TimeAwareSensor.ino sketch and I can't tell if the time ever gets set. I added a couple of serial print lines to the receiveTime function and they never get logged to my serial monitor. Also, timeReceived never gets set to true.

    // Example sketch showing how to request time from controller.
    // Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
    
    #include <SPI.h>
    #include <MySensor.h> 
    #include <Time.h> 
    
    MySensor gw;
    boolean timeReceived = false;
    unsigned long lastUpdate=0, lastRequest=0;
    
    void setup() 
    { 
      gw.begin();
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Clock", "1.0");
      // Request time from controller.
      gw.requestTime(receiveTime); 
    }
    
    // This is called when a new time value was received
    void receiveTime(unsigned long time) {
      // Ok, set incoming time
      Serial.print("Got Time");
      Serial.println(time);
      setTime(time);
      timeReceived = true;
    }
     
    void loop()    
    {    
      unsigned long now = millis();
      gw.process();
     
       // If no time has been received yet, request it every 10 second from controller
      // When time has been received, request update every hour
      if ((!timeReceived && now-lastRequest > 20*100)
        || (timeReceived && now-lastRequest > 60*1000*60)) {
        // Request time from controller.
        Serial.println("requesting time");
        gw.requestTime(receiveTime); 
        lastRequest = now;
      }
     
      // Print time every second
      if (timeReceived && now-lastUpdate > 1000) {
        Serial.print(hour());
        printDigits(minute());
        printDigits(second());
        Serial.print(" ");
        Serial.print(day());
        Serial.print(" ");
        Serial.print(month());
        Serial.print(" ");
        Serial.print(year());
        Serial.println();
        lastUpdate = now;
      }
    }
    
    void printDigits(int digits){
      // utility function for digital clock display: prints preceding colon and leading 0
      Serial.print(":");
      if(digits < 10)
        Serial.print('0');
      Serial.print(digits);
    }
    

    Here is the serial monitor output.

    sensor started, id 5
    send: 5-5-0-0 s=255,c=0,t=17,pt=0,l=3,st=ok:1.4
    send: 5-5-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
    read: 0-0-5 s=255,c=3,t=6,pt=0,l=1:I
    send: 5-5-0-0 s=255,c=3,t=11,pt=0,l=5,st=ok:Clock
    send: 5-5-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 5-5-0-0 s=255,c=3,t=1,pt=0,l=3,st=ok:1.0
    requesting time
    send: 5-5-0-0 s=255,c=3,t=1,pt=0,l=3,st=ok:1.0
    read: 0-0-5 s=255,c=3,t=4,pt=0,l=10:1411246677
    requesting time
    send: 5-5-0-0 s=255,c=3,t=1,pt=0,l=10,st=ok:1411246677
    read: 0-0-5 s=255,c=3,t=4,pt=0,l=10:1411246679
    requesting time
    send: 5-5-0-0 s=255,c=3,t=1,pt=0,l=10,st=ok:1411246679
    read: 0-0-5 s=255,c=3,t=4,pt=0,l=10:1411246681
    

    It seems like the sensor starts sending the time back to the controller but timeReceived never gets set to true so the current time is not printed to the serial monitor every second. Any suggestions?


  • Admin

    Looks like this when I run the sketch:

    requesting time
    send: 5-5-0-0 s=255,c=3,t=1,pt=0,l=1,st=ok:5
    read: 0-0-5 s=255,c=3,t=1,pt=0,l=10:1411255184
    23:19:44 20 9 2014
    23:19:44 20 9 2014
    23:19:45 20 9 2014
    23:19:46 20 9 2014
    

    There are some subtle differences. Why is your sensor sending in "1.0" as payload when requesting time? Looks wrong.
    Received package has t=4 on your side. That is not a time response (should be t=1). What type of controller are you running?



  • Thanks, changing type from 4 to 1 fixed it.



  • I have the same problem. Work goes through a repeater. Everything works, other than time.

    • Setup:
      sensor started, id=4, parent=0, distance=1
      send: 4-4-0-0 s=255,c=0,t=17,pt=0,l=5,st=fail:1.4.1
      send: 4-4-0-0 s=255,c=3,t=6,pt=1,l=1,st=fail:0
      read: 0-0-4 s=255,c=3,t=6,pt=0,l=1:M
      send: 4-4-0-0 s=255,c=3,t=11,pt=0,l=18,st=fail:Temperature Sensor
      send: 4-4-0-0 s=255,c=3,t=12,pt=0,l=3,st=fail:1.0
      send: 4-4-0-0 s=0,c=0,t=6,pt=0,l=5,st=fail:1.4.1
      lost parent
      find parent
      send: 4-4-255-255 s=255,c=3,t=7,pt=0,l=0,st=bc:
      read: 3-3-4 s=255,c=3,t=8,pt=1,l=1:1
      new parent=3, d=2
      read: 0-0-4 s=255,c=3,t=8,pt=1,l=1:0
      new parent=0, d=1
      send: 0-4-0-4 s=255,c=3,t=8,pt=1,l=1,st=fail:0
      send: 4-4-0-0 s=2,c=0,t=8,pt=0,l=5,st=fail:1.4.1
      send: 4-4-0-0 s=3,c=0,t=3,pt=0,l=5,st=fail:1.4.1
      send: 4-4-0-0 s=4,c=0,t=1,pt=0,l=5,st=fail:1.4.1
      gw.getStatus CHILD_ID_VIRT_Relay: 1
      send: 4-4-0-0 s=255,c=3,t=1,pt=0,l=5,st=fail:1.4.1
      lost parent
      read: 0-0-4 s=255,c=3,t=8,pt=1,l=1:0
      new parent=0, d=1
      requestTemperatures:
      requestTemperatures done:
      temperature done: 13.70
      temperature: 13.70
      send: 4-4-0-0 s=0,c=1,t=0,pt=7,l=5,st=fail:13.7
      send: 4-4-0-0 s=2,c=1,t=4,pt=7,l=5,st=fail:279
      send: 4-4-0-0 s=255,c=3,t=1,pt=1,l=1,st=fail:0
      gw.requestTime:0

Log in to reply
 

Suggested Topics

  • 3
  • 3
  • 2
  • 24
  • 2
  • 2

16
Online

11.2k
Users

11.1k
Topics

112.5k
Posts