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. Getting system time from the controller

Getting system time from the controller

Scheduled Pinned Locked Moved Troubleshooting
13 Posts 4 Posters 79 Views 3 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.
  • dpconsD Offline
    dpconsD Offline
    dpcons
    wrote on last edited by
    #1

    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);
    }

    1 Reply Last reply
    0
    • mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      The received message looks like this:
      Received Message
      Sender: 0
      Last Node: 0
      Destination: 6
      Sensor Id: 255
      Command: INTERNAL
      Message Type: I_TIME
      Payload Type: P_STRING
      Payload Length: 10
      Signing: 0
      Payload: 1740594416

      https://www.mysensors.org/build/parser?log=450375 TSF%3AMSG%3AREAD%2C0-0-6%2Cs%3D255%2Cc%3D3%2Ct%3D1%2Cpt%3D0%2Cl%3D10%2Csg%3D0%3A1740594416

      1740594416 is Thu, 27 Feb 2025 11:56:37 GMT which looks reasonable.

      So question is, why doesn’t the node print the received time?

      dpconsD 1 Reply Last reply
      0
      • skywatchS Offline
        skywatchS Offline
        skywatch
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • mfalkviddM mfalkvidd

          The received message looks like this:
          Received Message
          Sender: 0
          Last Node: 0
          Destination: 6
          Sensor Id: 255
          Command: INTERNAL
          Message Type: I_TIME
          Payload Type: P_STRING
          Payload Length: 10
          Signing: 0
          Payload: 1740594416

          https://www.mysensors.org/build/parser?log=450375 TSF%3AMSG%3AREAD%2C0-0-6%2Cs%3D255%2Cc%3D3%2Ct%3D1%2Cpt%3D0%2Cl%3D10%2Csg%3D0%3A1740594416

          1740594416 is Thu, 27 Feb 2025 11:56:37 GMT which looks reasonable.

          So question is, why doesn’t the node print the received time?

          dpconsD Offline
          dpconsD Offline
          dpcons
          wrote on last edited by
          #4

          @mfalkvidd
          Thanks for your response. Yes, that's the question. Did I neglect something in my code? Do I have to register the "receiveTime" routine? Is there any workaround to use the response data? This node is an ESP32 D1 mini...if that makes a difference. Does the operation depend on an interrupt?
          Again, thanks

          dpconsD mfalkviddM 2 Replies Last reply
          0
          • dpconsD dpcons

            @mfalkvidd
            Thanks for your response. Yes, that's the question. Did I neglect something in my code? Do I have to register the "receiveTime" routine? Is there any workaround to use the response data? This node is an ESP32 D1 mini...if that makes a difference. Does the operation depend on an interrupt?
            Again, thanks

            dpconsD Offline
            dpconsD Offline
            dpcons
            wrote on last edited by
            #5

            @dpcons sorry...esp8266 wemos mini is the actual device.

            1 Reply Last reply
            0
            • dpconsD dpcons

              @mfalkvidd
              Thanks for your response. Yes, that's the question. Did I neglect something in my code? Do I have to register the "receiveTime" routine? Is there any workaround to use the response data? This node is an ESP32 D1 mini...if that makes a difference. Does the operation depend on an interrupt?
              Again, thanks

              mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by
              #6

              @dpcons it could be that the gateway code for receiving time is (unintentionally) broken. I noticed that the other thread you found also was about a gateway.

              I have never used receivetime myself but I am pretty sure I have seen it working for other people on regular nodes.

              dpconsD 1 Reply Last reply
              0
              • nagelcN Offline
                nagelcN Offline
                nagelc
                wrote on last edited by
                #7

                I have found that controllers can be very slow to respond to time requests. Same experience for Domoticz and for Homeassistant. Try a wait(1500) after the time request.

                dpconsD 1 Reply Last reply
                0
                • nagelcN nagelc

                  I have found that controllers can be very slow to respond to time requests. Same experience for Domoticz and for Homeassistant. Try a wait(1500) after the time request.

                  dpconsD Offline
                  dpconsD Offline
                  dpcons
                  wrote on last edited by
                  #8

                  @nagelc Thanks for responding. The response from the controller seems to be very quick. The problem is the 'receiveTime' routine never gets executed. mfalkvidd stated that the response in the serial output looked reasonable so I'm assuming the controller is responding OK. I tried adding the delay(1500) but same issue.
                  Again, thanks for your response.

                  1 Reply Last reply
                  0
                  • mfalkviddM mfalkvidd

                    @dpcons it could be that the gateway code for receiving time is (unintentionally) broken. I noticed that the other thread you found also was about a gateway.

                    I have never used receivetime myself but I am pretty sure I have seen it working for other people on regular nodes.

                    dpconsD Offline
                    dpconsD Offline
                    dpcons
                    wrote on last edited by
                    #9

                    @mfalkvidd Thanks for the response. I once built the 'Display and Time' sensor and I remember it working...but that was about 3-4 years ago and I no longer have the device. Maybe I build it back up again and give it a shot!

                    dpconsD 1 Reply Last reply
                    0
                    • dpconsD dpcons

                      @mfalkvidd Thanks for the response. I once built the 'Display and Time' sensor and I remember it working...but that was about 3-4 years ago and I no longer have the device. Maybe I build it back up again and give it a shot!

                      dpconsD Offline
                      dpconsD Offline
                      dpcons
                      wrote on last edited by
                      #10

                      @dpcons I built the Time Display example and after a little futzing, I got it to talk to my NRF24L01 system but the receiveTimez() function looks broken. It appears to respond with data that's read, but function never executes.
                      Looks like I'll punt for now.

                      mfalkviddM 1 Reply Last reply
                      0
                      • mfalkviddM Offline
                        mfalkviddM Offline
                        mfalkvidd
                        Mod
                        wrote on last edited by
                        #11

                        I think the relevant code is here:
                        https://github.com/mysensors/MySensors/blob/e298769eb73ba2da781a34d66cae345c6840b7c0/core/MySensorsCore.cpp#L473

                        but I can’t see anything that looks broken.

                        1 Reply Last reply
                        0
                        • dpconsD dpcons

                          @dpcons I built the Time Display example and after a little futzing, I got it to talk to my NRF24L01 system but the receiveTimez() function looks broken. It appears to respond with data that's read, but function never executes.
                          Looks like I'll punt for now.

                          mfalkviddM Offline
                          mfalkviddM Offline
                          mfalkvidd
                          Mod
                          wrote on last edited by
                          #12

                          @dpcons try changing unsigned long in your sketch to uint32_t

                          Could be that the override needs to have an exact match.

                          dpconsD 1 Reply Last reply
                          0
                          • mfalkviddM mfalkvidd

                            @dpcons try changing unsigned long in your sketch to uint32_t

                            Could be that the override needs to have an exact match.

                            dpconsD Offline
                            dpconsD Offline
                            dpcons
                            wrote on last edited by
                            #13

                            @mfalkvidd Thanks, I'll try that.

                            1 Reply Last reply
                            1
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            12

                            Online

                            11.7k

                            Users

                            11.2k

                            Topics

                            113.1k

                            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