Sun, 05 Jan 2020 17:04:56 +0100
Added check for database changes for iSpindels such as a new beer, or changing mode. Added denity in Plato and SG to the iSpindel web screen. The iSpindels must be calibrated in Plato! A bit of documentation updated.
bmsd/bms.c | file | annotate | diff | comparison | revisions | |
bmsd/ispindels.c | file | annotate | diff | comparison | revisions | |
bmsd/mysql.c | file | annotate | diff | comparison | revisions | |
bmsd/mysql.h | file | annotate | diff | comparison | revisions | |
doc/bms-ch8.sgml | file | annotate | diff | comparison | revisions | |
www/js/mon_ispindel.js | file | annotate | diff | comparison | revisions | |
www/mon_ispindel.php | file | annotate | diff | comparison | revisions |
--- a/bmsd/bms.c Sun Jan 05 11:42:02 2020 +0100 +++ b/bmsd/bms.c Sun Jan 05 17:04:56 2020 +0100 @@ -133,8 +133,10 @@ while (my_shutdown == FALSE) { - usleep(5000000); + usleep(4000000); nodes_check_online(); + usleep(1000000); + ispindel_mysql_check(); } if (debug) fprintf(stdout, "[main] Exit from main loop\n");
--- a/bmsd/ispindels.c Sun Jan 05 11:42:02 2020 +0100 +++ b/bmsd/ispindels.c Sun Jan 05 17:04:56 2020 +0100 @@ -50,8 +50,8 @@ time_t timestamp; FILE *fp; - if (debug) - printf("ispindel_set: %s %s\n", node, payload); +// if (debug) +// printf("ispindel_set: %s %s\n", node, payload); /* * Search ispindel record in the memory array and use it if found. @@ -66,8 +66,8 @@ } } - if (debug) - printf("new_ispindel %s\n", new_ispindel ? "true":"false"); +// if (debug) +// printf("new_ispindel %s\n", new_ispindel ? "true":"false"); /* * Allocate new ispindel if not yet known. @@ -121,7 +121,7 @@ } } - ispindel_dump(ispindel); +// ispindel_dump(ispindel); if (new_ispindel) { if (ispindels == NULL) { @@ -143,8 +143,9 @@ * The data is complete, see if we can write a log entry. */ if (ispindel->beercode && strlen(ispindel->beercode) && ispindel->beername && strlen(ispindel->beername) && - (strcmp(ispindel->mode, (char *)"ON") == 0)) { + ispindel->online && (strcmp(ispindel->mode, (char *)"ON") == 0)) { datetime = malloc(72); + timestamp = time(NULL); mytime = localtime(×tamp); snprintf(datetime, 72, "%04d-%02d-%02d %02d:%02d:%02d", mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); @@ -157,6 +158,9 @@ snprintf(buf, 64, "%.5f", ispindel->gravity); line = xstrcat(line, buf); line = xstrcat(line, (char *)","); + snprintf(buf, 64, "%.5f", 1 + (ispindel->gravity / (258.6 - ((ispindel->gravity / 258.2) * 227.1)))); + line = xstrcat(line, buf); + line = xstrcat(line, (char *)","); snprintf(buf, 64, "%.5f", ispindel->battery); line = xstrcat(line, buf); line = xstrcat(line, (char *)",");
--- a/bmsd/mysql.c Sun Jan 05 11:42:02 2020 +0100 +++ b/bmsd/mysql.c Sun Jan 05 17:04:56 2020 +0100 @@ -338,6 +338,10 @@ for (tmpi = ispindels; tmpi; tmpi = oldtmpi) { oldtmpi = tmpi->next; + if (tmpi->uuid) + free(tmpi->uuid); + if (tmpi->alias) + free(tmpi->alias); if (tmpi->node) free(tmpi->node); if (tmpi->beercode) @@ -346,6 +350,8 @@ free(tmpi->beername); if (tmpi->beeruuid) free(tmpi->beeruuid); + if (tmpi->mode) + free(tmpi->mode); free(tmpi); } @@ -759,3 +765,49 @@ bms_mysql_query(query); free(query); } + + + +void ispindel_mysql_check(void) +{ + sys_ispindel_list *tmpp; + + if (ispindels == NULL) + return; + + if (mysql_query(con, "SELECT uuid,alias,beercode,beername,beeruuid,mode FROM mon_ispindels;")) { + syslog(LOG_NOTICE, "MySQL: SELECT uuid,alias,beercode,beername,beeruuid,mode FROM mon_ispindels error %u (%s))", mysql_errno(con), mysql_error(con)); + } else { + res_set = mysql_store_result(con); + if (res_set == NULL) { + syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con)); + } else { + while ((row = mysql_fetch_row(res_set)) != NULL) { + for (tmpp = ispindels; tmpp; tmpp = tmpp->next) { + if (strcmp(tmpp->uuid, row[0]) == 0) { + if (strcmp(tmpp->beercode, row[2]) || strcmp(tmpp->beername, row[3]) || strcmp(tmpp->beeruuid, row[4])) { + syslog(LOG_NOTICE, "ispindel `%s` change beer to `%s %s`", row[1], row[2], row[3]); + if (tmpp->beercode) + free(tmpp->beercode); + tmpp->beercode = xstrcpy(row[2]); + if (tmpp->beername) + free(tmpp->beername); + tmpp->beername = xstrcpy(row[3]); + if (tmpp->beeruuid) + free(tmpp->beeruuid); + tmpp->beeruuid = xstrcpy(row[4]); + } + if (strcmp(tmpp->mode, row[5])) { + syslog(LOG_NOTICE, "ispindel `%s` change mode `%s`", row[1], row[5]); + if (tmpp->mode) + free(tmpp->mode); + tmpp->mode = xstrcpy(row[5]); + } + } + } + } + mysql_free_result(res_set); + } + } +} +
--- a/bmsd/mysql.h Sun Jan 05 11:42:02 2020 +0100 +++ b/bmsd/mysql.h Sun Jan 05 17:04:56 2020 +0100 @@ -45,4 +45,12 @@ void ispindel_mysql_update(sys_ispindel_list *ispindel); void ispindel_mysql_death(char *alias); +/** + * @brief Check state changes in the database for all iSpindels and + * update the internal memory array. Called every 5 seconds from + * the main server thread. + */ +void ispindel_mysql_check(void); + + #endif
--- a/doc/bms-ch8.sgml Sun Jan 05 11:42:02 2020 +0100 +++ b/doc/bms-ch8.sgml Sun Jan 05 17:04:56 2020 +0100 @@ -83,13 +83,20 @@ is de unix tijd sinds 1 januari 1970. Niet alle controllers sturen een timestamp, controllers zonder klok laten dit weg. De tijd wordt dan door <code>bmsd</code> ingevuld en is de tijd dat het bericht ontvangen wordt. -Het `seq' nummer wordt met ieder bericht met 1 verhoogd.</para> +Het `seq' nummer wordt met ieder bericht met 1 verhoogd. +Ook dit nummer is niet altijd aanwezig.</para> +<para>In de `metric' groep is de `interval' optioneel. Dit wordt bijvoorbeeld +verstuurd door iSpindels en is de ingestelde update interval tijd in seconden. +Indien dit niet aanwezig is dan wordt 300 seconden als standaard waarde gebruikt. +Deze waarde wordt gebruikt om een apparaat als offline te markeren indien het langer +als twee maal deze tijd niet wordt gezien.</para> <programlisting> { "timestamp": 1532201089, "seq": 0, "metric": { "uuid": "b508f01c-1f82-4e8b-b0d2-d88ecfb53031", + "interval":300, "properties": { "hardwaremake": "Raspberry", "hardwaremodel": "Unknown", @@ -340,6 +347,13 @@ </programlisting> </sect1> +<sect1 id="payloadco2data"> +<title>Netwerk payload data formaat voor CO2 meters.</title> +<para> +Nog schrijven +</para> +</sect1> + <sect1 id="payloadco2log"> <title>Netwerk payload log formaat voor CO2 meters.</title> <para> @@ -369,22 +383,12 @@ </sect1> -<sect1 id="ispindellog"> -<title>Netwerk payload formaat voor de iSpindels.</title> +<sect1 id="payloadispindeldata"> +<title>Netwerk payload data formaat voor iSpindels.</title> <para> -De iSpindel is een extern project en verstuurd een afwijkend en simpel -formaat van MQTT berichten. De berichten die verstuurd worden met iedere -update zien er als volgt uit: +Nog schrijven </para> -<programlisting> - ispindel/<node>/tilt Tilt - ispindel/<node>/temperature 20.1250 - ispindel/<node>/temp_units C - ispindel/<node>/battery Volt - ispindel/<node>/gravity Gravity - ispindel/<node>/interval 900 - ispindel/<node>/RSSI WiFi.RSSI() -</programlisting> + <para> Voor iedere actieve iSpindel wordt bij iedere systeemstart een bericht gestuurd. Dit is ongeveer iedere 15 minuten. Omdat de iSpindel eenvoudige @@ -400,15 +404,16 @@ De bestandsnamen zijn <code>product_code\ product_name.log</code>. Het interne formaat is:</para> <programlisting> - 2019-10-11 16:13:33,70.12,22.250,3.576,1.032,900,-45 - | | | | | | | - 0 datetime + | | | | | | - 1 tilt -----------------+ | | | | | - 2 temperatuur -----------------+ | | | | - 3 batterij spanning -----------------+ | | | - 4 densiteit -------------------------------+ | | - 5 interval -------------------------------------+ | - 6 rssi ---------------------------------------------+ + 2020-01-05 14:01:53,19.3750,7.08093,1.02806,3.34724,38.78126,900,c0ffeeee-cafe-dead-bee0-2af236d50dc9 + | | | | | | | | + 0 datetime + | | | | | | | + 1 temperatuur -----------+ | | | | | | + 2 densiteit plato ---------------+ | | | | | + 3 densiteit SG --------------------------+ | | | | + 4 batterij voltage ------------------------------+ | | | + 5 tilt hoek ---------------------------------------------+ | | + 6 update interval ----------------------------------------------+ | + 7 ispindel uuid ------------------------------------------------------------------+ </programlisting> </sect1>
--- a/www/js/mon_ispindel.js Sun Jan 05 11:42:02 2020 +0100 +++ b/www/js/mon_ispindel.js Sun Jan 05 17:04:56 2020 +0100 @@ -76,7 +76,7 @@ ticksMinor: { size: '5%', interval: 2 }, ticksMajor: { size: '9%', interval: 10 }, ticksPosition: 'near', - min: 0990, max: 1120, width: 120, height: 375, + min: 0990, max: 1150, width: 120, height: 375, value: 1000, pointer: { pointerType: 'arrow', size: '15%', visible: true, offset: 0 }, colorScheme: 'scheme05', @@ -139,8 +139,10 @@ $('#info_battery').val(record.battery); $('#info_tilt').val(record.angle); + $('#info_plato').val(record.gravity); + $('#info_sg').val(plato_to_sg(record.gravity)); - gravity = plato_to_sg(record.gravity) * 1000; + var gravity = plato_to_sg(record.gravity) * 1000; $('#gaugeContainer_gravity').jqxLinearGauge({ value: gravity }); } }); @@ -161,7 +163,9 @@ }); $('#info_battery').jqxNumberInput(Show3dec); - $('#info_tilt').jqxNumberInput(Show3dec); + $('#info_tilt').jqxNumberInput(Show4dec); + $('#info_plato').jqxNumberInput(Show4dec); + $('#info_sg').jqxNumberInput(Show4dec); $('#gaugeContainer_temperature').jqxGauge(gaugeoptionst); $('#gaugeContainer_temperature').jqxGauge({ caption: { value: 'Temp: 00.000' }});
--- a/www/mon_ispindel.php Sun Jan 05 11:42:02 2020 +0100 +++ b/www/mon_ispindel.php Sun Jan 05 17:04:56 2020 +0100 @@ -11,33 +11,38 @@ <table style='width: 100%; padding: 10px;'> <col width="20%"> <col width="40%"> - <col width="40%"> - <tr><th colspan=3>iSpindel overzicht</th></tr> + <col width="20%"> + <col width="20%"> + <tr><th colspan=4>iSpindel overzicht</th></tr> <tr style="height: 25px;"> <td>Uuid</td> - <td colspan="2"><div id="info_uuid"></div></td> + <td colspan="3"><div id="info_uuid"></div></td> </tr> <tr style="height: 25px;"> <td>Systeem</td> <td><div id="info_system"></div></td> - <td><div id="info_online"></div></td> + <td colspan="2"><div id="info_online"></div></td> </tr> <tr style="height: 25px;"> <td>Code en bier</td> <td><div id="info_beer"></div></td> - <td><div id="select_beer"></div></td> + <td colspan="2"><div id="select_beer"></div></td> </tr> <tr style="height: 25px;"> <td>Werking</td> - <td colspan="2"><div id="info_mode"></div></td> + <td colspan="3"><div id="info_mode"></div></td> </tr> <tr style="height: 25px;"> <td>Batterij volt</td> - <td colspan="2"><div id="info_battery"></div></td> + <td><div id="info_battery"></div></td> + <td>Densiteit °P</td> + <td><div id="info_plato"></div></td> </tr> <tr style="height: 25px;"> <td>Tilt hoek °</td> - <td colspan="2"><div id="info_tilt"></div></td> + <td><div id="info_tilt"></div></td> + <td>Densiteit SG</td> + <td><div id="info_sg"></div></td> </tr> </table> </div>