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)601000*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);
}
-
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: 17405944161740594416 is Thu, 27 Feb 2025 11:56:37 GMT which looks reasonable.
So question is, why doesn’t the node print the received time?
-
This post is deleted!
-
@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
-
@dpcons sorry...esp8266 wemos mini is the actual device.
-
@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.
-
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.
-
@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.
-
@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!
-
@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.
-
I think the relevant code is here:
https://github.com/mysensors/MySensors/blob/e298769eb73ba2da781a34d66cae345c6840b7c0/core/MySensorsCore.cpp#L473but I can’t see anything that looks broken.
-
@dpcons try changing
unsigned long
in your sketch touint32_t
Could be that the override needs to have an exact match.