-
Notifications
You must be signed in to change notification settings - Fork 239
Custom Clock Source, "custom millis" #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I see there are problems with AdafruitHuzzahESP8266 examples. I haven't modified anything on them so I don't know what could be happend. When you could, tell me what i can do to solve it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together. It looks awesome! I have added some comments. Your example is quite complex and already well documented. However, I have the feeling it is still quite complex for most users. Is there room to make it simpler?
Also the hardware you're using is quite special. Any chance you could add a ESP8266 or ESP32 example? These chips are more common and would also allow me to test this. :-)
static uint32_t offset = 0; | ||
|
||
if(didWakeup) { | ||
offset = rtcMillis() - millis(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you set didWakeup = false
after setting the offset, customMillis
will call rtcMillis
only once after wakeup, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, of course! I forgot it. Feel free to add it.
README.md
Outdated
void setClockSource(MQTTClientClockSourceCb); | ||
// Callback signature: uint32_t customMillis (void) {} | ||
|
||
void clearClockSource(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove clearClockSource
and make setClockSource
accept NULL
to reset to the default implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think passing NULL
or nullptr
already works. We just need to add it to the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, your are right. It would be easy to pass nullptr and keep code cleaner.
src/MQTTClient.h
Outdated
@@ -9,8 +9,11 @@ extern "C" { | |||
#include "lwmqtt/lwmqtt.h" | |||
}; | |||
|
|||
typedef uint32_t (*MQTTClientClockSourceCb)(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just call it MQTTClientClockSource
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes sure! I called it ...Cb because I was thinking on callbacks, but It could be MQTTClientClockSource
Hi @256dpi. I used this hardware because I thought Arduino UNO and ETH Shield are common. Maybe DS1307 rtc could be the most specific element. I must to apologize because I haven't any ESP8266 or ESP32 board. However, I have SAMD (18J) board and MKRGSM1400 too. I could try to send you 2 examples with this two boards but I can't send them before next week at least. SAMD and MKR boads let me use its internal rtc with i.e. RTCZero library (could be donwloaded for Arduino IDE library manager) |
Hello @256dpi . As I promised you, I have rectified the code following your suggestions and, also, I have amended my EthernetShieldSleep example, I forgot set to false "didWakeUp". Now, I have added anothter example based on MKR1400 (ArduinoMKRGSM1400Sleep). I expect this example will be easier and simpler than the other one. It uses SAMD internal RTC as clock source. Like I wrote, I haven't any ESP board so I can't write any example based on them. Tell me if I can help you with anything. Regards. |
Would you mind squashing the commits? Sorry for being picky. 😄 |
Please, check if it's well done. I'm not git expert! Regards. |
I decided to not add more examples to the example directory in the repo in favor of opening the wiki to everyone to contribute further examples. I added your example here: https://github.com/256dpi/arduino-mqtt/wiki/Deep-Sleep-with-Arduino-UNO,-Ethernet-Shield-W5100-&-DS1307-RTC. Feel free to make any changes you want. |
I have added new feature to set custom millis source (i.e. external RTC) to keep correct time between sleep cicles. #141 issues thread.
I have added an example using Arduino UNO + Ethernet Shield (W5100) + DS1307 for demo purposes.
Please, advice me if anything is wrong.