Version 1.3
Added relay work modes.
This commit is contained in:
parent
dc17e39ff6
commit
0b603489fd
@ -11,6 +11,7 @@ ESP-NOW based switch for ESP8266. Alternate firmware for Tuya/SmartLife/eWeLink
|
|||||||
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.
|
||||||
7. Optionally support one external one wire digital climate sensor (DS18B20, DHT11 or DHT22) with automatically added sensor configuration to Home Assistan via MQTT discovery as a sensor. Periodically transmission sensor status (every 300 seconds) to the gateway.
|
7. Optionally support one external one wire digital climate sensor (DS18B20, DHT11 or DHT22) with automatically added sensor configuration to Home Assistan via MQTT discovery as a sensor. Periodically transmission sensor status (every 300 seconds) to the gateway.
|
||||||
|
8. Normal or reverse relay mode (normal by default).
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ function loadBlock() {
|
|||||||
}
|
}
|
||||||
document.getElementsByTagName('body')[0].innerHTML = newString;
|
document.getElementsByTagName('body')[0].innerHTML = newString;
|
||||||
setFirmvareValue('version', 'firmware');
|
setFirmvareValue('version', 'firmware');
|
||||||
|
setGpioValue('workModeSelect', 'workMode');
|
||||||
setGpioValue('relayPinSelect', 'relayPin');
|
setGpioValue('relayPinSelect', 'relayPin');
|
||||||
setGpioValue('relayPinTypeSelect', 'relayPinType');
|
setGpioValue('relayPinTypeSelect', 'relayPinType');
|
||||||
setGpioValue('ledPinSelect', 'ledPin');
|
setGpioValue('ledPinSelect', 'ledPin');
|
||||||
@ -71,7 +72,8 @@ function saveSetting(submit) {
|
|||||||
+ "&extButtonPin=" + getSelectValue('extButtonPinSelect')
|
+ "&extButtonPin=" + getSelectValue('extButtonPinSelect')
|
||||||
+ "&extButtonPinType=" + getSelectValue('extButtonPinTypeSelect')
|
+ "&extButtonPinType=" + getSelectValue('extButtonPinTypeSelect')
|
||||||
+ "&sensorPin=" + getSelectValue('sensorPinSelect')
|
+ "&sensorPin=" + getSelectValue('sensorPinSelect')
|
||||||
+ "&sensorType=" + getSelectValue('sensorTypeSelect');
|
+ "&sensorType=" + getSelectValue('sensorTypeSelect')
|
||||||
|
+ "&workMode=" + getSelectValue('workModeSelect');
|
||||||
sendRequest(submit, server);
|
sendRequest(submit, server);
|
||||||
alert("Please restart device for changes apply.");
|
alert("Please restart device for changes apply.");
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,15 @@
|
|||||||
title="ESP-NOW network name (1 to 20 characters)" />
|
title="ESP-NOW network name (1 to 20 characters)" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="wrapper">
|
||||||
|
<p class="text-select">Work mode:</p>
|
||||||
|
<input id="workMode" value="{{workMode}}" hidden />
|
||||||
|
<p><select id="workModeSelect">
|
||||||
|
<option value="0">NORMAL</option>
|
||||||
|
<option value="1">REVERSE</option>
|
||||||
|
</select></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<p class="text-select">Relay GPIO:</p>
|
<p class="text-select">Relay GPIO:</p>
|
||||||
<input id="relayPin" value="{{relayPin}}" hidden />
|
<input id="relayPin" value="{{relayPin}}" hidden />
|
||||||
|
27
src/main.cpp
27
src/main.cpp
@ -32,10 +32,12 @@ typedef struct
|
|||||||
|
|
||||||
std::vector<espnow_message_t> espnowMessage;
|
std::vector<espnow_message_t> espnowMessage;
|
||||||
|
|
||||||
const String firmware{"1.21"};
|
const String firmware{"1.3"};
|
||||||
|
|
||||||
String espnowNetName{"DEFAULT"};
|
String espnowNetName{"DEFAULT"};
|
||||||
|
|
||||||
|
uint8_t workMode{0};
|
||||||
|
|
||||||
String deviceName = "ESP-NOW switch " + String(ESP.getChipId(), HEX);
|
String deviceName = "ESP-NOW switch " + String(ESP.getChipId(), HEX);
|
||||||
|
|
||||||
bool relayStatus{false};
|
bool relayStatus{false};
|
||||||
@ -203,9 +205,19 @@ void onUnicastReceiving(const char *data, const uint8_t *sender)
|
|||||||
deserializeJson(json, incomingData.message);
|
deserializeJson(json, incomingData.message);
|
||||||
relayStatus = json["set"] == payloadOn ? true : false;
|
relayStatus = json["set"] == payloadOn ? true : false;
|
||||||
if (relayPin)
|
if (relayPin)
|
||||||
|
{
|
||||||
|
if (workMode)
|
||||||
|
digitalWrite(relayPin, relayPinType ? !relayStatus : relayStatus);
|
||||||
|
else
|
||||||
digitalWrite(relayPin, relayPinType ? relayStatus : !relayStatus);
|
digitalWrite(relayPin, relayPinType ? relayStatus : !relayStatus);
|
||||||
|
}
|
||||||
if (ledPin)
|
if (ledPin)
|
||||||
|
{
|
||||||
|
if (workMode)
|
||||||
|
digitalWrite(ledPin, ledPinType ? !relayStatus : relayStatus);
|
||||||
|
else
|
||||||
digitalWrite(ledPin, ledPinType ? relayStatus : !relayStatus);
|
digitalWrite(ledPin, ledPinType ? relayStatus : !relayStatus);
|
||||||
|
}
|
||||||
saveConfig();
|
saveConfig();
|
||||||
sendStatusMessage();
|
sendStatusMessage();
|
||||||
}
|
}
|
||||||
@ -258,6 +270,7 @@ void loadConfig()
|
|||||||
ledPinType = json["ledPinType"];
|
ledPinType = json["ledPinType"];
|
||||||
sensorPin = json["sensorPin"];
|
sensorPin = json["sensorPin"];
|
||||||
sensorType = json["sensorType"];
|
sensorType = json["sensorType"];
|
||||||
|
workMode = json["workMode"];
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,6 +291,7 @@ void saveConfig()
|
|||||||
json["ledPinType"] = ledPinType;
|
json["ledPinType"] = ledPinType;
|
||||||
json["sensorPin"] = sensorPin;
|
json["sensorPin"] = sensorPin;
|
||||||
json["sensorType"] = sensorType;
|
json["sensorType"] = sensorType;
|
||||||
|
json["workMode"] = workMode;
|
||||||
json["system"] = "empty";
|
json["system"] = "empty";
|
||||||
File file = LittleFS.open("/config.json", "w");
|
File file = LittleFS.open("/config.json", "w");
|
||||||
serializeJsonPretty(json, file);
|
serializeJsonPretty(json, file);
|
||||||
@ -301,6 +315,7 @@ void setupWebServer()
|
|||||||
ledPinType = request->getParam("ledPinType")->value().toInt();
|
ledPinType = request->getParam("ledPinType")->value().toInt();
|
||||||
sensorPin = request->getParam("sensorPin")->value().toInt();
|
sensorPin = request->getParam("sensorPin")->value().toInt();
|
||||||
sensorType = request->getParam("sensorType")->value().toInt();
|
sensorType = request->getParam("sensorType")->value().toInt();
|
||||||
|
workMode = request->getParam("workMode")->value().toInt();
|
||||||
deviceName = request->getParam("deviceName")->value();
|
deviceName = request->getParam("deviceName")->value();
|
||||||
espnowNetName = request->getParam("espnowNetName")->value();
|
espnowNetName = request->getParam("espnowNetName")->value();
|
||||||
request->send(200);
|
request->send(200);
|
||||||
@ -333,9 +348,19 @@ void switchingRelay()
|
|||||||
{
|
{
|
||||||
relayStatus = !relayStatus;
|
relayStatus = !relayStatus;
|
||||||
if (relayPin)
|
if (relayPin)
|
||||||
|
{
|
||||||
|
if (workMode)
|
||||||
|
digitalWrite(relayPin, relayPinType ? !relayStatus : relayStatus);
|
||||||
|
else
|
||||||
digitalWrite(relayPin, relayPinType ? relayStatus : !relayStatus);
|
digitalWrite(relayPin, relayPinType ? relayStatus : !relayStatus);
|
||||||
|
}
|
||||||
if (ledPin)
|
if (ledPin)
|
||||||
|
{
|
||||||
|
if (workMode)
|
||||||
|
digitalWrite(ledPin, ledPinType ? !relayStatus : relayStatus);
|
||||||
|
else
|
||||||
digitalWrite(ledPin, ledPinType ? relayStatus : !relayStatus);
|
digitalWrite(ledPin, ledPinType ? relayStatus : !relayStatus);
|
||||||
|
}
|
||||||
saveConfig();
|
saveConfig();
|
||||||
sendStatusMessage();
|
sendStatusMessage();
|
||||||
ETS_GPIO_INTR_ENABLE();
|
ETS_GPIO_INTR_ENABLE();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user