Version 1.1
Fixed some bugs.
This commit is contained in:
parent
752e8caf53
commit
82f7e3c128
@ -18,7 +18,7 @@ Communication protocol used in the firmware (only necessary "cuts" from the orig
|
|||||||
Module returns 55 AA 00 08 00 01 00 08 (Confirmation message)
|
Module returns 55 AA 00 08 00 01 00 08 (Confirmation message)
|
||||||
Module power off
|
Module power off
|
||||||
|
|
||||||
2. Sending the battery status. Pressing the button. Not used in the firmware.
|
2. Sending the battery status. Pressing the button.
|
||||||
|
|
||||||
Module power is on
|
Module power is on
|
||||||
Module sends 55 AA 00 01 00 00 00 (Initial message)
|
Module sends 55 AA 00 01 00 00 00 (Initial message)
|
||||||
|
42
src/main.cpp
42
src/main.cpp
@ -14,7 +14,7 @@ void sendSensorConfigMessage(void);
|
|||||||
void sendBatteryConfigMessage(void);
|
void sendBatteryConfigMessage(void);
|
||||||
void sendAttributesMessage(void);
|
void sendAttributesMessage(void);
|
||||||
|
|
||||||
const String firmware{"1.0"};
|
const String firmware{"1.1"};
|
||||||
|
|
||||||
String espnowNetName{"DEFAULT"};
|
String espnowNetName{"DEFAULT"};
|
||||||
|
|
||||||
@ -22,6 +22,9 @@ String deviceSensorName{"ESP-NOW window sensor"};
|
|||||||
uint8_t deviceSensorClass{HABSDC_WINDOW};
|
uint8_t deviceSensorClass{HABSDC_WINDOW};
|
||||||
String deviceBatteryName{"ESP-NOW window sensor battery"};
|
String deviceBatteryName{"ESP-NOW window sensor battery"};
|
||||||
|
|
||||||
|
String sensorStatus{""};
|
||||||
|
String batteryStatus{""};
|
||||||
|
|
||||||
char receivedBytes[128]{0};
|
char receivedBytes[128]{0};
|
||||||
uint8_t counter{0};
|
uint8_t counter{0};
|
||||||
uint8_t messageLenght{0};
|
uint8_t messageLenght{0};
|
||||||
@ -49,6 +52,9 @@ void setup()
|
|||||||
|
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
|
json["state"] = sensorStatus;
|
||||||
|
json["battery"] = batteryStatus;
|
||||||
|
|
||||||
myNet.begin(espnowNetName.c_str());
|
myNet.begin(espnowNetName.c_str());
|
||||||
|
|
||||||
myNet.setOnConfirmReceivingCallback(onConfirmReceiving);
|
myNet.setOnConfirmReceivingCallback(onConfirmReceiving);
|
||||||
@ -104,6 +110,7 @@ void loop()
|
|||||||
Serial.flush();
|
Serial.flush();
|
||||||
Serial.end();
|
Serial.end();
|
||||||
dataReceived = false;
|
dataReceived = false;
|
||||||
|
WiFi.mode(WIFI_AP);
|
||||||
WiFi.softAP(("ESP-NOW Window " + myNet.getNodeMac()).c_str(), "12345678", 1, 0);
|
WiFi.softAP(("ESP-NOW Window " + myNet.getNodeMac()).c_str(), "12345678", 1, 0);
|
||||||
setupWebServer();
|
setupWebServer();
|
||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
@ -113,22 +120,42 @@ void loop()
|
|||||||
if (receivedBytes[7] == 0x01)
|
if (receivedBytes[7] == 0x01)
|
||||||
{
|
{
|
||||||
if (receivedBytes[17] == 0x02)
|
if (receivedBytes[17] == 0x02)
|
||||||
|
{
|
||||||
json["battery"] = "HIGH";
|
json["battery"] = "HIGH";
|
||||||
|
batteryStatus = "HIGH";
|
||||||
|
}
|
||||||
if (receivedBytes[17] == 0x01)
|
if (receivedBytes[17] == 0x01)
|
||||||
|
{
|
||||||
json["battery"] = "MID";
|
json["battery"] = "MID";
|
||||||
|
batteryStatus = "MID";
|
||||||
|
}
|
||||||
if (receivedBytes[17] == 0x00)
|
if (receivedBytes[17] == 0x00)
|
||||||
|
{
|
||||||
json["battery"] = "LOW";
|
json["battery"] = "LOW";
|
||||||
|
batteryStatus = "LOW";
|
||||||
|
}
|
||||||
dataReceived = false;
|
dataReceived = false;
|
||||||
Serial.write(confirmationMessage, sizeof(confirmationMessage));
|
saveConfig();
|
||||||
Serial.flush();
|
serializeJsonPretty(json, buffer);
|
||||||
|
memcpy(outgoingData.message, buffer, sizeof(esp_now_payload_data_t::message));
|
||||||
|
memcpy(temp, &outgoingData, sizeof(esp_now_payload_data_t));
|
||||||
|
myNet.sendBroadcastMessage(temp);
|
||||||
|
semaphore = true;
|
||||||
}
|
}
|
||||||
if (receivedBytes[7] == 0x02)
|
if (receivedBytes[7] == 0x02)
|
||||||
{
|
{
|
||||||
if (receivedBytes[17] == 0x01)
|
if (receivedBytes[17] == 0x01)
|
||||||
|
{
|
||||||
json["state"] = "OPEN";
|
json["state"] = "OPEN";
|
||||||
|
sensorStatus = "OPEN";
|
||||||
|
}
|
||||||
if (receivedBytes[17] == 0x00)
|
if (receivedBytes[17] == 0x00)
|
||||||
|
{
|
||||||
json["state"] = "CLOSED";
|
json["state"] = "CLOSED";
|
||||||
|
sensorStatus = "CLOSED";
|
||||||
|
}
|
||||||
dataReceived = false;
|
dataReceived = false;
|
||||||
|
saveConfig();
|
||||||
serializeJsonPretty(json, buffer);
|
serializeJsonPretty(json, buffer);
|
||||||
memcpy(outgoingData.message, buffer, sizeof(esp_now_payload_data_t::message));
|
memcpy(outgoingData.message, buffer, sizeof(esp_now_payload_data_t::message));
|
||||||
memcpy(temp, &outgoingData, sizeof(esp_now_payload_data_t));
|
memcpy(temp, &outgoingData, sizeof(esp_now_payload_data_t));
|
||||||
@ -147,7 +174,6 @@ void onConfirmReceiving(const uint8_t *target, const bool status)
|
|||||||
{
|
{
|
||||||
Serial.write(confirmationMessage, sizeof(confirmationMessage));
|
Serial.write(confirmationMessage, sizeof(confirmationMessage));
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
ESP.deepSleep(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,23 +183,27 @@ void loadConfig()
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
File file = SPIFFS.open("/config.json", "r");
|
File file = SPIFFS.open("/config.json", "r");
|
||||||
String jsonFile = file.readString();
|
String jsonFile = file.readString();
|
||||||
StaticJsonDocument<512> json;
|
StaticJsonDocument<1024> json;
|
||||||
deserializeJson(json, jsonFile);
|
deserializeJson(json, jsonFile);
|
||||||
espnowNetName = json["espnowNetName"].as<String>();
|
espnowNetName = json["espnowNetName"].as<String>();
|
||||||
deviceSensorName = json["deviceSensorName"].as<String>();
|
deviceSensorName = json["deviceSensorName"].as<String>();
|
||||||
deviceBatteryName = json["deviceBatteryName"].as<String>();
|
deviceBatteryName = json["deviceBatteryName"].as<String>();
|
||||||
deviceSensorClass = json["deviceSensorClass"];
|
deviceSensorClass = json["deviceSensorClass"];
|
||||||
|
sensorStatus = json["sensorStatus"].as<String>();
|
||||||
|
batteryStatus = json["batteryStatus"].as<String>();
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveConfig()
|
void saveConfig()
|
||||||
{
|
{
|
||||||
StaticJsonDocument<512> json;
|
StaticJsonDocument<1024> json;
|
||||||
json["firmware"] = firmware;
|
json["firmware"] = firmware;
|
||||||
json["espnowNetName"] = espnowNetName;
|
json["espnowNetName"] = espnowNetName;
|
||||||
json["deviceSensorName"] = deviceSensorName;
|
json["deviceSensorName"] = deviceSensorName;
|
||||||
json["deviceBatteryName"] = deviceBatteryName;
|
json["deviceBatteryName"] = deviceBatteryName;
|
||||||
json["deviceSensorClass"] = deviceSensorClass;
|
json["deviceSensorClass"] = deviceSensorClass;
|
||||||
|
json["sensorStatus"] = sensorStatus;
|
||||||
|
json["batteryStatus"] = batteryStatus;
|
||||||
json["system"] = "empty";
|
json["system"] = "empty";
|
||||||
File file = SPIFFS.open("/config.json", "w");
|
File file = SPIFFS.open("/config.json", "w");
|
||||||
serializeJsonPretty(json, file);
|
serializeJsonPretty(json, file);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user