Skip to content
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

Adding support to turn off the blinking light after a while #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions OpenGarage/OpenGarage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ OptionStruct OpenGarage::options[] = {
{"atib", 3, 24, ""},
{"atob", OG_AUTO_NONE,255, ""},
{"noto", OG_NOTIFY_DO|OG_NOTIFY_DC,255, ""},
{"bas", OG_LIGHT_BLINK_FOREVER, OG_LIGHT_BLINK_MAX, ""},
{"usi", 0, 1, ""},
{"ssid", 0, 0, ""}, // string options have 0 max value
{"pass", 0, 0, ""},
Expand Down
8 changes: 7 additions & 1 deletion OpenGarage/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define _DEFINES_H

/** Firmware version, hardware version, and maximal values */
#define OG_FWV 120 // Firmware version: 120 means 1.2.0
#define OG_FWV 122 // Firmware version: 122 means 1.2.2
Copy link
Contributor Author

@jknaack jknaack Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes #79, at least going forward


/** GPIO pins */
#define PIN_RELAY 15 // D8 on nodemcu
Expand Down Expand Up @@ -108,6 +108,11 @@
#define OG_STATE_WAIT_RESTART 4
#define OG_STATE_RESET 9

#define OG_LIGHT_BLINK_FOREVER 0
#define OG_LIGHT_BLINK_MAX 99 // limited by rcnt to 99
#define OG_LIGHT_BLINK_TIME 25
#define OG_LIGHT_BLINK_NOTIFY 2000 // specifies how long the last blink should last before blinking turns off

#define CLOUD_NONE 0
#define CLOUD_BLYNK 1
#define CLOUD_OTC 2
Expand Down Expand Up @@ -161,6 +166,7 @@ typedef enum {
OPTION_ATIB, // automation interval B (in hours)
OPTION_ATOB, // automation options B
OPTION_NOTO, // notification options
OPTION_BAS, // blink count before turning the light off (0 means infinity)
OPTION_USI, // use static IP
OPTION_SSID, // wifi ssid
OPTION_PASS, // wifi password
Expand Down
4 changes: 3 additions & 1 deletion OpenGarage/html/sta_options.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<tr><td><b>Door Thres. (cm): </b></td><td><input type='text' size=3 maxlength=4 id='dth' data-mini='true' value=0></td></tr>
<tr><td><b>Car Thres. (cm):</b><br><small>set to 0 to disable</small></td><td><input type='text' size=3 maxlength=4 id='vth' data-mini='true' value=0 ></td></tr>
<tr><td><b>Status Check (s):</b><br><small>check status every</small></td><td><input type='text' size=3 maxlength=3 id='riv' data-mini='true' value=0></td></tr>
<tr><td><b>Blinks After Start:</b><br><small>set to 0 for always</small></td><td><input type='text' size=2 maxlength=2 id='bas' data-mini='true' value=0></td></tr>
<tr><td><b>Click Time (ms):</b></td><td><input type='text' size=3 maxlength=5 id='cdt' value=0 data-mini='true'></td></tr>
<tr><td><b>Switch Sensor:</b><br><small>on G04 and GND</small></td><td>
<select name='sn2' id='sn2' data-mini='true' onChange='update_sno()'>
Expand Down Expand Up @@ -193,7 +194,7 @@
e.preventDefault();
if(confirm('Submit changes?')) {
comm='co?dkey='+encodeURIComponent($('#dkey').val());
bc('sn1');bc('sn2');bc('sno');bc('dth');bc('vth');bc('riv');bc('alm');
bc('sn1');bc('sn2');bc('sno');bc('dth');bc('vth');bc('riv');bc('bas');bc('alm');
bc('lsz');bc('tsn');bc('htp');bc('cdt');bc('dri');bc('ati');bc('atib');
comm+='&aoo='+($('#aoo').is(':checked')?1:0);
comm+='&sto='+eval_cb('#to_cap');
Expand Down Expand Up @@ -253,6 +254,7 @@
$('#dth').val(jd.dth);
$('#vth').val(jd.vth);
$('#riv').val(jd.riv);
$('#bas').val(jd.bas);
$('#htp').val(jd.htp);
$('#cdt').val(jd.cdt);
$('#dri').val(jd.dri);
Expand Down
4 changes: 3 additions & 1 deletion OpenGarage/htmls.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ const char sta_options_html[] PROGMEM = R"(<head><title>OpenGarage</title><meta
<tr><td><b>Door Thres. (cm): </b></td><td><input type='text' size=3 maxlength=4 id='dth' data-mini='true' value=0></td></tr>
<tr><td><b>Car Thres. (cm):</b><br><small>set to 0 to disable</small></td><td><input type='text' size=3 maxlength=4 id='vth' data-mini='true' value=0 ></td></tr>
<tr><td><b>Status Check (s):</b><br><small>check status every</small></td><td><input type='text' size=3 maxlength=3 id='riv' data-mini='true' value=0></td></tr>
<tr><td><b>Blinks After Start:</b><br><small>set to 0 for always</small></td><td><input type='text' size=2 maxlength=2 id='bas' data-mini='true' value=0></td></tr>
<tr><td><b>Click Time (ms):</b></td><td><input type='text' size=3 maxlength=5 id='cdt' value=0 data-mini='true'></td></tr>
<tr><td><b>Switch Sensor:</b><br><small>on G04 and GND</small></td><td>
<select name='sn2' id='sn2' data-mini='true' onChange='update_sno()'>
Expand Down Expand Up @@ -555,7 +556,7 @@ function cbt(n,v=true) {$('#'+n).attr('checked',v).checkboxradio('refresh');}
e.preventDefault();
if(confirm('Submit changes?')) {
comm='co?dkey='+encodeURIComponent($('#dkey').val());
bc('sn1');bc('sn2');bc('sno');bc('dth');bc('vth');bc('riv');bc('alm');
bc('sn1');bc('sn2');bc('sno');bc('dth');bc('vth');bc('riv');bc('bas');bc('alm');
bc('lsz');bc('tsn');bc('htp');bc('cdt');bc('dri');bc('ati');bc('atib');
comm+='&aoo='+($('#aoo').is(':checked')?1:0);
comm+='&sto='+eval_cb('#to_cap');
Expand Down Expand Up @@ -615,6 +616,7 @@ update_sno();
$('#dth').val(jd.dth);
$('#vth').val(jd.vth);
$('#riv').val(jd.riv);
$('#bas').val(jd.bas);
$('#htp').val(jd.htp);
$('#cdt').val(jd.cdt);
$('#dri').val(jd.dri);
Expand Down
21 changes: 18 additions & 3 deletions OpenGarage/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static byte door_status_hist = 0;
static ulong curr_utc_time = 0;
static ulong curr_utc_hour= 0;
static HTTPClient http;
static bool light_blink_enabled = true;

void do_setup();

Expand Down Expand Up @@ -1111,8 +1112,10 @@ void check_status() {
static ulong checkstatus_timeout = 0;
static ulong checkstatus_report_timeout = 0;
if((curr_utc_time > checkstatus_timeout) || (checkstatus_timeout == 0)) { //also check on first boot
og.set_led(HIGH);
aux_ticker.once_ms(25, og.set_led, (byte)LOW);
if(light_blink_enabled) {
og.set_led(HIGH);
aux_ticker.once_ms(OG_LIGHT_BLINK_TIME, og.set_led, (byte)LOW);
}

// Read SN1 -- ultrasonic sensor
uint dth = og.options[OPTION_DTH].ival;
Expand Down Expand Up @@ -1164,7 +1167,19 @@ void check_status() {

// get temperature readings
og.read_TH_sensor(tempC, humid);
read_cnt = (read_cnt+1)%100;

read_cnt = (read_cnt+1)%100;

// once the light is disabled, quit blinking until a restart or a reset to 0.
byte blink_limit = og.options[OPTION_BAS].ival;
bool current_light_blink_enabled = light_blink_enabled;
light_blink_enabled = blink_limit == OG_LIGHT_BLINK_FOREVER || (light_blink_enabled && read_cnt <= blink_limit);

// do a long blink to notify that we are turning the light off
if(current_light_blink_enabled && !light_blink_enabled){
og.set_led(HIGH);
aux_ticker.once_ms(OG_LIGHT_BLINK_NOTIFY, og.set_led, (byte)LOW);
}

if (checkstatus_timeout == 0){
DEBUG_PRINTLN(F("First time checking status don't trigger a status change, set full history to current value"));
Expand Down