Sun, 14 Apr 2024 14:41:38 +0200
Server json unit data list added
thermferm/mqtt.h | file | annotate | diff | comparison | revisions | |
thermferm/server.c | file | annotate | diff | comparison | revisions |
--- a/thermferm/mqtt.h Sun Apr 14 12:46:02 2024 +0200 +++ b/thermferm/mqtt.h Sun Apr 14 14:41:38 2024 +0200 @@ -49,6 +49,8 @@ void mqtt_connect(void); void mqtt_disconnect(void); +char *unit_data(units_list *unit, bool birth); + /** * @brief Publish DBIRTH for all active units. If there are no active units, don't * publish anything. This function should be called at program start.
--- a/thermferm/server.c Sun Apr 14 12:46:02 2024 +0200 +++ b/thermferm/server.c Sun Apr 14 14:41:38 2024 +0200 @@ -46,7 +46,6 @@ int my_server_state = 0; /* Thread running state */ int my_server_shutdown = 0; /* Thread shutdown */ -//int s; /* connected socket */ int ls; /* listen socket */ struct sockaddr_in myaddr_in; /* for local socket address */ @@ -1317,6 +1316,7 @@ srv_send(s, (char *)"UNIT LIST List all Units"); srv_send(s, (char *)"UNIT GET uuid Get Unit record by uuid"); srv_send(s, (char *)"UNIT PUT uuid Put Unit record by uuid"); + srv_send(s, (char *)"UNIT JSON uuid Get Unit record in json"); srv_send(s, (char *)"."); return 0; } @@ -1534,6 +1534,28 @@ return 0; } + if (strcmp(opt, (char *)"JSON") == 0) { + for (unit = Config.units; unit; unit = unit->next) { + if (strcmp(param, unit->uuid) == 0) { + char *payload, *payloadu; + + srv_send(s, (char *)"213 Unit json data follows:"); + payload = xstrcpy((char *)"{\"fermenter\":"); + payloadu = unit_data(unit, true); + payload = xstrcat(payload, payloadu); + payload = xstrcat(payload, (char *)"}"); + srv_send(s, payload); + free(payload); + free(payloadu); + payload = payloadu = NULL; + srv_send(s, (char *)"."); + return 0; + } + } + srv_send(s, (char *)"440 No such unit"); + return 0; + } + if (strcmp(opt, (char *)"PUT") == 0) { /* * Block main process