Skip to content

Commit

Permalink
fixed SONOFF setup and letscontrolit#2892 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
giig1967g authored and TD-er committed Sep 30, 2020
1 parent f2878b8 commit 21fe3fe
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 55 deletions.
10 changes: 6 additions & 4 deletions src/Command.ino
Expand Up @@ -433,11 +433,13 @@ bool ExecuteCommand(taskIndex_t taskIndex, byte source, const char *Line, bool t
if (tryInternal) {
String status;
bool handled = executeInternalCommand(cmd.c_str(), &TempEvent, action.c_str(), status);
if (status.length() > 0) {
delay(0);
SendStatus(source, status);
delay(0);
delay(0);
if (status.length() > 0 && source != VALUE_SOURCE_HTTP) {
// giig1967g: if source == HTTP do not send 'status' as the output is handled in WebServer_ControlPage.ino file
SendStatus(source, status);
}
delay(0);

if (handled) {
return true;
}
Expand Down
47 changes: 29 additions & 18 deletions src/WebServer_ControlPage.ino
Expand Up @@ -23,36 +23,47 @@ void handle_control() {
#endif // ifndef BUILD_NO_DEBUG

bool handledCmd = false;

bool sendOK = false;
// in case of event, store to buffer and return...
String command = parseString(webrequest, 1);

if ((command == F("event")) || (command == F("asyncevent")))
{
eventQueue.add(parseStringToEnd(webrequest, 2));
handledCmd = true;
}
else {
// else if (command.equalsIgnoreCase(F("taskrun")) ||
// command.equalsIgnoreCase(F("taskvalueset")) ||
// command.equalsIgnoreCase(F("taskvaluetoggle")) ||
// command.equalsIgnoreCase(F("let")) ||
// command.equalsIgnoreCase(F("logPortStatus")) ||
// command.equalsIgnoreCase(F("jsonportstatus")) ||
// command.equalsIgnoreCase(F("rules"))) {
ExecuteCommand_internal(EventValueSource::Enum::VALUE_SOURCE_HTTP, webrequest.c_str());
handledCmd = true;
handledCmd = true;
sendOK = true;
// }
// else {
} else if (command.equalsIgnoreCase(F("taskrun")) ||
command.equalsIgnoreCase(F("taskvalueset")) ||
command.equalsIgnoreCase(F("taskvaluetoggle")) ||
command.equalsIgnoreCase(F("let")) ||
command.equalsIgnoreCase(F("logPortStatus")) ||
command.equalsIgnoreCase(F("jsonportstatus")) ||
command.equalsIgnoreCase(F("rules"))) {
handledCmd = ExecuteCommand_internal(EventValueSource::Enum::VALUE_SOURCE_HTTP, webrequest.c_str());
sendOK = true;
//handledCmd = true;
} else {
ExecuteCommand_internal(VALUE_SOURCE_HTTP, webrequest.c_str());
handledCmd = false;
printToWeb = true;
printWebString = "";
TXBuffer.startJsonStream();
handledCmd = ExecuteCommand_internal(VALUE_SOURCE_HTTP, webrequest.c_str());
TXBuffer += printWebString;
TXBuffer.endStream();
printToWeb = false;
sendOK = false;
}

if (handledCmd) {
TXBuffer.startStream("*");
addHtml(F("OK"));
TXBuffer.endStream();
if (sendOK) {
TXBuffer.startStream("*");
TXBuffer += "OK";
TXBuffer.endStream();
}
return;
}

printToWeb = true;
printWebString = "";
bool unknownCmd = !ExecuteCommand_plugin_config(EventValueSource::Enum::VALUE_SOURCE_HTTP, webrequest.c_str());
Expand Down
8 changes: 4 additions & 4 deletions src/_P001_Switch.ino
Expand Up @@ -480,9 +480,6 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
// CASE 2: not using SafeButton, or already waited 1 more 100ms cycle, so proceed.
else if ((state != currentStatus.state) || currentStatus.forceEvent)
{
// Reset forceEvent
currentStatus.forceEvent = 0;

// Reset SafeButton counter
PCONFIG_LONG(3) = 0;

Expand Down Expand Up @@ -539,7 +536,7 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
}

// send if output needs to be changed
if (currentOutputState != new_outputState)
if (currentOutputState != new_outputState || currentStatus.forceEvent)
{
byte output_value;
currentStatus.output = new_outputState;
Expand Down Expand Up @@ -583,6 +580,9 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
}
PCONFIG_LONG(0) = millis();
}
// Reset forceEvent
currentStatus.forceEvent = 0;

savePortStatus(key, currentStatus);
}

Expand Down
30 changes: 16 additions & 14 deletions src/_P009_MCP.ino
Expand Up @@ -328,17 +328,17 @@ boolean Plugin_009(byte function, struct EventStruct *event, String& string)
portStatusStruct currentStatus;
const uint32_t key = createKey(PLUGIN_ID_009, CONFIG_PORT);

// WARNING operator [],creates an entry in map if key doesn't exist:
currentStatus = globalMapPortStatus[key];

// Bug fixed: avoid 10xSEC in case of a non-fully configured device (no port defined yet)
if ((state != -1) && (CONFIG_PORT >= 0)) {
// CASE 1: using SafeButton, so wait 1 more 100ms cycle to acknowledge the status change
if (round(PCONFIG_FLOAT(3)) && (state != currentStatus.state) && (PCONFIG_LONG(3) == 0))
{
addLog(LOG_LEVEL_DEBUG, F("MCP :SafeButton 1st click."))
PCONFIG_LONG(3) = 1;
}
//CASE 1: using SafeButton, so wait 1 more 100ms cycle to acknowledge the status change
if (round(PCONFIG_FLOAT(3)) && state != currentStatus.state && PCONFIG_LONG(3)==0)
{
addLog(LOG_LEVEL_DEBUG,F("MCP :SafeButton 1st click."))
PCONFIG_LONG(3) = 1;
}
//CASE 2: not using SafeButton, or already waited 1 more 100ms cycle, so proceed.
else if (state != currentStatus.state || currentStatus.forceEvent)
{
// Reset SafeButton counter
PCONFIG_LONG(3) = 0;

// CASE 2: not using SafeButton, or already waited 1 more 100ms cycle, so proceed.
else if ((state != currentStatus.state) || currentStatus.forceEvent)
Expand Down Expand Up @@ -414,10 +414,12 @@ boolean Plugin_009(byte function, struct EventStruct *event, String& string)
event->sensorType = Sensor_VType::SENSOR_TYPE_SWITCH;
sendData(event);

// reset Userdata so it displays the correct state value in the web page
UserVar[event->BaseVarIndex] = sendState ? 1 : 0;
PCONFIG_LONG(0) = millis();
}
//Reset forceEvent
currentStatus.forceEvent = 0;

PCONFIG_LONG(0) = millis();
savePortStatus(key,currentStatus);
}
savePortStatus(key, currentStatus);
}
Expand Down
32 changes: 17 additions & 15 deletions src/_P019_PCF8574.ino
Expand Up @@ -333,18 +333,18 @@ boolean Plugin_019(byte function, struct EventStruct *event, String& string)
portStatusStruct currentStatus;
const uint32_t key = createKey(PLUGIN_ID_019, CONFIG_PORT);

// WARNING operator [],creates an entry in map if key doesn't exist:
currentStatus = globalMapPortStatus[key];

// Bug fixed: avoid 10xSEC in case of a non-fully configured device (no port defined yet)
if ((state != -1) && (CONFIG_PORT >= 0)) {
// CASE 1: using SafeButton, so wait 1 more 100ms cycle to acknowledge the status change
// QUESTION: MAYBE IT'S BETTER TO WAIT 2 CYCLES??
if (round(PCONFIG_FLOAT(3)) && (state != currentStatus.state) && (PCONFIG_LONG(3) == 0))
{
addLog(LOG_LEVEL_DEBUG, F("PCF :SafeButton 1st click."))
PCONFIG_LONG(3) = 1;
}
//CASE 1: using SafeButton, so wait 1 more 100ms cycle to acknowledge the status change
//QUESTION: MAYBE IT'S BETTER TO WAIT 2 CYCLES??
if (round(PCONFIG_FLOAT(3)) && state != currentStatus.state && PCONFIG_LONG(3)==0)
{
addLog(LOG_LEVEL_DEBUG,F("PCF :SafeButton 1st click."))
PCONFIG_LONG(3) = 1;
}
//CASE 2: not using SafeButton, or already waited 1 more 100ms cycle, so proceed.
else if (state != currentStatus.state || currentStatus.forceEvent)
{
// Reset SafeButton counter
PCONFIG_LONG(3) = 0;

// CASE 2: not using SafeButton, or already waited 1 more 100ms cycle, so proceed.
else if ((state != currentStatus.state) || currentStatus.forceEvent)
Expand Down Expand Up @@ -424,10 +424,12 @@ boolean Plugin_019(byte function, struct EventStruct *event, String& string)
event->sensorType = Sensor_VType::SENSOR_TYPE_SWITCH;
sendData(event);

// reset Userdata so it displays the correct state value in the web page
UserVar[event->BaseVarIndex] = sendState ? 1 : 0;
PCONFIG_LONG(0) = millis();
}
//Reset forceEvent
currentStatus.forceEvent = 0;

PCONFIG_LONG(0) = millis();
savePortStatus(key,currentStatus);
}
savePortStatus(key, currentStatus);
}
Expand Down

0 comments on commit 21fe3fe

Please sign in to comment.