Skip to content

Commit 8ecf767

Browse files
committed
Make the firmware request the next wakeup time instead of sleeping always 24h
1 parent 04577f8 commit 8ecf767

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

firmware/epaperinfodisplay.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ http_request: # required by online_image
113113
verify_ssl: false #not supported on the Arduino framework
114114

115115
deep_sleep:
116+
id: my_deep_sleep
116117
run_duration: 1h # we explicitly enter deep sleep
117-
sleep_duration: 24h # TODO: Add a time component and use until: to wakeup in the night
118+
sleep_duration: 24h # default
118119

119120
script:
120121
- id: download_image_script
@@ -124,6 +125,20 @@ script:
124125
# format: "VCC is %.1f V"
125126
# args: ['id(vcc_sensor).state']
126127
- component.update: frame_image
128+
- http_request.get:
129+
url: !secret wakeup_time_url
130+
capture_response: true
131+
on_response:
132+
- lambda: |-
133+
if (response->status_code == 200) {
134+
int next = std::stoi(body);
135+
id(my_deep_sleep).set_sleep_duration(next * 1000);
136+
} else {
137+
id(my_deep_sleep).set_sleep_duration(6 * 60 * 60 * 1000); // default to 6h
138+
}
139+
on_error:
140+
- lambda: |-
141+
id(my_deep_sleep).set_sleep_duration(6 * 60 * 60 * 1000); // default to 6h
127142
- id: update_display_script
128143
then:
129144
- wifi.disable: # disable wifi after image was downloaded

firmware/secrets.yaml.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ wifi_ssid: "MyWiFi"
22
wifi_password: "changeme"
33
ota_password: "changeme"
44
fallback_ap_password: "changeme"
5-
image_url: "http://192.168.178.21:5000/frame.png"
5+
image_url: "http://192.168.178.21:5000/frame.png"
6+
wakeup_time_url: "http:///192.168.178.21:5000/next_wakeup_time"

software/app.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,17 @@ def frame_image():
262262
return "No image available", 404
263263
return send_file(BytesIO(last_image), mimetype='image/png')
264264

265+
@app.route('/next_wakeup_time')
266+
def next_wakeup_time():
267+
"""Tell the hardware in how many minute to check back. """
268+
now = datetime.now()
269+
next_wakeup = config['wakeup_time']
270+
next_wakeup_dt = datetime.strptime(next_wakeup, "%H:%M").replace(year=now.year, month=now.month, day=now.day)
271+
if next_wakeup_dt <= now:
272+
next_wakeup_dt += timedelta(days=1)
273+
seconds_until_next_wakeup = int((next_wakeup_dt - now).total_seconds())
274+
return str(seconds_until_next_wakeup)
275+
265276
@app.route('/status')
266277
def status():
267278
""" Serve the current status information. """

0 commit comments

Comments
 (0)