summaryrefslogtreecommitdiff
path: root/platformio/relayctl/src/mqtt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platformio/relayctl/src/mqtt.cpp')
-rw-r--r--platformio/relayctl/src/mqtt.cpp48
1 files changed, 20 insertions, 28 deletions
diff --git a/platformio/relayctl/src/mqtt.cpp b/platformio/relayctl/src/mqtt.cpp
index 0314c75..ad3caef 100644
--- a/platformio/relayctl/src/mqtt.cpp
+++ b/platformio/relayctl/src/mqtt.cpp
@@ -1,24 +1,16 @@
#include <ESP8266httpUpdate.h>
-#include "mqtt.h"
-#include "logging.h"
-#include "wifi.h"
-#include "config.def.h"
+
+#include <homekit/logging.h>
+#include <homekit/wifi.h>
+#include <homekit/util.h>
+#include <homekit/mqtt.h>
+
#include "relay.h"
-#include "config.h"
-#include "static.h"
-#include "util.h"
-#include "led.h"
+#include "mqtt.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";
@@ -38,7 +30,7 @@ using namespace espMqttClientTypes;
MQTT::MQTT() {
auto cfg = config::read();
- homeId = String(cfg.flags.node_configured ? cfg.home_id : wifi::HOME_ID);
+ homeId = String(cfg.flags.node_configured ? cfg.node_id : wifi::NODE_ID);
randomSeed(micros());
@@ -178,7 +170,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{
@@ -252,19 +244,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);
@@ -284,7 +276,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);
@@ -292,10 +284,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 {
@@ -317,9 +309,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 - CONFIG_NODE_SECRET_SIZE - MD5_SIZE,
Update.size());
} else {
PRINTF("mqtt/ota: position is invalid, expected %ul, got %ul\n", ota.written, index);