You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, love the library! After reading the docs thoroughly, I have a pretty good handle on how to use everything.
However, the events set by me are not triggering. I've tried a lot
setting events to UTS vs myTZ
Passing a time_t object vs hr min sec arguments
Praying
anything else I could think of before posting here
I am using a heltec automation wifi kit 8 esp8266 w/ integrated 128 x 32 px oled display.
In the script, I know that loop keeps looping, because there is a clock that shows the current time on the board's display. Also with the debug set to INFO, I can see the NTP syncs regularly. So events() is being called.
When I set Debug level DEBUG, it does not show my events being created.
The event is supposed to trigger a function that flips a pin and changes the screen. It also sends some data along the serial line to show that the event triggered.
When I run the code below, I get the following, and then nothing when the event should trigger (I should see something on the serial monitor).
Any thoughts?
Serial Output
Serial Connected
WiFi Connected
Waiting for WiFi ... Querying pool.ntp.org ... ERROR: No network
connected
Waiting for time sync
Querying pool.ntp.org ... success (round trip 106 ms)
Received time: Friday, 10-May-19 19:14:21.456 UTC
Time is in sync
Time Synced
Friday, 10-May-2019 15:14:21 EDT Setting the 05:00:00 event
Friday, 10-May-2019 15:14:21 EDT Event set for 11-5-2019 05:00:00
Friday, 10-May-2019 15:14:21 EDT Setting the 10:00:00 event
Friday, 10-May-2019 15:14:21 EDT Event set for 11-5-2019 10:00:00
Friday, 10-May-2019 15:14:21 EDT Setting the 15:16:00 event
Friday, 10-May-2019 15:14:21 EDT Event set for 10-5-2019 15:16:00
Code:
/*
* A script to automate the actuation of a pin (Normally HIGH, Actuated LOW) for a set duration
*
* The board used is the Heltec WiFi kit 8 (I got mine on amazon)
* Note - the pinout diagram is all wrong on that particular board.
* Like, really, really wrong.
* My pin 12 is "D6"
*
* This script heavily utilizes the ezTime library for time keeping and event setting,
* So a big thanks to ropg for such a great library to use!
*
* This script is simplified to show some issues I am having with events
*
* By Andrew Shaw
*/
#include <ezTime.h>
#include <ESP8266WiFi.h>
#include "SSD1306Wire.h"
//#include "config.h"
#include "images.h"
#include "work_config.h"
//Event times, in global scope
uint8_t event1_hour = 5; // 5am
uint8_t event1_min = 0;
uint8_t event2_hour = 10;
uint8_t event2_min = 0;
uint8_t event3_hour = 15; // 3pm
uint8_t event3_min = 16;
uint8_t event_duration = 18000; // Event duration, seconds
//Define which pin the event pin is attached to
uint8_t event_pin = EVENT_PIN;
//Setup wifi credentials from config file.
char ssid[] = WIFI_SSID;
const char password[] = WIFI_PW;
//clearing the display, not going to use it for this sample.
SSD1306Wire display(0x3c, 4, 5, GEOMETRY_128_32);
//Create Timezone from config file, in global scope
Timezone myTZ;
char timezone_name[] = TIMEZONE_NAME;
void setup() {
setDebug(INFO);
pinMode(event_pin, OUTPUT);
digitalWrite(event_pin, HIGH);
Serial.begin(115200);
while (!Serial) { ; }
Serial.println("Serial Connected\n");
//Just clearing the display
pinMode(16, OUTPUT);
digitalWrite(16, LOW);
delay(50);
digitalWrite(16, HIGH);
display.init();
display.clear();
//Connect to WiFi
WiFi.begin (ssid, password);
Serial.println("WiFi Connected\n");
//Sync with NTP Server
waitForSync();
Serial.println("Time Synced\n");
//Set Timezone
myTZ.setLocation(timezone_name);
myTZ.setDefault();
Serial.print(myTZ.dateTime() + " ");
Serial.println("Timezone Set\n\n\n");
//Setting watering events to trigger for first time
make_next_event(event1_hour, event1_min, 0);
make_next_event(event2_hour, event2_min, 0);
make_next_event(event3_hour, event3_min, 0);
}
void idleDisplay() {
//This is where I have code for the oled display. not important.
}
void event_cycle(uint8_t hr, uint8_t mn, uint8_t sec){
Serial.print(myTZ.dateTime() + " ");
Serial.println("Executing the " + String(hr) + ":" + String(mn) + ":" + String(sec) + " event");
uint8_t time_left = event_duration; // This will be used to end the event.
digitalWrite(event_pin, LOW); //Turn on the relay
while (time_left > 0) {
//delay(1000);
//Or
//secondChanged is a boolean value, and is true when the second changes,
//but then goes back to false the next time you evaluate it.
while (!secondChanged()) {
delay(1);
}
time_left--; //decrement time left by one second
}
digitalWrite(event_pin, HIGH); //Turn off the relay
Serial.print(myTZ.dateTime() + " ");
Serial.println("Concluding the " + String(hr) + ":" + String(mn) + ":" + String(sec) + " event");
make_next_event(hr, mn, sec);
}
void make_next_event(uint8_t hr, uint8_t mn, uint8_t sec) {
//makeTime(hour, minute, second, day, month year)
time_t set_time = makeTime(hr, mn, sec, day(), month(), year());
if (myTZ.now() >= set_time) { // See if event set time has already elapsed
set_time += 86400; // 86400 seconds in 1 day
}
Serial.print(myTZ.dateTime() + " ");
Serial.println(" Setting the " + zeropad(hr, 2) + ":" + zeropad(mn, 2) + ":" + zeropad(sec, 2) + " event");
//setEvent(function, time_t object)
uint8_t setEvent(void event_cycle(uint8_t hr, uint8_t mn, uint8_t sec), time_t set_time);
Serial.print(myTZ.dateTime() + " ");
Serial.println(" Event set for " + String(day(set_time)) + "-" + String(month(set_time)) + "-" + String(year(set_time)) + " " + zeropad(hr, 2) + ":" + zeropad(mn, 2) + ":" + zeropad(sec, 2) + "\n");
}
void loop() {
//This is the events for the eztime library
//Needed to continually sync with NTP and trigger events, such as the watering events and the secondChanged() function
events();
//This function happens every time the internal clock's second changes.
//Unless an event is occuring...
if (secondChanged()) {
idleDisplay();
}
delay(5);
}
The text was updated successfully, but these errors were encountered:
First, love the library! After reading the docs thoroughly, I have a pretty good handle on how to use everything.
However, the events set by me are not triggering. I've tried a lot
I am using a heltec automation wifi kit 8 esp8266 w/ integrated 128 x 32 px oled display.
In the script, I know that loop keeps looping, because there is a clock that shows the current time on the board's display. Also with the debug set to INFO, I can see the NTP syncs regularly. So events() is being called.
When I set Debug level DEBUG, it does not show my events being created.
The event is supposed to trigger a function that flips a pin and changes the screen. It also sends some data along the serial line to show that the event triggered.
When I run the code below, I get the following, and then nothing when the event should trigger (I should see something on the serial monitor).
Any thoughts?
Serial Output
Serial Connected
WiFi Connected
Waiting for WiFi ... Querying pool.ntp.org ... ERROR: No network
connected
Waiting for time sync
Querying pool.ntp.org ... success (round trip 106 ms)
Received time: Friday, 10-May-19 19:14:21.456 UTC
Time is in sync
Time Synced
Timezone lookup for: America/New_York ... (round-trip 123 ms) success.
Olson: America/New_York
Posix: EST5EDT,M3.2.0,M11.1.0
Friday, 10-May-2019 15:14:21 EDT Timezone Set
Friday, 10-May-2019 15:14:21 EDT Setting the 05:00:00 event
Friday, 10-May-2019 15:14:21 EDT Event set for 11-5-2019 05:00:00
Friday, 10-May-2019 15:14:21 EDT Setting the 10:00:00 event
Friday, 10-May-2019 15:14:21 EDT Event set for 11-5-2019 10:00:00
Friday, 10-May-2019 15:14:21 EDT Setting the 15:16:00 event
Friday, 10-May-2019 15:14:21 EDT Event set for 10-5-2019 15:16:00
Code:
The text was updated successfully, but these errors were encountered: