-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
24 changed files
with
533 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.pio | ||
.vscode | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
# ESP-NOW-Water-Leakage-Sensor | ||
# ESP-NOW water leakage sensor for ESP8266 | ||
|
||
ESP-NOW based water leakage sensor for ESP8266. Alternate firmware for Tuya/SmartLife WiFi water leakage sensors. | ||
|
||
## Features | ||
|
||
1. 2 possiility operating modes - NORMAL and LITE. | ||
2. Average response time of 1.8 second (NORMAL), 0.4 second (LITE) (depends on the MCU of the sensor). | ||
3. Triggered in 2 cases: contact closure, contact drying (only if the contacts were previously closed). | ||
4. When triggered transmits system information and sensor status (ALARM/DRY) at NORMAL mode and always ALARM at LITE mode. | ||
5. In setup/update mode creates an access point named "ESP-NOW Water XXXXXXXXXXXX" with password "12345678" (IP 192.168.4.1) at NORMAL mode only. | ||
6. Automatically adds sensor configuration to Home Assistan via MQTT discovery as a binary_sensor. | ||
7. Possibility firmware update over OTA (if is allows the size of the flash memory) at NORMAL mode only. | ||
8. Web interface for settings at NORMAL mode only. | ||
|
||
## Notes | ||
|
||
1. ESP-NOW mesh network based on the library [ZHNetwork](https://github.com/aZholtikov/ZHNetwork). | ||
2. For enter to setup/update mode press the button for > 2 seconds. The LED blinks fast. Access point will be available during 120 seconds before the module is powered off. | ||
|
||
## Tested on | ||
|
||
See [here](https://github.com/aZholtikov/ESP-NOW-Water-Leakage-Sensor/tree/main/hardware). | ||
|
||
## Attention | ||
|
||
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. | ||
3. Upload the "data" folder (with web interface) into the filesystem before flashing for NORMAL mode only. | ||
4. For using this firmware on Tuya/SmartLife WiFi water leakage sensors, the WiFi module must be replaced with an ESP8266 compatible module (if necessary). | ||
5. Highly recommended connect an external power supply during setup/upgrade. | ||
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-Water-Leakage-Sensor/tree/main/doc) for NORMAL mode only. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var xmlHttp = createXmlHttpObject(); | ||
function createXmlHttpObject() { | ||
if (window.XMLHttpRequest) { | ||
xmlHttp = new XMLHttpRequest(); | ||
} else { | ||
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); | ||
} | ||
return xmlHttp; | ||
} | ||
|
||
function load() { | ||
if (xmlHttp.readyState == 0 || xmlHttp.readyState == 4) { | ||
xmlHttp.open('PUT', '/config.json', true); | ||
xmlHttp.send(null); | ||
xmlHttp.onload = function () { | ||
jsonResponse = JSON.parse(xmlHttp.responseText); | ||
loadBlock(); | ||
} | ||
} | ||
} | ||
|
||
function loadBlock() { | ||
newData = JSON.parse(xmlHttp.responseText); | ||
data = document.getElementsByTagName('body')[0].innerHTML; | ||
var newString; | ||
for (var key in newData) { | ||
newString = data.replace(new RegExp('{{' + key + '}}', 'g'), newData[key]); | ||
data = newString; | ||
} | ||
document.getElementsByTagName('body')[0].innerHTML = newString; | ||
setFirmvareValue('version', 'firmware'); | ||
handleServerResponse(); | ||
} | ||
|
||
function getValue(id) { | ||
var value = document.getElementById(id).value; | ||
return value; | ||
} | ||
|
||
function sendRequest(submit, server) { | ||
request = new XMLHttpRequest(); | ||
request.open("GET", server, true); | ||
request.send(); | ||
} | ||
|
||
function saveSetting(submit) { | ||
server = "/setting?deviceName=" + getValue('deviceName') | ||
+ "&espnowNetName=" + getValue('espnowNetName'); | ||
sendRequest(submit, server); | ||
alert("Please restart device for changes apply."); | ||
} | ||
|
||
function restart(submit) { | ||
server = "/restart"; | ||
sendRequest(submit, server); | ||
} | ||
|
||
function setFirmvareValue(id, value) { | ||
document.getElementById(id).innerHTML = document.getElementById(value).value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<html> | ||
|
||
<head> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=0.9"> | ||
<link rel="stylesheet" href="style.css"> | ||
<script type="text/javascript" src="function.js"></script> | ||
<title>ESP-NOW Water Leakage Sensor</title> | ||
</head> | ||
|
||
<body onload="load();"> | ||
<form class="box"> | ||
<h1>ESP-NOW Water Leakage Sensor </h1> | ||
<div class="wrapper"> | ||
<p class="text">Firmware:</p> | ||
<p class="text" id="version"></p> | ||
<input id="firmware" value="{{firmware}}" hidden /> | ||
</div> | ||
|
||
<div class="wrapper"> | ||
<p class="text">Sensor name:</p> | ||
<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">ESP-NOW network name:</p> | ||
<input id="espnowNetName" value="{{espnowNetName}}" placeholder="Name" autocomplete="off" label | ||
title="ESP-NOW network name (1 to 20 characters)" /> | ||
</div> | ||
|
||
<div class="wrapper"> | ||
<input class="btn" type="submit" value="Save" onclick="saveSetting(this);"> | ||
<input class="btn" type="submit" value="Restart" onclick="restart(this);"> | ||
</div> | ||
</form> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
body { | ||
font-family: "Gill Sans", sans-serif; | ||
background: rgb(255, 255, 255); | ||
} | ||
|
||
.box { | ||
width: 400px; | ||
padding: 20px 20px; | ||
margin: 20px auto; | ||
background: #e0f5fb; | ||
box-shadow: 4px 4px 30px rgba(0, 0, 0, 0.2); | ||
border-radius: 10px; | ||
} | ||
|
||
h1 { | ||
color: rgb(65, 125, 238); | ||
text-align: center; | ||
} | ||
|
||
.text { | ||
font-weight: 600; | ||
flex-shrink: 0; | ||
margin-right: 10px; | ||
} | ||
|
||
.wrapper { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: baseline; | ||
} | ||
|
||
input { | ||
width: 48%; | ||
min-height: 30px; | ||
border-radius: 5px; | ||
border: none; | ||
margin-bottom: 10px; | ||
padding: 0 10px; | ||
color: rgb(0, 0, 0); | ||
background: #a3e0f1; | ||
transition: .5s; | ||
} | ||
|
||
input:hover { | ||
background: white; | ||
cursor: pointer; | ||
} | ||
|
||
.btn { | ||
width: 48%; | ||
background: rgb(65, 125, 238); | ||
color: white; | ||
transition: .5s; | ||
} | ||
|
||
.btn:hover { | ||
background: rgb(65, 125, 238); | ||
opacity: 0.5; | ||
transform: translatey(-3px); | ||
} | ||
|
||
#deviceName, | ||
#espnowNetName { | ||
width: 73%; | ||
} | ||
|
||
.wrapper.wrapper--end { | ||
align-items: baseline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Communication protocol | ||
|
||
The protocol can be read with 2 USB-TTL converters. RX of the first one is connected to the RX of the WiFi module to read the MCU data. Connect the RX of the second to the TX of the WiFi module to read the module's data. Don't forget to connect all GND (of both converters and module). | ||
|
||
Communication protocol used in the firmware (only necessary "cuts" from the original protocol): | ||
|
||
```text | ||
1. Normal mode. Sensor triggering. | ||
Module power is on | ||
Module sends 55 AA 00 01 00 00 00 (Initial message) | ||
MCU returns 55 AA 00 01 00 00 ............ (MCU system information) | ||
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 sends 55 AA 00 05 00 05 01 04 00 01 00 0F (Leak status. 00 0F - leak, 01 10 - dry) | ||
Module returns 55 AA 00 05 00 01 00 05 (Confirmation message) | ||
MCU sends 55 AA 00 05 00 05 03 04 00 01 02 13 (Battery status. 02 13 - high, 01 12 - medium, 00 11 - low) | ||
Module returns 55 AA 00 05 00 01 00 05 (Confirmation message) | ||
Module power off | ||
2. Update mode. Pressing the button for > 2 seconds - the LED blinks fast. | ||
Module power is on | ||
Module sends 55 AA 00 01 00 00 00 (Initial message) | ||
MCU returns 55 AA 00 01 00 00 ............ (MCU system information) | ||
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 sends 55 AA 00 04 00 00 01 00 04 (Message for switching to setting mode) | ||
Module returns 55 AA 00 04 00 00 03 (Confirmation message) | ||
Update mode has started. Will be available during 120 seconds until the module is powered off. | ||
After updating and rebooting the module will return to normal mode - the LED will go off. | ||
Highly recommended connect an external power supply during update. | ||
Battery level sending is not used in the firmware because it is not needed. | ||
``` |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+318 KB
doc/Serial Port Protocol Wi-Fi Low-Power Device Solution v20210125.pdf
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Tested on | ||
|
||
1. Model WIFI S2 Type 1. Built on Tuya WiFi module TYWE3S (ESP8266 chip). Analogue of ESP-01. Does not require replacement. Total triggering time about 2 sec (NORMAL), 0.4 sec (LITE). [Photo](https://github.com/aZholtikov/ESP-NOW-Water-Leakage-Sensor/tree/main/hardware/Model_WIFI_S2_Type_1). | ||
|
||
2. Model WIFI S2 Type 2. Built on Tuya WiFi module CB3S (BK7231N chip). Replacement required. Performed replacement with ESP-12E. Total triggering time about 1.5 sec (NORMAL), 0.3 sec (LITE). [Photo](https://github.com/aZholtikov/ESP-NOW-Water-Leakage-Sensor/tree/main/hardware/Model_WIFI_S2_Type_2). A pull-up to GND of GPIO15 is required (i used a 0805 10K SMD resistor on top of the module pins). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[env:TYWE3S] | ||
platform = espressif8266 | ||
board = esp01_1m | ||
framework = arduino | ||
lib_deps = | ||
https://github.com/aZholtikov/ZHNetwork | ||
https://github.com/aZholtikov/ZHConfig | ||
bblanchon/ArduinoJson@^6.19.4 | ||
me-no-dev/ESP Async WebServer@^1.2.3 | ||
|
||
[env:ESP-12E] | ||
platform = espressif8266 | ||
board = esp12e | ||
framework = arduino | ||
lib_deps = | ||
https://github.com/aZholtikov/ZHNetwork | ||
https://github.com/aZholtikov/ZHConfig | ||
bblanchon/ArduinoJson@^6.19.4 | ||
me-no-dev/ESP Async WebServer@^1.2.3 | ||
|
||
[env:ESP-12E-OTA] | ||
platform = espressif8266 | ||
board = esp12e | ||
framework = arduino | ||
upload_port = 192.168.4.1 | ||
upload_protocol = espota | ||
lib_deps = | ||
https://github.com/aZholtikov/ZHNetwork | ||
https://github.com/aZholtikov/ZHConfig | ||
bblanchon/ArduinoJson@^6.19.4 | ||
me-no-dev/ESP Async WebServer@^1.2.3 |
Oops, something went wrong.