]> mj.ucw.cz Git - home-hw.git/commitdiff
BSB Daemon: MQTT timestamps
authorMartin Mares <mj@ucw.cz>
Sun, 1 Mar 2020 16:24:08 +0000 (17:24 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 1 Mar 2020 16:24:08 +0000 (17:24 +0100)
bsb/daemon/burrow-bsbd.c

index 98fec4c0fed9bd86bccac8b7f2f4b227bd666b18..b775924d3deceafe9d80af1cf06478063e18c314 100644 (file)
@@ -188,11 +188,11 @@ static void process_stats(time_t t, byte *resp, uint len)
        for (uint i=0; i < ARRAY_SIZE(stat_names) && 4*i + 3 < (uint) len; i++) {
                char item[64];
                snprintf(item, sizeof(item), "bsb/stats/%s", stat_names[i]);
-               mqtt_publish(item, "%u", (uint) get_u32_le(resp+4*i), t);
+               mqtt_publish(item, "%u %lld", (uint) get_u32_le(resp+4*i), (long long) t);
        }
 }
 
-static void process_info(byte *p, uint len)
+static void process_info(time_t t, byte *p, uint len)
 {
        if (len < 4)
                return;
@@ -206,42 +206,42 @@ static void process_info(byte *p, uint len)
                        if (len >= 4) {
                                int temp = get_s16_be(p);
                                uint press = get_u16_be(p + 2);
-                               mqtt_publish("burrow/heating/outside-temp", "%.2f", temp / 64.);
-                               mqtt_publish("burrow/heating/water-pressure", "%.1f", press / 10.);
+                               mqtt_publish("burrow/heating/outside-temp", "%.2f %lld", temp / 64., (long long) t);
+                               mqtt_publish("burrow/heating/water-pressure", "%.1f %lld", press / 10., (long long) t);
                        }
                        break;
                case 0x05000229:
                        // AGU.2 status
                        if (len >= 2) {
                                int temp = get_s16_be(p);
-                               mqtt_publish("burrow/heating/circuit1/mix-temp", "%.2f", temp / 64.);
+                               mqtt_publish("burrow/heating/circuit1/mix-temp", "%.2f %lld", temp / 64., (long long) t);
                        }
                        break;
                case 0x05040227:
                        // AGU.2 control
                        if (len >= 2) {
                                uint m = get_u16_be(p);
-                               mqtt_publish("burrow/heating/circuit1/mix-valve", "%u", m);
+                               mqtt_publish("burrow/heating/circuit1/mix-valve", "%u %lld", m, (long long) t);
                        }
                        break;
                case 0x3d2d0215:
                        // Room 1 status
                        if (len >= 2) {
                                int temp = get_s16_be(p);
-                               mqtt_publish("burrow/heating/circuit1/room-temp", "%.2f", temp / 64.);
+                               mqtt_publish("burrow/heating/circuit1/room-temp", "%.2f %lld", temp / 64., (long long) t);
                        }
                        break;
                case 0x3e2e0215:
                        // Room 2 status
                        if (len >= 2) {
                                int temp = get_s16_be(p);
-                               mqtt_publish("burrow/heating/circuit2/room-temp", "%.2f", temp / 64.);
+                               mqtt_publish("burrow/heating/circuit2/room-temp", "%.2f %lld", temp / 64., (long long) t);
                        }
                        break;
        }
 }
 
-static void process_answer(byte *p, uint len)
+static void process_answer(time_t t, byte *p, uint len)
 {
        if (len < 4)
                return;
@@ -285,10 +285,10 @@ static void process_frame(time_t t, byte *pkt, uint len)
 
        switch (pkt[BF_OP]) {
                case BSB_OP_INFO:
-                       process_info(body, body_len);
+                       process_info(t, body, body_len);
                        break;
                case BSB_OP_ANSWER:
-                       process_answer(body, body_len);
+                       process_answer(t, body, body_len);
                        break;
        }
 }