Status of relay switch not maintained after ESP Restart
Moderators: grovkillen, Stuntteam, TD-er
Status of relay switch not maintained after ESP Restart
Hello,
I am using a relay connected to ESP and it is working fine, but if i power down and then powerup ESP8266 the lasts state it is not maintained.
In may opinion it should maintain ( or optional), Is it possible ? ( by writing the last status in eprom/flash)
Waiting news soon
TIA
Best regards,
F. Coelho
I am using a relay connected to ESP and it is working fine, but if i power down and then powerup ESP8266 the lasts state it is not maintained.
In may opinion it should maintain ( or optional), Is it possible ? ( by writing the last status in eprom/flash)
Waiting news soon
TIA
Best regards,
F. Coelho
Re: Status of relay switch not maintained after ESP Restart
First of all: Thank YOU for this aweosome piece of software!
Second: Save specific pin/s state/s to EEPROM at runtime is the missing link in my project....
Second: Save specific pin/s state/s to EEPROM at runtime is the missing link in my project....
Re: Status of relay switch not maintained after ESP Restart
Hi again,
I found a workaround about this problem ...
The only thing is to add these two lines:
after 201 line in _P001_Switch
So when you change an state of GPIO via Domoticz with command:
or
these two lines will write corresponding GPIO states into flash ...
where "event->Par1" is GPIO pin, and "event->Par2 + 1" - pin state (0-default, 1 - ON, 2 - OFF (or reverse))
For me it works without problems.
Please developer/s correct me if I'm wrong.
Chears!
I found a workaround about this problem ...
The only thing is to add these two lines:
Code: Select all
Settings.PinStates[event->Par1] = event->Par2 + 1;
SaveSettings();
So when you change an state of GPIO via Domoticz with command:
Code: Select all
http://YOUR_ESP_ADDRESS/control?cmd=gpio,12,0
Code: Select all
http://YOUR_ESP_ADDRESS/control?cmd=gpio,12,1
where "event->Par1" is GPIO pin, and "event->Par2 + 1" - pin state (0-default, 1 - ON, 2 - OFF (or reverse))
For me it works without problems.
Please developer/s correct me if I'm wrong.
Chears!
Re: Status of relay switch not maintained after ESP Restart
Interesting, but can you be more specific where to put those lines in the switch plugin ?simeonof wrote:Hi again,
I found a workaround about this problem ...
Because line 201 is different in different releases.
Would be good to see a few lines before and after these two lines so it is clear where to put them.
Re: Status of relay switch not maintained after ESP Restart
In _P001_Switch.ino:
I thing there is no changes in this module recently....
Code: Select all
case PLUGIN_WRITE:
{
String tmpString = string;
int argIndex = tmpString.indexOf(',');
if (argIndex)
tmpString = tmpString.substring(0, argIndex);
if (tmpString.equalsIgnoreCase(F("GPIO")))
{
success = true;
if (event->Par1 >= 0 && event->Par1 <= 16)
{
pinMode(event->Par1, OUTPUT);
digitalWrite(event->Par1, event->Par2);
//<-------------------------------------------------------------------------------------------------------->
Settings.PinStates[event->Par1] = event->Par2 + 1; //Save GPIO settings
SaveSettings(); //Save GPIO settings
//<-------------------------------------------------------------------------------------------------------->
if (printToWeb)
{
printWebString += F("GPIO ");
printWebString += event->Par1;
printWebString += F(" Set to ");
printWebString += event->Par2;
printWebString += F("<BR>");
}
}
}
Re: Status of relay switch not maintained after ESP Restart
Hi fellows.
Can you write me back how can I do the same in the last release R120?
Can you write me back how can I do the same in the last release R120?
Re: Status of relay switch not maintained after ESP Restart
Or alternately...
In the advanced options switch on retain message...
Then add (or amend your existing rule) to publish topic: /device_name/GPIO/12 message 1
Assuming that you are switching the device. If you are commanding it from a HA server, add a retain to it's message settings.
You switch will recieve the retained message on connection to the mqtt server.
In the advanced options switch on retain message...
Then add (or amend your existing rule) to publish topic: /device_name/GPIO/12 message 1
Assuming that you are switching the device. If you are commanding it from a HA server, add a retain to it's message settings.
You switch will recieve the retained message on connection to the mqtt server.
Re: Status of relay switch not maintained after ESP Restart
Please I need to know how to do this from the firmware in the last release R120, without the mqtt server, thanks!
Re: Status of relay switch not maintained after ESP Restart
I want to use it only that way:
So I need to change source code.
Code: Select all
http://YOUR_ESP_ADDRESS/control?cmd=gpio,12,0
Re: Status of relay switch not maintained after ESP Restart
It looks like we have to change:
to
Code: Select all
Settings.PinStates[event->Par1] = event->Par2 + 1; //Save GPIO settings
Code: Select all
Settings.PinBootStates[event->Par1] = event->Par2 + 1; //Save GPIO settings
Re: Status of relay switch not maintained after ESP Restart
Compile but doesn't work 

Re: Status of relay switch not maintained after ESP Restart
Compiles but doesn't work 

Re: Status of relay switch not maintained after ESP Restart
Hello,
Very interested by this feature for persistant state on relay switch, i have patched the R120 release.
As said, the compil JOB is ok but with relays don't work.
any ideas ?
br,
Very interested by this feature for persistant state on relay switch, i have patched the R120 release.
As said, the compil JOB is ok but with relays don't work.
any ideas ?
br,
Re: Status of relay switch not maintained after ESP Restart
My code looks like that:
and it works. But one condition: no devices configured in "Devices" menu. When I set Switch input device, saving states wasn't working properly.
Code: Select all
case PLUGIN_WRITE:
{
String log = "";
String command = parseString(string, 1);
if (command == F("gpio"))
{
success = true;
if (event->Par1 >= 0 && event->Par1 <= 16)
{
pinMode(event->Par1, OUTPUT);
digitalWrite(event->Par1, event->Par2);
setPinState(PLUGIN_ID_001, event->Par1, PIN_MODE_OUTPUT, event->Par2);
Settings.PinBootStates[event->Par1] = event->Par2+1; //Save GPIO settings
SaveSettings();
log = String(F("SW : GPIO ")) + String(event->Par1) + String(F(" Set to ")) + String(event->Par2);
addLog(LOG_LEVEL_INFO, log);
SendStatus(event->Source, getPinStateJSON(SEARCH_PIN_STATE, PLUGIN_ID_001, event->Par1, log, 0));
}
}
Re: Status of relay switch not maintained after ESP Restart
Hello All,
After we add the lines on in the switch.ino file i should re-flash the ESP to make it work?
Plus is it a correct thing that makes the GPIO to maintain the last status ?
Thank you,
After we add the lines on in the switch.ino file i should re-flash the ESP to make it work?
Plus is it a correct thing that makes the GPIO to maintain the last status ?
Thank you,
Re: Status of relay switch not maintained after ESP Restart
Guys, there is a really good hardware fix for that problem. Use I2C expander, they keep their gpio output states, even while the ESP is rebooting.
Even if you can retain the value in flash, the GPIOs will still "click" through as the ESP boots (depending which ones), or at least go low during reboot. If you use I2C expander, the output stays unchanged until new command is received. At least the output will not change due to warmboots, which can always happen with esp easy
Even if you can retain the value in flash, the GPIOs will still "click" through as the ESP boots (depending which ones), or at least go low during reboot. If you use I2C expander, the output stays unchanged until new command is received. At least the output will not change due to warmboots, which can always happen with esp easy
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8
Re: Status of relay switch not maintained after ESP Restart
The other options seems to retain the state on MQTT, that is if you use MQTT at all
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8
Who is online
Users browsing this forum: No registered users and 10 guests