summaryrefslogtreecommitdiff
path: root/platformio/temphum/src/mqtt.cpp
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-05-17 04:06:18 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-05-17 04:06:18 +0300
commitc0111bf4d3dd91f54d27346970e4c6e0a1ce357e (patch)
treebeb15167412bc3ed60e3e11e9076d27ea6f437e5 /platformio/temphum/src/mqtt.cpp
parent893e21cc83ee1ecf236a005f1bf4893448e9b3ea (diff)
pio: products refactoring
Diffstat (limited to 'platformio/temphum/src/mqtt.cpp')
-rw-r--r--platformio/temphum/src/mqtt.cpp43
1 files changed, 17 insertions, 26 deletions
diff --git a/platformio/temphum/src/mqtt.cpp b/platformio/temphum/src/mqtt.cpp
index ff13e43..b3305ce 100644
--- a/platformio/temphum/src/mqtt.cpp
+++ b/platformio/temphum/src/mqtt.cpp
@@ -1,23 +1,14 @@
#include <ESP8266httpUpdate.h>
+#include <homekit/logging.h>
+#include <homekit/config.h>
+#include <homekit/util.h>
+#include <homekit/wifi.h>
+
#include "mqtt.h"
-#include "logging.h"
-#include "wifi.h"
-#include "config.def.h"
-#include "config.h"
-#include "static.h"
-#include "util.h"
-#include "led.h"
+#include "leds.h"
namespace homekit::mqtt {
-static const uint8_t MQTT_CA_FINGERPRINT[] = DEFAULT_MQTT_CA_FINGERPRINT;
-static const char MQTT_SERVER[] = DEFAULT_MQTT_SERVER;
-static const uint16_t MQTT_PORT = DEFAULT_MQTT_PORT;
-static const char MQTT_USERNAME[] = DEFAULT_MQTT_USERNAME;
-static const char MQTT_PASSWORD[] = DEFAULT_MQTT_PASSWORD;
-static const char MQTT_CLIENT_ID[] = DEFAULT_MQTT_CLIENT_ID;
-static const char MQTT_SECRET[HOME_SECRET_SIZE+1] = HOME_SECRET;
-
static const char TOPIC_DIAGNOSTICS[] = "stat";
static const char TOPIC_INITIAL_DIAGNOSTICS[] = "stat1";
static const char TOPIC_OTA_RESPONSE[] = "otares";
@@ -168,7 +159,7 @@ void MQTT::sendInitialDiagnostics() {
auto cfg = config::read();
InitialDiagnosticsPayload stat{
.ip = wifi::getIPAsInteger(),
- .fw_version = FW_VERSION,
+ .fw_version = CONFIG_FW_VERSION,
.rssi = wifi::getRSSI(),
.free_heap = ESP.getFreeHeap(),
.flags = DiagnosticsFlags{
@@ -224,19 +215,19 @@ void MQTT::handleAdminOtaPayload(uint16_t packetId, const uint8_t *payload, size
Update.runAsync(true);
if (index == 0) {
- if (length < HOME_SECRET_SIZE + MD5_SIZE) {
+ if (length < CONFIG_NODE_SECRET_SIZE + MD5_SIZE) {
PRINTLN("mqtt/ota: failed to check secret, first packet size is too small");
return;
}
- if (memcmp((const char*)payload, HOME_SECRET, HOME_SECRET_SIZE) != 0) {
+ if (memcmp((const char*)payload, CONFIG_NODE_SECRET, CONFIG_NODE_SECRET_SIZE) != 0) {
PRINTLN("mqtt/ota: invalid secret");
return;
}
- PRINTF("mqtt/ota: starting update, total=%ul\n", total-HOME_SECRET_SIZE);
+ PRINTF("mqtt/ota: starting update, total=%ul\n", total-NODE_SECRET_SIZE);
for (int i = 0; i < MD5_SIZE; i++) {
- md5Ptr += sprintf(md5Ptr, "%02x", *((unsigned char*)(payload+HOME_SECRET_SIZE+i)));
+ md5Ptr += sprintf(md5Ptr, "%02x", *((unsigned char*)(payload+CONFIG_NODE_SECRET_SIZE+i)));
}
md5[32] = '\0';
PRINTF("mqtt/ota: md5 is %s\n", md5);
@@ -256,7 +247,7 @@ void MQTT::handleAdminOtaPayload(uint16_t packetId, const uint8_t *payload, size
ota.dataPacketId = packetId;
- if (!Update.begin(total - HOME_SECRET_SIZE - MD5_SIZE)) {
+ if (!Update.begin(total - CONFIG_NODE_SECRET_SIZE - MD5_SIZE)) {
ota.clean();
#ifdef DEBUG
Update.printError(Serial);
@@ -264,10 +255,10 @@ void MQTT::handleAdminOtaPayload(uint16_t packetId, const uint8_t *payload, size
sendOtaResponse(OTAResult::UPDATE_ERROR, Update.getError());
}
- ota.written = Update.write(const_cast<uint8_t*>(payload)+HOME_SECRET_SIZE + MD5_SIZE, length-HOME_SECRET_SIZE - MD5_SIZE);
- ota.written += HOME_SECRET_SIZE + MD5_SIZE;
+ ota.written = Update.write(const_cast<uint8_t*>(payload)+CONFIG_NODE_SECRET_SIZE + MD5_SIZE, length-CONFIG_NODE_SECRET_SIZE - MD5_SIZE);
+ ota.written += CONFIG_NODE_SECRET_SIZE + MD5_SIZE;
- esp_led.blink(1, 1);
+ mcu_led->blink(1, 1);
PRINTF("mqtt/ota: updating %u/%u\n", ota.written, Update.size());
} else {
@@ -289,9 +280,9 @@ void MQTT::handleAdminOtaPayload(uint16_t packetId, const uint8_t *payload, size
}
ota.written += length;
- esp_led.blink(1, 1);
+ mcu_led->blink(1, 1);
PRINTF("mqtt/ota: updating %u/%u\n",
- ota.written - HOME_SECRET_SIZE - MD5_SIZE,
+ ota.written - NODE_SECRET_SIZE - MD5_SIZE,
Update.size());
} else {
PRINTF("mqtt/ota: position is invalid, expected %ul, got %ul\n", ota.written, index);