Getting system time from the controller



  • Just starting on a scene controller, which I intend to use to display temperatures from a mysensors sensor unit connected to my fridge. Right now I just trying to get the system time using "requestTime()" function.
    The system is communicating OK, I think. When I send the command, the "receiveTime() function never gets executed. Should I see this time request in the log??

    Here's the serial debug info: I don't get any error executing the requestTime() function
    requesting time
    450046 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=1,pt=0,l=0,sg=0,ft=0,st=OK:
    450375 TSF:MSG:READ,0-0-6,s=255,c=3,t=1,pt=0,l=10,sg=0:1740594416 ****What's this?

    The code follows: Anybody see any issues? Thanks for looking.
    /*
    Scene Controller Will be used to receive my Fridge and Freezer Temps and display on a MAX7917 7-Seg
    8 Character display.
    */

    // Enable debug prints to serial monitor
    #define MY_DEBUG

    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_RFM69

    #include <TimeLib.h>
    #include <SPI.h>
    #include <MySensors.h>
    #include <stdarg.h>

    #define CHILD_ID 1

    MyMessage on(CHILD_ID, V_SCENE_ON);
    MyMessage off(CHILD_ID, V_SCENE_OFF);

    bool timeReceived = false;
    unsigned long lastTimeUpdate=0, lastRequest=0;
    char timeBuf[20];

    void setup()
    {
    // Request time from controller.
    requestTime();
    }

    void presentation() {
    // Send the sketch version information to the gateway and Controller
    sendSketchInfo("Fridge Temp Displays", "1.0");
    present(CHILD_ID, S_SCENE_CONTROLLER);
    }

    void loop()
    {
    unsigned long now = millis();
    // 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 > (unsigned long)101000)
    || (timeReceived && now-lastRequest > (unsigned long)60
    1000*60)) {
    // Request time from controller.
    Serial.println("requesting time");
    bool status = requestTime();
    if(!status) Serial.println("time request failed");
    lastRequest = now;
    }

    // Update time every second
    if (timeReceived && now-lastTimeUpdate > 1000) {
    printTime();
    lastTimeUpdate = now;
    }
    }

    // This is called when a new time value was received
    void receiveTime(unsigned long time) {
    // Ok, set incoming time
    setTime(time);
    timeReceived = true;
    }

    void printTime() {
    sprintf(timeBuf, "%02d:%02d:%02d", hour(), minute(), second());
    Serial.println(timeBuf);
    }


Log in to reply
 

Suggested Topics

48
Online

11.5k
Users

11.1k
Topics

112.7k
Posts