Skip to content

Commit

Permalink
Use millisecond timestamp for events
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fb-martin committed Nov 26, 2020
1 parent 6179d68 commit f6bd6e1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion housesprinkler.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ int main (int argc, const char **argv) {
housediscover_initialize (argc, argv);

gethostname (hostname, sizeof(hostname));
houselog_event (time(0), "SYSTEM", hostname, "START", "");
houselog_event ("SYSTEM", hostname, "START", "");
echttp_loop();
}

8 changes: 3 additions & 5 deletions housesprinkler_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,11 @@ const char *housesprinkler_config_load (int argc, const char **argv) {
UseFactoryDefaults = 1;
newconfig = echttp_parser_load (FactoryDefaultsConfigFile);
if (!newconfig) return "not accessible";
houselog_event (time(0), "SYSTEM", "CONFIG", "LOAD",
houselog_event ("SYSTEM", "CONFIG", "LOAD",
"FILE %s", FactoryDefaultsConfigFile);

} else {
houselog_event (time(0), "SYSTEM", "CONFIG", "LOAD",
"FILE %s", ConfigFile);
houselog_event ("SYSTEM", "CONFIG", "LOAD", "FILE %s", ConfigFile);
}

if (ConfigText) echttp_parser_free (ConfigText);
Expand Down Expand Up @@ -171,8 +170,7 @@ const char *housesprinkler_config_save (const char *text) {
close (fd);

UseFactoryDefaults = 0;
houselog_event (time(0), "SYSTEM", "CONFIG", "UPDATED",
"FILE %s", ConfigFile);
houselog_event ("SYSTEM", "CONFIG", "UPDATED", "FILE %s", ConfigFile);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion housesprinkler_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static void housesprinkler_index_response
// Now that we do got a brand new index, it is time to let everyone
// know about it.
//
houselog_event (now, "INDEX", SprinklerIndexOrigin, "APPLY",
houselog_event ("INDEX", SprinklerIndexOrigin, "APPLY",
"%d%% FROM %s (PRIORITY %d)",
SprinklerIndex, urlsource, ipriority);

Expand Down
8 changes: 4 additions & 4 deletions housesprinkler_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,11 @@ static void housesprinkler_program_activate
// Now that we know which index to apply, let's launch this program.
//
if (indexname) {
houselog_event (now, "PROGRAM", program->name, "START",
houselog_event ("PROGRAM", program->name, "START",
"%s, INDEX %d%% FROM %s",
manual ? "manual" : "scheduled", index, indexname);
} else {
houselog_event (now, "PROGRAM", program->name, "START",
houselog_event ("PROGRAM", program->name, "START",
"%s, NO INDEX", manual ? "manual" : "scheduled");
}

Expand Down Expand Up @@ -441,7 +441,7 @@ void housesprinkler_program_periodic (time_t now) {
if (housesprinkler_zone_idle()) {
for (i = 0; i < ProgramsCount; ++i) {
if (Programs[i].running) {
houselog_event (now, "PROGRAM", Programs[i].name, "STOP", "");
houselog_event ("PROGRAM", Programs[i].name, "STOP", "");
Programs[i].running = 0;
}
}
Expand Down Expand Up @@ -512,7 +512,7 @@ void housesprinkler_program_periodic (time_t now) {
void housesprinkler_program_switch (void) {
time_t now = time(0);
SprinklerState = !SprinklerState;
houselog_event (now, "PROGRAM", "SWITCH", SprinklerState?"ON":"OFF", "");
houselog_event ("PROGRAM", "SWITCH", SprinklerState?"ON":"OFF", "");
}

int housesprinkler_program_status (char *buffer, int size) {
Expand Down
8 changes: 4 additions & 4 deletions housesprinkler_zone.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static void housesprinkler_zone_cancelled
void housesprinkler_zone_cancel (SprinklerZone *zone) {

if (zone->url[0]) {
houselog_event (time(0), "ZONE", zone->name, "CANCEL", "manual");
houselog_event ("ZONE", zone->name, "CANCEL", "manual");
static char url[256];
snprintf (url, sizeof(url),
"%s/set?point=%s&state=off", zone->url, zone->name);
Expand All @@ -266,7 +266,7 @@ void housesprinkler_zone_stop (void) {
time_t now = time(0);

DEBUG ("%ld: Stop all zones\n", now);
houselog_event (now, "ZONE", "ALL", "STOP", "manual");
houselog_event ("ZONE", "ALL", "STOP", "manual");
for (i = 0; i < QueueNext; ++i) {
Queue[i].runtime = 0;
}
Expand Down Expand Up @@ -301,7 +301,7 @@ static int housesprinkler_zone_start (int zone,
now, Zones[zone].name, pulse);
if (Zones[zone].url[0]) {
if (!context || context[0] == 0) context = "manual";
houselog_event (now, "ZONE", Zones[zone].name, "START",
houselog_event ("ZONE", Zones[zone].name, "START",
"for %d seconds using %s (%s)",
pulse, Zones[zone].url, context);
static char url[256];
Expand Down Expand Up @@ -447,7 +447,7 @@ static void housesprinkler_zone_discovered
Zones[zone].status = 'i';
DEBUG ("Zone %s discovered on %s\n",
Zones[zone].name, Zones[zone].url);
houselog_event (time(0), "ZONE", Zones[zone].name, "ROUTE",
houselog_event ("ZONE", Zones[zone].name, "ROUTE",
"TO %s", Zones[zone].url);
}
}
Expand Down
2 changes: 1 addition & 1 deletion public/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
for (var i = response.sprinkler.events.length-1; i >= 0; --i) {
var event = response.sprinkler.events[i];
var timestamp = new Date(event[0] * 1000);
var timestamp = new Date(event[0]);
var row = document.createElement("tr");
row.appendChild(newColumn(timestamp.toLocaleString(), i));
row.appendChild(newColumn(event[1], i));
Expand Down

0 comments on commit f6bd6e1

Please sign in to comment.