Status of relay switch not maintained after ESP Restart

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
fcoelho
New user
Posts: 1
Joined: 17 Jan 2016, 01:16

Status of relay switch not maintained after ESP Restart

#1 Post by fcoelho » 17 Jan 2016, 01:24

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

simeonof
Normal user
Posts: 10
Joined: 20 Jan 2016, 06:38

Re: Status of relay switch not maintained after ESP Restart

#2 Post by simeonof » 20 Jan 2016, 07:05

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....

simeonof
Normal user
Posts: 10
Joined: 20 Jan 2016, 06:38

Re: Status of relay switch not maintained after ESP Restart

#3 Post by simeonof » 04 Mar 2016, 23:13

Hi again,
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();
after 201 line in _P001_Switch
So when you change an state of GPIO via Domoticz with command:

Code: Select all

http://YOUR_ESP_ADDRESS/control?cmd=gpio,12,0
or

Code: Select all

http://YOUR_ESP_ADDRESS/control?cmd=gpio,12,1
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!

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Status of relay switch not maintained after ESP Restart

#4 Post by costo » 05 Mar 2016, 01:15

simeonof wrote:Hi again,
I found a workaround about this problem ...
Interesting, but can you be more specific where to put those lines in the switch plugin ?
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.

simeonof
Normal user
Posts: 10
Joined: 20 Jan 2016, 06:38

Re: Status of relay switch not maintained after ESP Restart

#5 Post by simeonof » 05 Mar 2016, 18:55

In _P001_Switch.ino:

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>");
            }
          }
        }
I thing there is no changes in this module recently....

mcteusz
New user
Posts: 7
Joined: 07 Mar 2017, 13:53

Re: Status of relay switch not maintained after ESP Restart

#6 Post by mcteusz » 07 Mar 2017, 14:26

Hi fellows.
Can you write me back how can I do the same in the last release R120?

Justblair
Normal user
Posts: 63
Joined: 08 Aug 2016, 23:42

Re: Status of relay switch not maintained after ESP Restart

#7 Post by Justblair » 07 Mar 2017, 16:00

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.

mlemes
New user
Posts: 4
Joined: 07 Mar 2017, 18:58

Re: Status of relay switch not maintained after ESP Restart

#8 Post by mlemes » 07 Mar 2017, 19:02

Please I need to know how to do this from the firmware in the last release R120, without the mqtt server, thanks!

mcteusz
New user
Posts: 7
Joined: 07 Mar 2017, 13:53

Re: Status of relay switch not maintained after ESP Restart

#9 Post by mcteusz » 08 Mar 2017, 09:11

I want to use it only that way:

Code: Select all

http://YOUR_ESP_ADDRESS/control?cmd=gpio,12,0
So I need to change source code.

mcteusz
New user
Posts: 7
Joined: 07 Mar 2017, 13:53

Re: Status of relay switch not maintained after ESP Restart

#10 Post by mcteusz » 13 Mar 2017, 14:21

It looks like we have to change:

Code: Select all

Settings.PinStates[event->Par1] = event->Par2 + 1;        //Save GPIO settings
to

Code: Select all

Settings.PinBootStates[event->Par1] = event->Par2 + 1;        //Save GPIO settings

mlemes
New user
Posts: 4
Joined: 07 Mar 2017, 18:58

Re: Status of relay switch not maintained after ESP Restart

#11 Post by mlemes » 13 Mar 2017, 17:07

Compile but doesn't work :(

mlemes
New user
Posts: 4
Joined: 07 Mar 2017, 18:58

Re: Status of relay switch not maintained after ESP Restart

#12 Post by mlemes » 13 Mar 2017, 17:09

Compiles but doesn't work :(

teonitro
New user
Posts: 1
Joined: 13 Mar 2017, 23:35

Re: Status of relay switch not maintained after ESP Restart

#13 Post by teonitro » 13 Mar 2017, 23:45

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,

mcteusz
New user
Posts: 7
Joined: 07 Mar 2017, 13:53

Re: Status of relay switch not maintained after ESP Restart

#14 Post by mcteusz » 14 Mar 2017, 11:09

My code looks like that:

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));
          }
        }
and it works. But one condition: no devices configured in "Devices" menu. When I set Switch input device, saving states wasn't working properly.

Hollako
New user
Posts: 3
Joined: 22 Oct 2017, 19:26

Re: Status of relay switch not maintained after ESP Restart

#15 Post by Hollako » 23 Oct 2017, 08:48

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,

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Status of relay switch not maintained after ESP Restart

#16 Post by toffel969 » 23 Oct 2017, 18:35

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
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Status of relay switch not maintained after ESP Restart

#17 Post by toffel969 » 23 Oct 2017, 18:41

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

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests