-
Notifications
You must be signed in to change notification settings - Fork 103
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
Modify OnTick_t typedef for ESP8266 platform #16
Open
gmag11
wants to merge
3
commits into
PaulStoffregen:master
Choose a base branch
from
gmag11:ESP_std_function
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* TimeAlarm_ESP8266.ino | ||
* | ||
* This example calls two repetitive timers, one every | ||
* 5 seconds and one every 22 seconds. A single shot | ||
* timer is triggered after 58 seconds too. It finishes | ||
* 5 senconds timer | ||
* | ||
* An alarm is triggered 1 minute after current time. | ||
* | ||
* At startup the time is syncd to NTP server, so | ||
* it requires NTP Client library from | ||
* https://github.com/gmag11/NtpClient | ||
* | ||
* It uses a class to initalize triggers | ||
* to show how to use class methods as callbacks. | ||
* | ||
*/ | ||
|
||
#define YOUR_WIFI_SSID "Your_SSID" | ||
#define YOUR_WIFI_SSID "Your_Pw" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi gmag11, The line 21 should be corrected as follows: -#define YOUR_WIFI_SSID "Your_Pw" |
||
|
||
#include <TimeLib.h> | ||
#include <NtpClientLib.h> | ||
#include <ESP8266WiFi.h> | ||
#include <TimeAlarms.h> | ||
|
||
#include <functional> | ||
using namespace std; | ||
using namespace placeholders; | ||
|
||
class AlarmManager{ | ||
public: | ||
void begin() { | ||
while (timeStatus() != timeSet) { | ||
// Wait for time sync. Make yourself sure it can connect to WiFi | ||
Serial.print("."); | ||
delay(1000); | ||
} | ||
Serial.println(); | ||
|
||
//Set alarms | ||
Alarm.timerRepeat(0, 0, 22, std::bind(&AlarmManager::timer22,this)); | ||
alarm5 = Alarm.timerRepeat(0, 0, 5, std::bind(&AlarmManager::timer5, this)); | ||
Alarm.timerOnce(0, 0, 58, std::bind(&AlarmManager::timerOnce, this)); | ||
time_t alarm = now() + 60; // Current time + 1 minute | ||
Serial.printf("---- Set alarm at %s\r\n", NTP.getTimeDateString(alarm).c_str()); | ||
Alarm.alarmOnce(hour(alarm), minute(alarm), second(alarm), std::bind(&AlarmManager::alarmOnce, this)); | ||
} | ||
|
||
protected: | ||
AlarmId alarm5; | ||
|
||
void timer22() { | ||
static int i = 0; | ||
Serial.printf("-- %02d. timerRepeat every 22 seconds. It's %s. Uptime: %s\r\n", i, NTP.getTimeDateString().c_str(), NTP.getUptimeString().c_str()); | ||
i++; | ||
} | ||
|
||
void timer5() { | ||
static int i = 0; | ||
Serial.printf("- %02d. timerRepeat every 5 seconds. It's %s. Uptime: %s\r\n", i, NTP.getTimeDateString().c_str(), NTP.getUptimeString().c_str()); | ||
i++; | ||
} | ||
|
||
void timerOnce() { | ||
Serial.printf("--- TimerOnce at 58 seconds. It's %s. Uptime: %s\r\n", NTP.getTimeDateString().c_str(), NTP.getUptimeString().c_str()); | ||
} | ||
|
||
void alarmOnce() { | ||
Serial.printf("---- AlarmOnce. It's %s. Uptime: %s\r\n", NTP.getTimeDateString().c_str(), NTP.getUptimeString().c_str()); | ||
Alarm.free(alarm5); | ||
} | ||
|
||
}; | ||
|
||
AlarmManager manager; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
WiFi.mode(WIFI_STA); | ||
WiFi.begin(YOUR_WIFI_SSID, YOUR_WIFI_PASSWD); | ||
NTP.begin("pool.ntp.org", 1, true); //Start NTP Client | ||
manager.begin(); | ||
} | ||
|
||
void loop() | ||
{ | ||
Alarm.delay(0); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This pull request was not merged because of this change.
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.
Hi, even though I'm not the author of the pull request, I'm still wondering why line 245 is preventing the PR from being merged. Would you mind elaborating? To me the proposed extension seem to be implemented exactly as it is in other libraries (e.g. the ubiquitous "PubSubClient" MQTT client). The syntax change of line 245 simply ensures that the calling syntax is compatible with both cases: plain old function pointer and std::function.
I'd quite like to see this extension implemented in TimeAlarms. It allows for more elegant OOP design.
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 like you can have a try of my fork of the TimeAlarm. I rewrote it using the latest ESP 2.4 that is using Newlib C time functions.
https://github.com/jhagberg/ESP8266TimeAlarms
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 pointing that out! Personally I try as much as possible to use the libraries available through platform.io's package manager and treat those as the "canonical" versions. That's why I'm interested in contributing some minor ESP8266-relatex fixes. A second consideration is to use platform-agnostic libraries (AVR vs ESP) whenever possible.
But then again, having a rebased library specifically for the ESP8266's C library is quite nice, too. Thanks!
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 this code is not reviewed by anyone yet. But it will handle Timezones and Daylight savings very nicely without any extra library. And works for me for the moment at least!