Added repeat functionality
This commit is contained in:
@@ -105,6 +105,12 @@ extern "C" void onReceive(const uint8_t *mac_addr, const uint8_t *data, int len)
|
|||||||
|
|
||||||
ESP_LOGI(TAG, "ID: %s - Token: %s", stringSettings.esp_now_door_id.c_str(), stringSettings.esp_now_door_token.c_str());
|
ESP_LOGI(TAG, "ID: %s - Token: %s", stringSettings.esp_now_door_id.c_str(), stringSettings.esp_now_door_token.c_str());
|
||||||
|
|
||||||
|
if (settings.repeatESPNow)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Repeat ESP-NOW message \"%s\"", message.c_str());
|
||||||
|
send_espnow_message(message);
|
||||||
|
}
|
||||||
|
|
||||||
// Parse the message (msg format: "msg_type:msg_value:msg_token") via find and npos
|
// Parse the message (msg format: "msg_type:msg_value:msg_token") via find and npos
|
||||||
const size_t pos = message.find(":");
|
const size_t pos = message.find(":");
|
||||||
if (pos == std::string::npos) {
|
if (pos == std::string::npos) {
|
||||||
@@ -240,7 +246,7 @@ void handle()
|
|||||||
digitalWrite(PIN_RELAY, LOW);
|
digitalWrite(PIN_RELAY, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!last_send_ms || espchrono::ago(*last_send_ms) > 1s) {
|
if (!last_send_ms || espchrono::ago(*last_send_ms) > 1s && !settings.repeatESPNow) {
|
||||||
const auto message = fmt::format("T:{}", espchrono::utc_clock::now().time_since_epoch().count());
|
const auto message = fmt::format("T:{}", espchrono::utc_clock::now().time_since_epoch().count());
|
||||||
send_espnow_message(message);
|
send_espnow_message(message);
|
||||||
last_send_ms = espchrono::millis_clock::now();
|
last_send_ms = espchrono::millis_clock::now();
|
||||||
|
@@ -352,6 +352,7 @@ constexpr Settings defaultSettings {
|
|||||||
#ifdef FEATURE_ESPNOW
|
#ifdef FEATURE_ESPNOW
|
||||||
.espnow = defaultEspNowSettings,
|
.espnow = defaultEspNowSettings,
|
||||||
#endif
|
#endif
|
||||||
|
.repeatESPNow = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
StringSettings makeDefaultStringSettings();
|
StringSettings makeDefaultStringSettings();
|
||||||
|
@@ -233,6 +233,7 @@ struct Settings
|
|||||||
bool syncBlink;
|
bool syncBlink;
|
||||||
} espnow;
|
} espnow;
|
||||||
#endif
|
#endif
|
||||||
|
bool repeatESPNow;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void executeForEveryCommonSetting(T &&callable);
|
void executeForEveryCommonSetting(T &&callable);
|
||||||
@@ -379,6 +380,7 @@ void Settings::executeForEveryCommonSetting(T &&callable)
|
|||||||
callable("espnowSyncBl", espnow.syncBlink);
|
callable("espnowSyncBl", espnow.syncBlink);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
callable("repeat", repeatESPNow);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
Reference in New Issue
Block a user