Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
afaf9b5e8f | |||
82f7e3c128 | |||
752e8caf53 | |||
373be8ac60 | |||
a18d4366ac |
13
README.md
13
README.md
@ -4,9 +4,9 @@ ESP-NOW based window/door sensor for ESP8266. Alternate firmware for Tuya/SmartL
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
1. When triggered transmits system information, battery status and sensor status.
|
1. When triggered transmits system information, battery status (HIGH/MID/LOW) and sensor status (OPEN/CLOSED).
|
||||||
2. Average response time of 1 second (depends on the MCU of the sensor).
|
2. Average response time of 1 second (depends on the MCU of the sensor).
|
||||||
3. In setup/update mode creates an access point named "ESP-NOW Window XXXXXXXXXXXX" with password "12345678" (IP 192.168.4.1).
|
3. In setup/update mode creates an access point named "ESP-NOW window XXXXXXXXXXXX" with password "12345678" (IP 192.168.4.1).
|
||||||
4. Automatically adds sensor and battery configuration to Home Assistan via MQTT discovery as a binary_sensors (2 different binary_sensor).
|
4. Automatically adds sensor and battery configuration to Home Assistan via MQTT discovery as a binary_sensors (2 different binary_sensor).
|
||||||
5. Possibility firmware update over OTA (if is allows the size of the flash memory).
|
5. Possibility firmware update over OTA (if is allows the size of the flash memory).
|
||||||
6. Web interface for settings.
|
6. Web interface for settings.
|
||||||
@ -24,7 +24,8 @@ See [here](https://github.com/aZholtikov/ESP-NOW-Window-Door-Sensor/tree/main/ha
|
|||||||
|
|
||||||
1. A gateway is required. For details see [ESP-NOW Gateway](https://github.com/aZholtikov/ESP-NOW-Gateway).
|
1. A gateway is required. For details see [ESP-NOW Gateway](https://github.com/aZholtikov/ESP-NOW-Gateway).
|
||||||
2. ESP-NOW network name must be set same of all another ESP-NOW devices in network.
|
2. ESP-NOW network name must be set same of all another ESP-NOW devices in network.
|
||||||
3. Upload the "data" folder (with web interface) into the filesystem before flashing.
|
3. If encryption is used, the key must be set same of all another ESP-NOW devices in network.
|
||||||
4. For using this firmware on Tuya/SmartLife WiFi window/door sensors, the WiFi module must be replaced with an ESP8266 compatible module (if necessary).
|
4. Upload the "data" folder (with web interface) into the filesystem before flashing.
|
||||||
5. Highly recommended connect an external power supply during setup/upgrade.
|
5. For using this firmware on Tuya/SmartLife WiFi window/door sensors, the WiFi module must be replaced with an ESP8266 compatible module (if necessary).
|
||||||
6. Because this sensor is battery operated, it has an additional controller (MCU) that controls the power of the WiFi module (Module) and transmits data to it for transmission to the network. The communication is done via UART at 9600 speed. Make sure that the protocol is correct before flashing. Details [here](https://github.com/aZholtikov/ESP-NOW-Window-Door-Sensor/tree/main/doc).
|
6. Highly recommended connect an external power supply during setup/upgrade.
|
||||||
|
7. Because this sensor is battery operated, it has an additional controller (MCU) that controls the power of the WiFi module (Module) and transmits data to it for transmission to the network. The communication is done via UART at 9600 speed. Make sure that the protocol is correct before flashing. Details [here](https://github.com/aZholtikov/ESP-NOW-Window-Door-Sensor/tree/main/doc).
|
||||||
|
@ -29,7 +29,7 @@ function loadBlock() {
|
|||||||
}
|
}
|
||||||
document.getElementsByTagName('body')[0].innerHTML = newString;
|
document.getElementsByTagName('body')[0].innerHTML = newString;
|
||||||
setFirmvareValue('version', 'firmware');
|
setFirmvareValue('version', 'firmware');
|
||||||
setGpioValue('deviceSensorClassSelect', 'deviceSensorClass');
|
setGpioValue('deviceClassSelect', 'deviceClass');
|
||||||
handleServerResponse();
|
handleServerResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,10 +51,9 @@ function sendRequest(submit, server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function saveSetting(submit) {
|
function saveSetting(submit) {
|
||||||
server = "/setting?deviceSensorName=" + getValue('deviceSensorName')
|
server = "/setting?deviceName=" + getValue('deviceName')
|
||||||
+ "&deviceBatteryName=" + getValue('deviceBatteryName')
|
|
||||||
+ "&espnowNetName=" + getValue('espnowNetName')
|
+ "&espnowNetName=" + getValue('espnowNetName')
|
||||||
+ "&deviceSensorClass=" + getSelectValue('deviceSensorClassSelect');
|
+ "&deviceClass=" + getSelectValue('deviceClassSelect');
|
||||||
sendRequest(submit, server);
|
sendRequest(submit, server);
|
||||||
alert("Please restart device for changes apply.");
|
alert("Please restart device for changes apply.");
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=0.9">
|
<meta name="viewport" content="width=device-width, initial-scale=0.9">
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
<script type="text/javascript" src="function.js"></script>
|
<script type="text/javascript" src="function.js"></script>
|
||||||
<title>ESP-NOW Window/Door Sensor</title>
|
<title>ESP-NOW Window Sensor</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body onload="load();">
|
<body onload="load();">
|
||||||
<form class="box">
|
<form class="box">
|
||||||
<h1>ESP-NOW Window/Door Sensor </h1>
|
<h1>ESP-NOW Window Sensor </h1>
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<p class="text">Firmware:</p>
|
<p class="text">Firmware:</p>
|
||||||
<p class="text" id="version"></p>
|
<p class="text" id="version"></p>
|
||||||
@ -18,14 +18,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<p class="text">Sensor name:</p>
|
<p class="text">Device name:</p>
|
||||||
<input id="deviceSensorName" value="{{deviceSensorName}}" placeholder="Name" autocomplete="off" label
|
<input id="deviceName" value="{{deviceName}}" placeholder="Name" autocomplete="off" label
|
||||||
title="ESP-NOW device name (up to 150 characters)" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="wrapper">
|
|
||||||
<p class="text">Battery name:</p>
|
|
||||||
<input id="deviceBatteryName" value="{{deviceBatteryName}}" placeholder="Name" autocomplete="off" label
|
|
||||||
title="ESP-NOW device name (up to 150 characters)" />
|
title="ESP-NOW device name (up to 150 characters)" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -37,8 +31,8 @@
|
|||||||
|
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<p class="text-select">Sensor type:</p>
|
<p class="text-select">Sensor type:</p>
|
||||||
<input id="deviceSensorClass" value="{{deviceSensorClass}}" hidden />
|
<input id="deviceClass" value="{{deviceClass}}" hidden />
|
||||||
<p><select id="deviceSensorClassSelect">
|
<p><select id="deviceClassSelect">
|
||||||
<option value="28">WINDOW</option>
|
<option value="28">WINDOW</option>
|
||||||
<option value="6">DOOR</option>
|
<option value="6">DOOR</option>
|
||||||
</select></p>
|
</select></p>
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
p{
|
||||||
|
margin: 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: "Gill Sans", sans-serif;
|
font-family: "Gill Sans", sans-serif;
|
||||||
background: rgb(255, 255, 255);
|
background: rgb(255, 255, 255);
|
||||||
@ -21,6 +25,8 @@ h1 {
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
|
margin-left: 10px;
|
||||||
|
margin: 10px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-select {
|
.text-select {
|
||||||
@ -42,6 +48,7 @@ input {
|
|||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
border: none;
|
border: none;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
margin-left: 10px;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
color: rgb(0, 0, 0);
|
color: rgb(0, 0, 0);
|
||||||
background: #a3e0f1;
|
background: #a3e0f1;
|
||||||
@ -76,6 +83,8 @@ select:hover {
|
|||||||
background: rgb(65, 125, 238);
|
background: rgb(65, 125, 238);
|
||||||
color: white;
|
color: white;
|
||||||
transition: .5s;
|
transition: .5s;
|
||||||
|
margin-left: 0;
|
||||||
|
margin-top: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn:hover {
|
.btn:hover {
|
||||||
@ -84,10 +93,13 @@ select:hover {
|
|||||||
transform: translatey(-3px);
|
transform: translatey(-3px);
|
||||||
}
|
}
|
||||||
|
|
||||||
#deviceSensorName,
|
#deviceName,
|
||||||
#deviceBatteryName,
|
|
||||||
#espnowNetName {
|
#espnowNetName {
|
||||||
width: 73%;
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#espnowNetName {
|
||||||
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.wrapper.wrapper--end {
|
.wrapper.wrapper--end {
|
||||||
|
@ -12,20 +12,20 @@ Communication protocol used in the firmware (only necessary "cuts" from the orig
|
|||||||
MCU returns 55 AA 00 01 00 ............ (MCU system information)
|
MCU returns 55 AA 00 01 00 ............ (MCU system information)
|
||||||
Module sends 55 AA 00 02 00 01 04 06 (Network connection established)
|
Module sends 55 AA 00 02 00 01 04 06 (Network connection established)
|
||||||
MCU returns 55 AA 00 02 00 00 01 (Confirmation message)
|
MCU returns 55 AA 00 02 00 00 01 (Confirmation message)
|
||||||
The MCU sends 55 AA 00 08 00 0C 00 01 01 01 01 01 03 04 00 01 02 23 (Battery status. 02 23 - high, 01 22 - medium, 00 21 - low)
|
MCU sends 55 AA 00 08 00 0C 00 01 01 01 01 01 03 04 00 01 02 23 (Battery status. 02 23 - high, 01 22 - medium, 00 21 - low)
|
||||||
Module returns 55 AA 00 08 00 01 00 08 (Confirmation message)
|
Module returns 55 AA 00 08 00 01 00 08 (Confirmation message)
|
||||||
The MCU sends 55 AA 00 08 00 0C 00 02 02 02 02 02 01 01 01 00 22 (Sensor position. 01 23 - open, 00 22 - closed)
|
MCU sends 55 AA 00 08 00 0C 00 02 02 02 02 02 01 01 01 00 22 (Sensor position. 01 23 - open, 00 22 - closed)
|
||||||
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)
|
||||||
MCU returns 55 AA 00 01 00 00 ............ (MCU system information)
|
MCU returns 55 AA 00 01 00 00 ............ (MCU system information)
|
||||||
Module sends 55 AA 00 02 00 01 04 06 (Network connection established)
|
Module sends 55 AA 00 02 00 01 04 06 (Network connection established)
|
||||||
MCU returns 55 AA 00 02 00 00 01 (Confirmation message)
|
MCU returns 55 AA 00 02 00 00 01 (Confirmation message)
|
||||||
The MCU sends 55 AA 00 08 00 0C 00 01 01 01 01 01 03 04 00 01 02 23 (Battery status. 02 23 - high, 01 22 - medium, 00 21 - low)
|
MCU sends 55 AA 00 08 00 0C 00 01 01 01 01 01 03 04 00 01 02 23 (Battery status. 02 23 - high, 01 22 - medium, 00 21 - low)
|
||||||
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
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ Communication protocol used in the firmware (only necessary "cuts" from the orig
|
|||||||
MCU returns 55 AA 00 01 00 00 ............ (MCU system information)
|
MCU returns 55 AA 00 01 00 00 ............ (MCU system information)
|
||||||
Module sends 55 AA 00 02 00 01 04 06 (Network connection established)
|
Module sends 55 AA 00 02 00 01 04 06 (Network connection established)
|
||||||
MCU returns 55 AA 00 02 00 00 01 (Confirmation message)
|
MCU returns 55 AA 00 02 00 00 01 (Confirmation message)
|
||||||
The MCU sends 55 AA 00 03 00 00 02 (Message for switching to setting mode)
|
MCU sends 55 AA 00 03 00 00 02 (Message for switching to setting mode)
|
||||||
Module returns 55 AA 00 03 00 00 02 (Confirmation message)
|
Module returns 55 AA 00 03 00 00 02 (Confirmation message)
|
||||||
|
|
||||||
Update mode has started. Will be available during 120 seconds until the module is powered off.
|
Update mode has started. Will be available during 120 seconds until the module is powered off.
|
||||||
|
87
src/main.cpp
87
src/main.cpp
@ -4,7 +4,7 @@
|
|||||||
#include "ZHNetwork.h"
|
#include "ZHNetwork.h"
|
||||||
#include "ZHConfig.h"
|
#include "ZHConfig.h"
|
||||||
|
|
||||||
void onConfirmReceiving(const uint8_t *target, const bool status);
|
void onConfirmReceiving(const uint8_t *target, const uint16_t id, const bool status);
|
||||||
|
|
||||||
void loadConfig(void);
|
void loadConfig(void);
|
||||||
void saveConfig(void);
|
void saveConfig(void);
|
||||||
@ -14,24 +14,25 @@ void sendSensorConfigMessage(void);
|
|||||||
void sendBatteryConfigMessage(void);
|
void sendBatteryConfigMessage(void);
|
||||||
void sendAttributesMessage(void);
|
void sendAttributesMessage(void);
|
||||||
|
|
||||||
const String firmware{"1.0"};
|
const String firmware{"1.2"};
|
||||||
|
|
||||||
String espnowNetName{"DEFAULT"};
|
String espnowNetName{"DEFAULT"};
|
||||||
|
|
||||||
String deviceSensorName{"ESP-NOW window sensor"};
|
String deviceName = "ESP-NOW window " + String(ESP.getChipId(), HEX);
|
||||||
uint8_t deviceSensorClass{HABSDC_WINDOW};
|
uint8_t deviceClass{HABSDC_WINDOW};
|
||||||
String deviceBatteryName{"ESP-NOW window sensor battery"};
|
|
||||||
|
String sensorStatus{""};
|
||||||
|
String batteryStatus{""};
|
||||||
|
|
||||||
char receivedBytes[128]{0};
|
char receivedBytes[128]{0};
|
||||||
byte counter{0};
|
uint8_t counter{0};
|
||||||
byte messageLenght{0};
|
uint8_t messageLenght{0};
|
||||||
bool dataReceiving{false};
|
bool dataReceiving{false};
|
||||||
bool dataReceived{false};
|
bool dataReceived{false};
|
||||||
bool semaphore{false};
|
bool semaphore{false};
|
||||||
|
|
||||||
esp_now_payload_data_t outgoingData{ENDT_SENSOR, ENPT_STATE};
|
esp_now_payload_data_t outgoingData{ENDT_SENSOR, ENPT_STATE};
|
||||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||||
char buffer[sizeof(esp_now_payload_data_t::message)]{0};
|
|
||||||
char temp[sizeof(esp_now_payload_data_t)]{0};
|
char temp[sizeof(esp_now_payload_data_t)]{0};
|
||||||
const char initialMessage[] = {0x55, 0xAA, 0x00, 0x01, 0x00, 0x00, 0x00};
|
const char initialMessage[] = {0x55, 0xAA, 0x00, 0x01, 0x00, 0x00, 0x00};
|
||||||
const char connectedMessage[] = {0x55, 0xAA, 0x00, 0x02, 0x00, 0x01, 0x04, 0x06};
|
const char connectedMessage[] = {0x55, 0xAA, 0x00, 0x02, 0x00, 0x01, 0x04, 0x06};
|
||||||
@ -49,7 +50,11 @@ void setup()
|
|||||||
|
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
|
json["state"] = sensorStatus;
|
||||||
|
json["battery"] = batteryStatus;
|
||||||
|
|
||||||
myNet.begin(espnowNetName.c_str());
|
myNet.begin(espnowNetName.c_str());
|
||||||
|
// myNet.setCryptKey("VERY_LONG_CRYPT_KEY"); // If encryption is used, the key must be set same of all another ESP-NOW devices in network.
|
||||||
|
|
||||||
myNet.setOnConfirmReceivingCallback(onConfirmReceiving);
|
myNet.setOnConfirmReceivingCallback(onConfirmReceiving);
|
||||||
|
|
||||||
@ -104,7 +109,8 @@ void loop()
|
|||||||
Serial.flush();
|
Serial.flush();
|
||||||
Serial.end();
|
Serial.end();
|
||||||
dataReceived = false;
|
dataReceived = false;
|
||||||
WiFi.softAP(("ESP-NOW Window " + myNet.getNodeMac()).c_str(), "12345678", 1, 0);
|
WiFi.mode(WIFI_AP);
|
||||||
|
WiFi.softAP(("ESP-NOW window " + String(ESP.getChipId(), HEX)).c_str(), "12345678", 1, 0);
|
||||||
setupWebServer();
|
setupWebServer();
|
||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
}
|
}
|
||||||
@ -113,25 +119,43 @@ 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, outgoingData.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;
|
||||||
serializeJsonPretty(json, buffer);
|
saveConfig();
|
||||||
memcpy(outgoingData.message, buffer, sizeof(esp_now_payload_data_t::message));
|
serializeJsonPretty(json, outgoingData.message);
|
||||||
memcpy(temp, &outgoingData, sizeof(esp_now_payload_data_t));
|
memcpy(&temp, &outgoingData, sizeof(esp_now_payload_data_t));
|
||||||
myNet.sendBroadcastMessage(temp);
|
myNet.sendBroadcastMessage(temp);
|
||||||
semaphore = true;
|
semaphore = true;
|
||||||
}
|
}
|
||||||
@ -141,7 +165,7 @@ void loop()
|
|||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onConfirmReceiving(const uint8_t *target, const bool status)
|
void onConfirmReceiving(const uint8_t *target, const uint16_t id, const bool status)
|
||||||
{
|
{
|
||||||
if (semaphore)
|
if (semaphore)
|
||||||
{
|
{
|
||||||
@ -156,23 +180,25 @@ 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>();
|
deviceName = json["deviceName"].as<String>();
|
||||||
deviceBatteryName = json["deviceBatteryName"].as<String>();
|
deviceClass = json["deviceClass"];
|
||||||
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["deviceName"] = deviceName;
|
||||||
json["deviceBatteryName"] = deviceBatteryName;
|
json["deviceClass"] = deviceClass;
|
||||||
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);
|
||||||
@ -186,9 +212,8 @@ void setupWebServer()
|
|||||||
|
|
||||||
webServer.on("/setting", HTTP_GET, [](AsyncWebServerRequest *request)
|
webServer.on("/setting", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||||
{
|
{
|
||||||
deviceSensorName = request->getParam("deviceSensorName")->value();
|
deviceName = request->getParam("deviceName")->value();
|
||||||
deviceBatteryName = request->getParam("deviceBatteryName")->value();
|
deviceClass = request->getParam("deviceClass")->value().toInt();
|
||||||
deviceSensorClass = request->getParam("deviceSensorClass")->value().toInt();
|
|
||||||
espnowNetName = request->getParam("espnowNetName")->value();
|
espnowNetName = request->getParam("espnowNetName")->value();
|
||||||
request->send(200);
|
request->send(200);
|
||||||
saveConfig(); });
|
saveConfig(); });
|
||||||
@ -214,10 +239,11 @@ void sendSensorConfigMessage()
|
|||||||
{
|
{
|
||||||
esp_now_payload_data_t outgoingData{ENDT_SENSOR, ENPT_CONFIG};
|
esp_now_payload_data_t outgoingData{ENDT_SENSOR, ENPT_CONFIG};
|
||||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||||
json["name"] = deviceSensorName;
|
json["name"] = deviceName;
|
||||||
json["unit"] = 1;
|
json["unit"] = 1;
|
||||||
json["type"] = HACT_BINARY_SENSOR;
|
json["type"] = HACT_BINARY_SENSOR;
|
||||||
json["class"] = deviceSensorClass;
|
json["class"] = deviceClass;
|
||||||
|
json["template"] = "state";
|
||||||
json["payload_on"] = "OPEN";
|
json["payload_on"] = "OPEN";
|
||||||
json["payload_off"] = "CLOSED";
|
json["payload_off"] = "CLOSED";
|
||||||
char buffer[sizeof(esp_now_payload_data_t::message)]{0};
|
char buffer[sizeof(esp_now_payload_data_t::message)]{0};
|
||||||
@ -232,10 +258,11 @@ void sendBatteryConfigMessage()
|
|||||||
{
|
{
|
||||||
esp_now_payload_data_t outgoingData{ENDT_SENSOR, ENPT_CONFIG};
|
esp_now_payload_data_t outgoingData{ENDT_SENSOR, ENPT_CONFIG};
|
||||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||||
json["name"] = deviceBatteryName;
|
json["name"] = deviceName + " battery";
|
||||||
json["unit"] = 2;
|
json["unit"] = 2;
|
||||||
json["type"] = HACT_BINARY_SENSOR;
|
json["type"] = HACT_BINARY_SENSOR;
|
||||||
json["class"] = HABSDC_BATTERY;
|
json["class"] = HABSDC_BATTERY;
|
||||||
|
json["template"] = "battery";
|
||||||
json["payload_on"] = "MID";
|
json["payload_on"] = "MID";
|
||||||
json["payload_off"] = "HIGH";
|
json["payload_off"] = "HIGH";
|
||||||
char buffer[sizeof(esp_now_payload_data_t::message)]{0};
|
char buffer[sizeof(esp_now_payload_data_t::message)]{0};
|
||||||
@ -250,7 +277,7 @@ void sendAttributesMessage()
|
|||||||
{
|
{
|
||||||
esp_now_payload_data_t outgoingData{ENDT_SENSOR, ENPT_ATTRIBUTES};
|
esp_now_payload_data_t outgoingData{ENDT_SENSOR, ENPT_ATTRIBUTES};
|
||||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||||
json["Type"] = "ESP-NOW Window Sensor";
|
json["Type"] = "ESP-NOW window sensor";
|
||||||
json["MCU"] = "ESP8266";
|
json["MCU"] = "ESP8266";
|
||||||
json["MAC"] = myNet.getNodeMac();
|
json["MAC"] = myNet.getNodeMac();
|
||||||
json["Firmware"] = firmware;
|
json["Firmware"] = firmware;
|
||||||
|
Reference in New Issue
Block a user