summaryrefslogtreecommitdiff
path: root/platformio/common
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-05-31 09:22:00 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-06-03 01:01:27 +0300
commit0f0a5fd44867b684bcbafd102b6b769ae61229b4 (patch)
treed4845bd3295159c06041b25753af4eb2d7b59461 /platformio/common
parent3e3753d726f8a02d98368f20f77dd9fa739e3d80 (diff)
wip
Diffstat (limited to 'platformio/common')
-rw-r--r--platformio/common/libs/main/homekit/main.cpp21
-rw-r--r--platformio/common/libs/main/homekit/main.h4
-rw-r--r--platformio/common/libs/main/library.json2
-rw-r--r--platformio/common/libs/mqtt/homekit/mqtt/mqtt.cpp14
-rw-r--r--platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h5
-rw-r--r--platformio/common/libs/mqtt_module_relay/library.json2
6 files changed, 36 insertions, 12 deletions
diff --git a/platformio/common/libs/main/homekit/main.cpp b/platformio/common/libs/main/homekit/main.cpp
index fd08925..816c764 100644
--- a/platformio/common/libs/main/homekit/main.cpp
+++ b/platformio/common/libs/main/homekit/main.cpp
@@ -6,7 +6,12 @@
namespace homekit::main {
+#ifndef CONFIG_TARGET_ESP01
+#ifndef CONFIG_NO_RECOVERY
enum WorkingMode working_mode = WorkingMode::NORMAL;
+#endif
+#endif
+
static const uint16_t recovery_boot_detection_ms = 2000;
static const uint8_t recovery_boot_delay_ms = 100;
@@ -22,8 +27,10 @@ static StopWatch blinkStopWatch;
#endif
#ifndef CONFIG_TARGET_ESP01
+#ifndef CONFIG_NO_RECOVERY
static DNSServer* dnsServer = nullptr;
#endif
+#endif
static void onWifiConnected(const WiFiEventStationModeGotIP& event);
static void onWifiDisconnected(const WiFiEventStationModeDisconnected& event);
@@ -45,6 +52,7 @@ static void wifiConnect() {
}
#ifndef CONFIG_TARGET_ESP01
+#ifndef CONFIG_NO_RECOVERY
static void wifiHotspot() {
led::mcu_led->on();
@@ -71,13 +79,16 @@ static void waitForRecoveryPress() {
}
}
#endif
+#endif
void setup() {
WiFi.disconnect();
+#ifndef CONFIG_NO_RECOVERY
#ifndef CONFIG_TARGET_ESP01
homekit::main::waitForRecoveryPress();
#endif
+#endif
#ifdef DEBUG
Serial.begin(115200);
@@ -95,6 +106,7 @@ void setup() {
}
#ifndef CONFIG_TARGET_ESP01
+#ifndef CONFIG_NO_RECOVERY
switch (working_mode) {
case WorkingMode::RECOVERY:
wifiHotspot();
@@ -102,19 +114,24 @@ void setup() {
case WorkingMode::NORMAL:
#endif
+#endif
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnected);
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnected);
wifiConnect();
+#ifndef CONFIG_NO_RECOVERY
#ifndef CONFIG_TARGET_ESP01
break;
}
#endif
+#endif
}
void loop(LoopConfig* config) {
+#ifndef CONFIG_NO_RECOVERY
#ifndef CONFIG_TARGET_ESP01
if (working_mode == WorkingMode::NORMAL) {
#endif
+#endif
if (wifi_state == WiFiConnectionState::WAITING) {
PRINT(".");
led::mcu_led->blink(2, 50);
@@ -166,6 +183,7 @@ void loop(LoopConfig* config) {
}
#endif
}
+#ifndef CONFIG_NO_RECOVERY
#ifndef CONFIG_TARGET_ESP01
} else {
if (dnsServer != nullptr)
@@ -176,6 +194,7 @@ void loop(LoopConfig* config) {
httpServer->loop();
}
#endif
+#endif
}
static void onWifiConnected(const WiFiEventStationModeGotIP& event) {
@@ -191,4 +210,4 @@ static void onWifiDisconnected(const WiFiEventStationModeDisconnected& event) {
wifiTimer.once(2, wifiConnect);
}
-} \ No newline at end of file
+}
diff --git a/platformio/common/libs/main/homekit/main.h b/platformio/common/libs/main/homekit/main.h
index a503dd0..78a0695 100644
--- a/platformio/common/libs/main/homekit/main.h
+++ b/platformio/common/libs/main/homekit/main.h
@@ -10,8 +10,10 @@
#include <homekit/config.h>
#include <homekit/logging.h>
#ifndef CONFIG_TARGET_ESP01
+#ifndef CONFIG_NO_RECOVERY
#include <homekit/http_server.h>
#endif
+#endif
#include <homekit/wifi.h>
#include <homekit/mqtt/mqtt.h>
@@ -20,6 +22,7 @@
namespace homekit::main {
#ifndef CONFIG_TARGET_ESP01
+#ifndef CONFIG_NO_RECOVERY
enum class WorkingMode {
RECOVERY, // AP mode, http server with configuration
NORMAL, // MQTT client
@@ -27,6 +30,7 @@ enum class WorkingMode {
extern enum WorkingMode working_mode;
#endif
+#endif
enum class WiFiConnectionState {
WAITING = 0,
diff --git a/platformio/common/libs/main/library.json b/platformio/common/libs/main/library.json
index 04eedab..728d4f8 100644
--- a/platformio/common/libs/main/library.json
+++ b/platformio/common/libs/main/library.json
@@ -1,6 +1,6 @@
{
"name": "homekit_main",
- "version": "1.0.8",
+ "version": "1.0.10",
"build": {
"flags": "-I../../include"
},
diff --git a/platformio/common/libs/mqtt/homekit/mqtt/mqtt.cpp b/platformio/common/libs/mqtt/homekit/mqtt/mqtt.cpp
index cb2cea7..16f4675 100644
--- a/platformio/common/libs/mqtt/homekit/mqtt/mqtt.cpp
+++ b/platformio/common/libs/mqtt/homekit/mqtt/mqtt.cpp
@@ -55,13 +55,9 @@ Mqtt::Mqtt() {
}
}
-// if (ota.readyToRestart) {
-// restartTimer.once(1, restart);
-// } else {
- reconnectTimer.once(2, [&]() {
- reconnect();
- });
-// }
+ reconnectTimer.once(2, [&]() {
+ reconnect();
+ });
});
client.onSubscribe([&](uint16_t packetId, const SubscribeReturncode* returncodes, size_t len) {
@@ -79,7 +75,7 @@ Mqtt::Mqtt() {
PRINTF("mqtt: message received, topic=%s, qos=%d, dup=%d, retain=%d, len=%ul, index=%ul, total=%ul\n",
topic, properties.qos, (int)properties.dup, (int)properties.retain, len, index, total);
- const char *ptr = topic + nodeId.length() + 10;
+ const char *ptr = topic + nodeId.length() + 4;
String relevantTopic(ptr);
auto it = moduleSubscriptions.find(relevantTopic);
@@ -87,7 +83,7 @@ Mqtt::Mqtt() {
auto module = it->second;
module->handlePayload(*this, relevantTopic, properties.packetId, payload, len, index, total);
} else {
- PRINTF("error: module subscription for topic %s not found\n", topic);
+ PRINTF("error: module subscription for topic %s not found\n", relevantTopic.c_str());
}
});
diff --git a/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h b/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h
index 6420de1..1e80987 100644
--- a/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h
+++ b/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h
@@ -10,6 +10,10 @@ struct MqttRelaySwitchPayload {
uint8_t state;
} __attribute__((packed));
+struct MqttRelayStatusPayload {
+ uint8_t opened;
+} __attribute__((packed));
+
class MqttRelayModule : public MqttModule {
public:
MqttRelayModule() : MqttModule(0) {}
@@ -21,3 +25,4 @@ public:
}
#endif //HOMEKIT_LIB_MQTT_MODULE_RELAY_H
+
diff --git a/platformio/common/libs/mqtt_module_relay/library.json b/platformio/common/libs/mqtt_module_relay/library.json
index e71cf95..431bb49 100644
--- a/platformio/common/libs/mqtt_module_relay/library.json
+++ b/platformio/common/libs/mqtt_module_relay/library.json
@@ -1,6 +1,6 @@
{
"name": "homekit_mqtt_module_relay",
- "version": "1.0.3",
+ "version": "1.0.4",
"build": {
"flags": "-I../../include"
},