Skip to content

Commit

Permalink
Version 1.3
Browse files Browse the repository at this point in the history
Changed library for MQTT connection.
Added support for LAN connection.
Added getting data from NTP server.
  • Loading branch information
aZholtikov committed Feb 9, 2023
1 parent 24ba0a0 commit 7a74c4f
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 135 deletions.
37 changes: 27 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
# ESP-NOW gateway for ESP8266/ESP32

Gateway for data exchange between ESP-NOW devices and MQTT broker via WiFi.
Gateway for data exchange between ESP-NOW devices and MQTT broker via WiFi/LAN.

## Features

1. Creates an access point named "ESP-NOW gateway XXXXXXXXXXXX" with password "12345678" (IP 192.168.4.1).
2. Possibility a device search through the Windows Network Environment via SSDP.
3. Periodically transmission of system information to the MQTT broker (every 60 seconds) and availability status to the ESP-NOW network and to the MQTT broker (every 10 seconds).
2. Possibility a device search through the Windows Network Environment via SSDP (at ESP_NOW_WIFI mode).
3. Periodically transmission of system information to the MQTT broker (every 60 seconds), availability status to the ESP-NOW network and to the MQTT broker (every 10 seconds) and current date and time to the ESP-NOW network (every 10 seconds).
4. Automatically adds gateway configuration to Home Assistan via MQTT discovery as a binary_sensor.
5. Automatically adds supported ESP-NOW devices configurations to Home Assistan via MQTT discovery.
6. Possibility firmware update over OTA.
7. Web interface for settings.

6. Possibility firmware update over OTA (at ESP_NOW_LAN mode via access point only).
7. Web interface for settings (at ESP_NOW_LAN mode via access point only).
8. 3 operating modes:

```text
ESP_NOW ESP-NOW node only. Default mode after flashing.
ESP_NOW_WIFI Gateway between ESP-NOW devices and MQTT broker via WiFi.
ESP_NOW_LAN Gateway between ESP-NOW devices and MQTT broker via Ethernet. Preferred mode.
```

## Notes

1. ESP-NOW mesh network based on the library [ZHNetwork](https://github.com/aZholtikov/ZHNetwork).
2. Regardless of the status of connections to WiFi or MQTT the device perform ESP-NOW node function.
3. For restart the device (without using the Web interface and only if MQTT connection established) send an "restart" command to the device's root topic (example - "homeassistant/espnow_gateway/70039F44BEF7").
4. W5500 connection:

```text
ESP8266 (GPIO05 - CS, GPIO14 - SCK, GPIO12 - MISO, GPIO13 - MOSI).
ESP32 (GPIO05 - CS, GPIO18 - SCK, GPIO19 - MISO, GPIO23 - MOSI).
```

## Attention

1. ESP-NOW network name must be set same of all another ESP-NOW devices in network.
2. If encryption is used, the key 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.
4. WiFi router must be set on channel 1.
4. At ESP_NOW_WIFI mode WiFi router must be set on channel 1.

## Tested on

1. NodeMCU 1.0 (ESP-12E Module). ESP-NOW + WiFi mode. Unstable work.
2. AZ-Delivery ESP-32 Dev Kit C V4. ESP-NOW + WiFi mode. Stable work.
1. NodeMCU 1.0 (ESP-12E Module). ESP_NOW_WIFI mode. Unstable work.
2. AZ-Delivery ESP-32 Dev Kit C V4. ESP_NOW_WIFI mode. Stable work.
3. NodeMCU 1.0 (ESP-12E Module) + W5500. ESP_NOW_LAN mode. Stable work.
4. AZ-Delivery ESP-32 Dev Kit C V4 + W5500. ESP_NOW_LAN mode. Stable work.

## Supported devices

Expand All @@ -41,7 +56,9 @@ Gateway for data exchange between ESP-NOW devices and MQTT broker via WiFi.
## To Do

- [X] Automatically add ESP-NOW devices configurations to Home Assistan via MQTT discovery.
- [ ] LAN connection support.
- [X] LAN connection support.
- [ ] nRF24 device support (in current time uses "RF Gateway").
- [ ] BLE device support (for ESP32).
- [ ] LoRa device support.

Any feedback via [e-mail](mailto:[email protected]) would be appreciated. Or... [Buy me a coffee](https://paypal.me/aZholtikov).
17 changes: 16 additions & 1 deletion data/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function loadBlock() {
}
document.getElementsByTagName('body')[0].innerHTML = newString;
setFirmvareValue('version', 'firmware');
setGpioValue('workModeSelect', 'workMode');
handleServerResponse();
}

Expand All @@ -37,6 +38,12 @@ function getValue(id) {
return value;
}

function getSelectValue(id) {
var select = document.getElementById(id);
var value = select.value;
return value;
}

function sendRequest(submit, server) {
request = new XMLHttpRequest();
request.open("GET", server, true);
Expand All @@ -49,7 +56,10 @@ function saveSetting(submit) {
+ "&login=" + getValue('mqttUserLogin') + "&pass=" + encodeURIComponent(getValue('mqttUserPassword'))
+ "&prefix=" + getValue('topicPrefix')
+ "&name=" + getValue('deviceName')
+ "&net=" + getValue('espnowNetName');
+ "&net=" + getValue('espnowNetName')
+ "&mode=" + getSelectValue('workModeSelect')
+ "&ntp=" + getValue('ntpHostName')
+ "&zone=" + getValue('gmtOffset');
sendRequest(submit, server);
alert("Please restart device for changes apply.");
}
Expand All @@ -62,3 +72,8 @@ function restart(submit) {
function setFirmvareValue(id, value) {
document.getElementById(id).innerHTML = document.getElementById(value).value;
}

function setGpioValue(id, value) {
var select = document.getElementById(id);
select.value = document.getElementById(value).value;
}
17 changes: 17 additions & 0 deletions data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,30 @@ <h1>ESP-NOW Gateway </h1>
title="ESP-NOW network name (1 to 20 characters)" />
</div>

<div class="wrapper">
<p class="text-select">Work mode:</p>
<input id="workMode" value="{{workMode}}" hidden />
<p><select id="workModeSelect">
<option value="0">ESP-NOW</option>
<option value="1">ESP-NOW WIFI</option>
<option value="2">ESP-NOW LAN</option>
</select></p>
</div>

<p class="text">WiFi settings</p>
<div class="wrapper">
<input class="text-inp" id="ssid" value="{{ssid}}" placeholder="SSID" label title="WiFi network name" />
<input id="password" value="{{password}}" onfocus="this.type='text'" type="password" placeholder="Password"
autocomplete="off" label title="WiFi password" />
</div>

<p class="text">NTP settings</p>
<div class="wrapper">
<input class="text-inp" id="ntpHostName" value="{{ntpHostName}}" placeholder="URL or IP" label
title="NTP server URL or IP" />
<input id="gmtOffset" value="{{gmtOffset}}" placeholder="Time zone" label title="Time zone" />
</div>

<p class="text">MQTT settings</p>
<div class="wrapper">
<input class="text-inp" id="mqttHostName" value="{{mqttHostName}}" placeholder="URL or IP" label
Expand Down
26 changes: 25 additions & 1 deletion data/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ h1 {
margin: 10px 0;
}

.text-select {
width: 35%;
font-weight: 600;
flex-shrink: 0;
margin-right: 10px;
}

.text-inp {
width: 48%;
min-height: 30px;
Expand Down Expand Up @@ -61,11 +68,28 @@ input {
margin-left: 10px;
}

select {
width: 140px;
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;
}

select:hover {
background: white;
cursor: pointer;
}

.btn {
width: 48%;
background: rgb(65, 125, 238);
Expand All @@ -88,7 +112,7 @@ input:hover {
}

#espnowNetName {
margin-bottom: 10px;
margin-bottom: 15px;
}

.wrapper.wrapper--end {
Expand Down
30 changes: 19 additions & 11 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -1,53 +1,61 @@
[env:ESP8266]
platform = espressif8266
board = nodemcuv2
board = esp12e
framework = arduino
board_build.filesystem = littlefs
lib_deps =
https://github.com/aZholtikov/ZHNetwork
https://github.com/aZholtikov/ZHConfig
https://github.com/aZholtikov/Async-Web-Server
https://github.com/bblanchon/ArduinoJson
https://github.com/marvinroger/async-mqtt-client
https://github.com/arduino-libraries/Ethernet
https://github.com/knolleary/pubsubclient
https://github.com/arduino-libraries/NTPClient

[env:ESP8266-OTA]
platform = espressif8266
board = nodemcuv2
board = esp12e
framework = arduino
board_build.filesystem = littlefs
upload_port = 192.168.1.113
upload_port = 192.168.4.1
upload_protocol = espota
lib_deps =
https://github.com/aZholtikov/ZHNetwork
https://github.com/aZholtikov/ZHConfig
https://github.com/aZholtikov/Async-Web-Server
https://github.com/bblanchon/ArduinoJson
https://github.com/marvinroger/async-mqtt-client
https://github.com/arduino-libraries/Ethernet
https://github.com/knolleary/pubsubclient
https://github.com/arduino-libraries/NTPClient

[env:ESP32]
platform = espressif32
board = az-delivery-devkit-v4
board = esp32dev
framework = arduino
board_build.filesystem = littlefs
lib_deps =
https://github.com/aZholtikov/ZHNetwork
https://github.com/aZholtikov/ZHConfig
https://github.com/aZholtikov/Async-Web-Server
https://github.com/bblanchon/ArduinoJson
https://github.com/marvinroger/async-mqtt-client
https://github.com/arduino-libraries/Ethernet
https://github.com/knolleary/pubsubclient
https://github.com/arduino-libraries/NTPClient
https://github.com/luc-github/ESP32SSDP

[env:ESP32-OTA]
platform = espressif32
board = az-delivery-devkit-v4
board = esp32dev
framework = arduino
board_build.filesystem = littlefs
upload_port = 192.168.1.110
upload_port = 192.168.4.1
upload_protocol = espota
lib_deps =
https://github.com/aZholtikov/ZHNetwork
https://github.com/aZholtikov/ZHConfig
https://github.com/aZholtikov/Async-Web-Server
https://github.com/bblanchon/ArduinoJson
https://github.com/marvinroger/async-mqtt-client
https://github.com/luc-github/ESP32SSDP
https://github.com/arduino-libraries/Ethernet
https://github.com/knolleary/pubsubclient
https://github.com/arduino-libraries/NTPClient
https://github.com/luc-github/ESP32SSDP
Loading

0 comments on commit 7a74c4f

Please sign in to comment.