Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
82e736dc8b | |||
439722511f | |||
5d9784c9ae |
@ -19,7 +19,7 @@ ESP-NOW based switch for ESP8266. Alternate firmware for Tuya/SmartLife WiFi swi
|
||||
|
||||
## Tested on
|
||||
|
||||
Coming soon.
|
||||
See [here](https://github.com/aZholtikov/ESP-NOW-Switch/tree/main/hardware).
|
||||
|
||||
## Attention
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
p{
|
||||
margin: 0 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "Gill Sans", sans-serif;
|
||||
background: rgb(255, 255, 255);
|
||||
@ -21,13 +25,15 @@ h1 {
|
||||
font-weight: 600;
|
||||
flex-shrink: 0;
|
||||
margin-right: 10px;
|
||||
margin-left: 10px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.text-select {
|
||||
width: 35%;
|
||||
font-weight: 600;
|
||||
flex-shrink: 0;
|
||||
margin-right: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.wrapper {
|
||||
@ -42,6 +48,7 @@ input {
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
margin-bottom: 10px;
|
||||
margin-left: 10px;
|
||||
padding: 0 10px;
|
||||
color: rgb(0, 0, 0);
|
||||
background: #a3e0f1;
|
||||
@ -76,6 +83,8 @@ select:hover {
|
||||
background: rgb(65, 125, 238);
|
||||
color: white;
|
||||
transition: .5s;
|
||||
margin-left: 0;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
@ -89,6 +98,10 @@ select:hover {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#espnowNetName {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.wrapper.wrapper--end {
|
||||
align-items: baseline;
|
||||
}
|
BIN
hardware/MOES_1CH_10A/Pins.jpeg
Normal file
BIN
hardware/MOES_1CH_10A/Pins.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 MiB |
BIN
hardware/MOES_1CH_10A/TYWE2S.pdf
Normal file
BIN
hardware/MOES_1CH_10A/TYWE2S.pdf
Normal file
Binary file not shown.
BIN
hardware/MOES_1CH_10A/WB2S.pdf
Normal file
BIN
hardware/MOES_1CH_10A/WB2S.pdf
Normal file
Binary file not shown.
BIN
hardware/MOES_1CH_10A/inside1.jpeg
Normal file
BIN
hardware/MOES_1CH_10A/inside1.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 MiB |
BIN
hardware/MOES_1CH_10A/inside2.jpeg
Normal file
BIN
hardware/MOES_1CH_10A/inside2.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 MiB |
BIN
hardware/MOES_1CH_10A/inside3.jpeg
Normal file
BIN
hardware/MOES_1CH_10A/inside3.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 MiB |
BIN
hardware/MOES_1CH_10A/main.jpeg
Normal file
BIN
hardware/MOES_1CH_10A/main.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 MiB |
12
hardware/README.md
Normal file
12
hardware/README.md
Normal file
@ -0,0 +1,12 @@
|
||||
# Tested on
|
||||
|
||||
1. MOES 1CH 10A. Built on Tuya WiFi module WA2 (WB2S) (BK7231T chip). Replacement required. Performed replacement with ESP-02S (TYWE2S). [Photo](https://github.com/aZholtikov/ESP-NOW-Switch/tree/main/hardware/MOES_1CH_10A).
|
||||
|
||||
```text
|
||||
Relay GPIO GPIO04 HIGH
|
||||
Led GPIO GPIO12 LOW
|
||||
Button GPIO GPIO14 RISING
|
||||
```
|
||||
|
||||
2. AUBESS 1CH 16A (Coming soon)
|
||||
3. LIGHT E27 SOCKET (Coming soon)
|
@ -1,4 +1,4 @@
|
||||
[env:esp8266]
|
||||
[env:ESP-12E]
|
||||
platform = espressif8266
|
||||
board = esp12e
|
||||
framework = arduino
|
||||
@ -9,7 +9,7 @@ lib_deps =
|
||||
bblanchon/ArduinoJson@^6.19.4
|
||||
me-no-dev/ESP Async WebServer@^1.2.3
|
||||
|
||||
[env:esp8266-ota]
|
||||
[env:ESP-12E-OTA]
|
||||
platform = espressif8266
|
||||
board = esp12e
|
||||
framework = arduino
|
||||
@ -22,7 +22,7 @@ lib_deps =
|
||||
bblanchon/ArduinoJson@^6.19.4
|
||||
me-no-dev/ESP Async WebServer@^1.2.3
|
||||
|
||||
[env:esp8285]
|
||||
[env:ESP-02S]
|
||||
platform = espressif8266
|
||||
board = esp8285
|
||||
framework = arduino
|
||||
@ -32,16 +32,3 @@ lib_deps =
|
||||
https://github.com/aZholtikov/ZHConfig
|
||||
bblanchon/ArduinoJson@^6.19.4
|
||||
me-no-dev/ESP Async WebServer@^1.2.3
|
||||
|
||||
[env:esp8285-ota]
|
||||
platform = espressif8266
|
||||
board = esp8285
|
||||
framework = arduino
|
||||
upload_port = 192.168.4.1
|
||||
upload_protocol = espota
|
||||
lib_extra_dirs =
|
||||
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
|
||||
|
32
src/main.cpp
32
src/main.cpp
@ -21,11 +21,11 @@ void sendKeepAliveMessage(void);
|
||||
void sendConfigMessage(void);
|
||||
void sendStatusMessage(void);
|
||||
|
||||
const String firmware{"1.0"};
|
||||
const String firmware{"1.11"};
|
||||
|
||||
String espnowNetName{"DEFAULT"};
|
||||
|
||||
String deviceName{"ESP-NOW switch"};
|
||||
String deviceName = "ESP-NOW switch " + String(ESP.getChipId(), HEX);
|
||||
|
||||
bool relayStatus{false};
|
||||
uint8_t relayPin{0};
|
||||
@ -41,6 +41,9 @@ bool wasMqttAvailable{false};
|
||||
|
||||
uint8_t gatewayMAC[6]{0};
|
||||
|
||||
const String payloadOn{"ON"};
|
||||
const String payloadOff{"OFF"};
|
||||
|
||||
ZHNetwork myNet;
|
||||
AsyncWebServer webServer(80);
|
||||
|
||||
@ -103,7 +106,7 @@ void setup()
|
||||
myNet.setOnConfirmReceivingCallback(onConfirmReceiving);
|
||||
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
WiFi.softAP(("ESP-NOW Switch " + myNet.getNodeMac()).c_str(), "12345678", 1, 0);
|
||||
WiFi.softAP(("ESP-NOW switch " + String(ESP.getChipId(), HEX)).c_str(), "12345678", 1, 0);
|
||||
apModeHideTimer.once(300, apModeHideTimerCallback);
|
||||
|
||||
setupWebServer();
|
||||
@ -161,7 +164,7 @@ void onUnicastReceiving(const char *data, const uint8_t *sender)
|
||||
if (incomingData.payloadsType == ENPT_SET)
|
||||
{
|
||||
deserializeJson(json, incomingData.message);
|
||||
relayStatus = json["set"] == "ON" ? true : false;
|
||||
relayStatus = json["set"] == payloadOn ? true : false;
|
||||
if (relayPin)
|
||||
digitalWrite(relayPin, relayPinType ? relayStatus : !relayStatus);
|
||||
if (ledPin)
|
||||
@ -171,7 +174,8 @@ void onUnicastReceiving(const char *data, const uint8_t *sender)
|
||||
}
|
||||
if (incomingData.payloadsType == ENPT_UPDATE)
|
||||
{
|
||||
WiFi.softAP(("ESP-NOW Switch " + myNet.getNodeMac()).c_str(), "12345678", 1, 0);
|
||||
WiFi.softAP(("ESP-NOW switch " + String(ESP.getChipId(), HEX)).c_str(), "12345678", 1, 0);
|
||||
webServer.begin();
|
||||
apModeHideTimer.once(300, apModeHideTimerCallback);
|
||||
}
|
||||
if (incomingData.payloadsType == ENPT_RESTART)
|
||||
@ -288,7 +292,7 @@ void setupWebServer()
|
||||
void IRAM_ATTR buttonInterrupt()
|
||||
{
|
||||
ETS_GPIO_INTR_DISABLE();
|
||||
buttonInterruptTimer.once_ms(50, switchingRelay); // For prevent contact chatter.
|
||||
buttonInterruptTimer.once_ms(100, switchingRelay); // For prevent contact chatter.
|
||||
}
|
||||
|
||||
void switchingRelay()
|
||||
@ -314,7 +318,7 @@ void sendAttributesMessage()
|
||||
uint32_t days = hours / 24;
|
||||
esp_now_payload_data_t outgoingData{ENDT_SWITCH, ENPT_ATTRIBUTES};
|
||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||
json["Type"] = "ESP-NOW Switch";
|
||||
json["Type"] = "ESP-NOW switch";
|
||||
json["MCU"] = "ESP8266";
|
||||
json["MAC"] = myNet.getNodeMac();
|
||||
json["Firmware"] = firmware;
|
||||
@ -353,9 +357,10 @@ void sendConfigMessage()
|
||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||
json["name"] = deviceName;
|
||||
json["unit"] = 1;
|
||||
json["type"] = getValueName(HACT_SWITCH);
|
||||
json["class"] = getValueName(HASWDC_SWITCH);
|
||||
json["reverse"] = "false";
|
||||
json["type"] = HACT_SWITCH;
|
||||
json["class"] = HASWDC_SWITCH;
|
||||
json["payload_on"] = payloadOn;
|
||||
json["payload_off"] = payloadOff;
|
||||
char buffer[sizeof(esp_now_payload_data_t::message)]{0};
|
||||
serializeJsonPretty(json, buffer);
|
||||
memcpy(outgoingData.message, buffer, sizeof(esp_now_payload_data_t::message));
|
||||
@ -364,7 +369,7 @@ void sendConfigMessage()
|
||||
myNet.sendUnicastMessage(temp, gatewayMAC, true);
|
||||
|
||||
configMessageResendTimerSemaphore = true;
|
||||
configMessageResendTimer.once(5, sendConfigMessage);
|
||||
configMessageResendTimer.once(1, sendConfigMessage);
|
||||
}
|
||||
|
||||
void sendStatusMessage()
|
||||
@ -374,7 +379,7 @@ void sendStatusMessage()
|
||||
statusMessageTimerSemaphore = false;
|
||||
esp_now_payload_data_t outgoingData{ENDT_SWITCH, ENPT_STATE};
|
||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||
json["state"] = relayStatus ? "ON" : "OFF";
|
||||
json["state"] = relayStatus ? payloadOn : payloadOff;
|
||||
char buffer[sizeof(esp_now_payload_data_t::message)]{0};
|
||||
serializeJsonPretty(json, buffer);
|
||||
memcpy(&outgoingData.message, &buffer, sizeof(esp_now_payload_data_t::message));
|
||||
@ -394,7 +399,8 @@ void gatewayAvailabilityCheckTimerCallback()
|
||||
|
||||
void apModeHideTimerCallback()
|
||||
{
|
||||
WiFi.softAP(("ESP-NOW Switch " + myNet.getNodeMac()).c_str(), "12345678", 1, 1);
|
||||
WiFi.softAP(("ESP-NOW switch " + String(ESP.getChipId(), HEX)).c_str(), "12345678", 1, 1);
|
||||
webServer.end();
|
||||
}
|
||||
|
||||
void attributesMessageTimerCallback()
|
||||
|
Reference in New Issue
Block a user