Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Can't tell if time is set with TimeAwareSensor Sketch

Can't tell if time is set with TimeAwareSensor Sketch

Scheduled Pinned Locked Moved Troubleshooting
4 Posts 3 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mikeones
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by hek
      #2

      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?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mikeones
        wrote on last edited by
        #3

        Thanks, changing type from 4 to 1 fixed it.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Daemon D
          wrote on last edited by
          #4

          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
          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          19

          Online

          11.7k

          Users

          11.2k

          Topics

          113.0k

          Posts


          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • MySensors
          • OpenHardware.io
          • Categories
          • Recent
          • Tags
          • Popular