Compare commits

..

5 Commits

3 changed files with 113 additions and 18 deletions

View File

@ -1,16 +1,12 @@
# Generated on Sun 29 Sep 2019 09:08:01 PM CEST
# Generated on Fri 08 Nov 2019 12:52:27 AM CET
# Device,IPv4,Chan,Name,TimeSpec(UTC)
# esp8266_808501,192.168.9.7,0,Heli Basking Light,06:00:00-17:00:00
# esp8266_808501,192.168.9.7,1,Heli UV Light,05:45:00-17:15:00
# esp8266_052EE8,192.168.9.12,0,Heli Red/White LED,05:30:00-17:30:00
# esp8266_052FB1,192.168.9.13,0,Heli Blue LED,21:30:00-04:00:00
esp8266_807AAD,192.168.9.8,0,Sticky Basking Light,06:00:00-17:00:00
esp8266_807AAD,192.168.9.8,1,Sticky UV Light,05:45:00-17:15:00
esp8266_202936,192.168.9.10,0,Sticky Red/White LED,05:30:00-17:30:00
esp8266_053F26,192.168.9.11,0,Sticky Blue LED,21:30:00-04:00:00
esp8266_807AAD,192.168.9.8,0,Sticky Basking Light,07:00:00-17:00:00
esp8266_807AAD,192.168.9.8,1,Sticky UV Light,06:45:00-17:15:00
esp8266_202936,192.168.9.10,0,Sticky Red/White LED,06:30:00-17:30:00
esp8266_053F26,192.168.9.11,0,Sticky Blue LED,21:00:00-01:00:00
esp8266_807AAD,192.168.9.8,2,Sticky Fogging,16:02:00-16:22:00
esp8266_807AAD,192.168.9.8,3,Sticky Raining,16:15:00-16:15:15
esp8266_82BE2B,192.168.9.9,0,Heli LED front,05:30:00-16:30:00
esp8266_82BE2B,192.168.9.9,1,Heli LED back,05:50:00-16:10:00
esp8266_82BE2B,192.168.9.9,2,Heli Basking,06:10:00-15:50:00
esp8266_82BE2B,192.168.9.9,3,Heli Brightsun,06:00:00-16:00:00
esp8266_82BE2B,192.168.9.9,0,Heli LED front,06:30:00-16:30:00
esp8266_82BE2B,192.168.9.9,1,Heli LED back,06:50:00-16:10:00
esp8266_82BE2B,192.168.9.9,2,Heli Basking,07:10:00-15:50:00
esp8266_82BE2B,192.168.9.9,3,Heli Brightsun,07:00:00-16:00:00

1 # Generated on Sun 29 Sep 2019 09:08:01 PM CEST # Generated on Fri 08 Nov 2019 12:52:27 AM CET
2 # Device,IPv4,Chan,Name,TimeSpec(UTC) # Device,IPv4,Chan,Name,TimeSpec(UTC)
3 # esp8266_808501,192.168.9.7,0,Heli Basking Light,06:00:00-17:00:00 esp8266_807AAD,192.168.9.8,0,Sticky Basking Light,07:00:00-17:00:00
4 # esp8266_808501,192.168.9.7,1,Heli UV Light,05:45:00-17:15:00 esp8266_807AAD,192.168.9.8,1,Sticky UV Light,06:45:00-17:15:00
5 # esp8266_052EE8,192.168.9.12,0,Heli Red/White LED,05:30:00-17:30:00 esp8266_202936,192.168.9.10,0,Sticky Red/White LED,06:30:00-17:30:00
6 # esp8266_052FB1,192.168.9.13,0,Heli Blue LED,21:30:00-04:00:00 esp8266_053F26,192.168.9.11,0,Sticky Blue LED,21:00:00-01:00:00
esp8266_807AAD,192.168.9.8,0,Sticky Basking Light,06:00:00-17:00:00
esp8266_807AAD,192.168.9.8,1,Sticky UV Light,05:45:00-17:15:00
esp8266_202936,192.168.9.10,0,Sticky Red/White LED,05:30:00-17:30:00
esp8266_053F26,192.168.9.11,0,Sticky Blue LED,21:30:00-04:00:00
7 esp8266_807AAD,192.168.9.8,2,Sticky Fogging,16:02:00-16:22:00 esp8266_807AAD,192.168.9.8,2,Sticky Fogging,16:02:00-16:22:00
8 esp8266_807AAD,192.168.9.8,3,Sticky Raining,16:15:00-16:15:15 esp8266_807AAD,192.168.9.8,3,Sticky Raining,16:15:00-16:15:15
9 esp8266_82BE2B,192.168.9.9,0,Heli LED front,05:30:00-16:30:00 esp8266_82BE2B,192.168.9.9,0,Heli LED front,06:30:00-16:30:00
10 esp8266_82BE2B,192.168.9.9,1,Heli LED back,05:50:00-16:10:00 esp8266_82BE2B,192.168.9.9,1,Heli LED back,06:50:00-16:10:00
11 esp8266_82BE2B,192.168.9.9,2,Heli Basking,06:10:00-15:50:00 esp8266_82BE2B,192.168.9.9,2,Heli Basking,07:10:00-15:50:00
12 esp8266_82BE2B,192.168.9.9,3,Heli Brightsun,06:00:00-16:00:00 esp8266_82BE2B,192.168.9.9,3,Heli Brightsun,07:00:00-16:00:00

View File

@ -236,6 +236,97 @@ exit:
(void)fi;
}
static void rpc_timespec_replace_handler(struct mg_rpc_request_info *ri, void *cb_arg, struct mg_rpc_frame_info *fi, struct mg_str args) {
struct mgos_timespec *ts;
int idx;
char *spec = NULL;
char fn[100];
rpc_log(ri, args);
json_scanf(args.p, args.len, ri->args_fmt, &idx, &spec);
if (idx < 0 || idx >= channel_get_total()) {
mg_rpc_send_errorf(ri, 400, "idx must be between 0 and %d", channel_get_total() - 1);
ri = NULL;
goto exit;
}
ts = channel_get_timespec(idx);
if (!ts) {
mg_rpc_send_errorf(ri, 400, "timespec on channel %d isn't set", idx);
ri = NULL;
goto exit;
}
if (!timespec_clear_spec(ts)) {
mg_rpc_send_errorf(ri, 400, "Failed to clear timespec on channel %d", idx);
ri = NULL;
return;
}
channel_override_clear(idx);
if (!timespec_add_spec(ts, spec)) {
mg_rpc_send_errorf(ri, 400, "timespec '%Q' is malformed", spec);
ri = NULL;
goto exit;
}
snprintf(fn, sizeof(fn) - 1, "timespec.chan%d", idx);
if (!timespec_write_file(ts, fn)) {
mg_rpc_send_errorf(ri, 400, "Could not commit timespec to file: %s", fn);
ri = NULL;
return;
}
mg_rpc_send_responsef(ri, "{idx: %d}", idx);
ri = NULL;
exit:
if (spec) {
free(spec);
}
(void)cb_arg;
(void)fi;
}
static void rpc_followsun_get_handler(struct mg_rpc_request_info *ri, void *cb_arg, struct mg_rpc_frame_info *fi, struct mg_str args) {
rpc_log(ri, args);
mg_rpc_send_errorf(ri, 400, "Not implemented yet");
ri = NULL;
return;
(void)cb_arg;
(void)fi;
}
static void rpc_followsun_set_handler(struct mg_rpc_request_info *ri, void *cb_arg, struct mg_rpc_frame_info *fi, struct mg_str args) {
rpc_log(ri, args);
mg_rpc_send_errorf(ri, 400, "Not implemented yet");
ri = NULL;
return;
(void)cb_arg;
(void)fi;
}
static void rpc_followsun_clear_handler(struct mg_rpc_request_info *ri, void *cb_arg, struct mg_rpc_frame_info *fi, struct mg_str args) {
rpc_log(ri, args);
mg_rpc_send_errorf(ri, 400, "Not implemented yet");
ri = NULL;
return;
(void)cb_arg;
(void)fi;
}
static void rpc_followsun_replace_handler(struct mg_rpc_request_info *ri, void *cb_arg, struct mg_rpc_frame_info *fi, struct mg_str args) {
rpc_log(ri, args);
mg_rpc_send_errorf(ri, 400, "Not implemented yet");
ri = NULL;
return;
(void)cb_arg;
(void)fi;
}
void rpc_init() {
struct mg_rpc *c = mgos_rpc_get_global();
@ -245,4 +336,9 @@ void rpc_init() {
mg_rpc_add_handler(c, "Timespec.Get", "{idx: %d}", rpc_timespec_get_handler, NULL);
mg_rpc_add_handler(c, "Timespec.Clear", "{idx: %d}", rpc_timespec_clear_handler, NULL);
mg_rpc_add_handler(c, "Timespec.Add", "{idx: %d, spec: %Q}", rpc_timespec_add_handler, NULL);
mg_rpc_add_handler(c, "Timespec.Replace", "{idx: %d, spec: %Q}", rpc_timespec_replace_handler, NULL);
mg_rpc_add_handler(c, "FollowSun.Get", "{idx: %d}", rpc_followsun_get_handler, NULL);
mg_rpc_add_handler(c, "FollowSun.Clear", "{idx: %d}", rpc_followsun_clear_handler, NULL);
mg_rpc_add_handler(c, "FollowSun.Set", "{idx: %d, riseoffset: %d, setoffset: %d}", rpc_followsun_set_handler, NULL);
mg_rpc_add_handler(c, "FollowSun.Replace", "{idx: %d, riseoffset: %d, setoffset: %d}", rpc_followsun_replace_handler, NULL);
}

View File

@ -55,8 +55,11 @@ static float calcSun(int year, int month, int day, float latitude,
(cosDec * cos((M_PI / 180.0f) * latitude));
if (cosH > 1) {
// the sun never rises at this location on the specified date
return 0;
} else if (cosH < -1) {
}
if (cosH < -1) {
// the sun never sets at this location on the specified date
return 0;
}
@ -99,11 +102,11 @@ uint32_t calcSunSet(int year, int month, int day, float latitude,
uint32_t calcDaylight(int month, float latitude, uint32_t rise, uint32_t set) {
if (set == 0 || rise == 0) {
if (month < 4 || month > 9) {
if (latitude < 0) return 86400;
else return 0;
if (latitude <= -65.7) return 86400;
else if (latitude >= 65.7) return 0;
} else {
if (latitude > 0) return 86400;
else return 0;
if (latitude >= 65.7) return 86400;
else if (latitude <= -65.7) return 0;
}
}