Serial MCU controlled relay/switch

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#31 Post by enesbcs » 27 Sep 2017, 21:50

cmcooper123 wrote: 26 Sep 2017, 20:33 I thought about serial logging as well but I think the problem is to do with the relay not the ESP,
because it didn't always turn on the first time when I sent the command from my computer using serial and also when I was using different firmware,
but with firmware you sent it seems to work every time.
Also I didn't need to have the "Enable Serial port" option enabled for it to function.
Thanks for this, hopefully these additions will be merged to the git. :D
Thank you for testing it, i've uploaded the source to github.
Just noticed that the P165 plugin found it's way to the official ESPEasyPluginPlayground thanx to psy0rz. :) I started a new pull request.

Mattley30
New user
Posts: 4
Joined: 04 Oct 2017, 17:41

Re: Serial MCU controlled relay/switch

#32 Post by Mattley30 » 04 Oct 2017, 18:00

Hi enesbcs
Congratulations on your job, I used your plugin successfully with domoticz. Now I have trouble with the rules for 4/5 days that I'm doing tests but not successful so I wanted to write to you.
My project as I think others is to use the Sonoff Dual for the blinds, and make sure that when I turn on relay0 the relay1 is turned off, and when I get the relay1, the relay0 is turned off, using pin “Button 0” and “Button1” present on the Sonoff dual.
I tried different rules and this seemed to me the simplest and most logical but it does not work:

on sonoff#relay0 do
if [sonoff#relay0]=1
relay1,0
endif
endon

on sonoff#relay1 do
if [sonoff#relay1]=1
relay0,0
endif
endon

Could you give me some help?

Thanks
P.s. Sorry for my english

Mattley30

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#33 Post by enesbcs » 04 Oct 2017, 20:44

Mattley30 wrote: 04 Oct 2017, 18:00 Hi enesbcs
Congratulations on your job, I used your plugin successfully with domoticz. Now I have trouble with the rules for 4/5 days that I'm doing tests but not successful so I wanted to write to you.
My project as I think others is to use the Sonoff Dual for the blinds, and make sure that when I turn on relay0 the relay1 is turned off, and when I get the relay1, the relay0 is turned off, using pin “Button 0” and “Button1” present on the Sonoff dual.
I tried different rules and this seemed to me the simplest and most logical but it does not work:

on sonoff#relay0 do
if [sonoff#relay0]=1
relay1,0
endif
endon

on sonoff#relay1 do
if [sonoff#relay1]=1
relay0,0
endif
endon

Could you give me some help?

Thanks
P.s. Sorry for my english

Mattley30
Thanx! Your english is at least as understandable as mine. Currently my Dual is in a box somewhere, but i will do my best to search it and try at the weekend. :) Can you try the following?
//
On sonoff#relay0=1 do
relay,1,0
Endon

On sonoff#relay1=1 do
relay,0,0
Endon
//

If it is not working i can implement an exluding working mode for blinds to the Dual, that can be choosed in the plugin options.. in that mode, switching on a relay will automatically switch off the other one instantly.
When the rules method used, i think there will always be a little time, when both relays states are ON before the other one go OFF.

Mattley30
New user
Posts: 4
Joined: 04 Oct 2017, 17:41

Re: Serial MCU controlled relay/switch

#34 Post by Mattley30 » 05 Oct 2017, 14:44

hi
I did a test with the rules you wrote in your post, but it does not work, it does not switch relay0,1 and relay1,0, I even noticed that with this rule when the Button0 or the Button1 is active the dual janeff crashes and after a few seconds restarts.

The solution to include in your plugin the possibility of using dual with the blinds seems great, if you can be of assistance i have done tests on domoticz using the actions to turn off the switch between one relay and the other 1 second time between switching off and on is a good delay.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#35 Post by enesbcs » 05 Oct 2017, 19:40

Mattley30 wrote: 05 Oct 2017, 14:44 it does not switch relay0,1 and relay1,0, I even noticed that with this rule when the Button0 or the Button1 is active the dual janeff crashes and after a few seconds restarts.
relay1,0 is not a command
relay1,0, is not a command
relay,1,0 is a command

Are you sure that you are using it correctly?

Anyway the implementation of exclusive mode is not so complicated i will try it at the weekend.

Mattley30
New user
Posts: 4
Joined: 04 Oct 2017, 17:41

Re: Serial MCU controlled relay/switch

#36 Post by Mattley30 » 06 Oct 2017, 08:13

enesbcs wrote: 05 Oct 2017, 19:40
Mattley30 wrote: 05 Oct 2017, 14:44 it does not switch relay0,1 and relay1,0, I even noticed that with this rule when the Button0 or the Button1 is active the dual janeff crashes and after a few seconds restarts.
relay1,0 is not a command
relay1,0, is not a command
relay,1,0 is a command

Are you sure that you are using it correctly?

Anyway the implementation of exclusive mode is not so complicated i will try it at the weekend.
the commands I used are relay,0,1 etc.
I made a copy and paste the rules you wrote in your previous post. :P

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#37 Post by enesbcs » 07 Oct 2017, 09:56

Mattley30 wrote: 06 Oct 2017, 08:13 the commands I used are relay,0,1 etc.
I made a copy and paste the rules you wrote in your previous post. :P
Now i understand the problem. This plugin has 3 return value, and everytime when either is changing returns all three value... so if the first relay is on, and the second is also on there were a little endless loop, after little fixing now only the first rule runs, second never fired.. so i do not think that it can be done with rules - easily.

Anyway i implemented blinds mode directly in the plugin, tested with my Dual, it works.

Also fixed the button0 and button1 support (panel pins) and the third relay "Relay2" now holds the value of the WiFi on-board button of the Dual. This button do nothing alone (no relay behind), but can be used in rules, also thinking to implement in the plugin such as "Relay0 ON/OFF", "Relay1 ON/OFF", "Relay0+1 ON/OFF" functions.. look forward to the ideas. :)

Tested with every possible scenario that crossed my mind.. currently there are no delay in case of switching, please let me know it it is needed.
Last edited by enesbcs on 07 Oct 2017, 14:22, edited 1 time in total.

Mattley30
New user
Posts: 4
Joined: 04 Oct 2017, 17:41

Re: Serial MCU controlled relay/switch

#38 Post by Mattley30 » 07 Oct 2017, 12:58

Hi,
Your new plugin with the solution to include the blinds works fine. In fact with this solution there is not even a need to put a delay time between one switch and the other because the communications with domoticz work well and the blind engine has no problems.
Congratulations still on your job, I think other people will use it well.
Now I do other tests with actions on domoticz for up, down and stop.

papperone
Normal user
Posts: 497
Joined: 04 Oct 2016, 23:16

Re: Serial MCU controlled relay/switch

#39 Post by papperone » 07 Oct 2017, 13:36

I think this idea of dual relays control for blinds should be implemented in a more generic plugin.
Like you can select the output (SonoffDual, or 2 GPIOs controlling to normal relays) and have all the logic applied when UP/DOWN (or left/right in case of curtains!) commands are sent to it.
We can call this "Blind Control" plugin... :D

PS: I do not have personally any automated blinds as I dont' have actually blinds in my house.... But my wife has always asked me to automate our curtains (and the logic should be similar).
My TINDIE Store where you can find all ESP8266 boards I manufacture --> https://www.tindie.com/stores/GiovanniCas/
My Wiki Project page with self-made PCB/devices --> https://www.letscontrolit.com/wiki/inde ... :Papperone

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#40 Post by enesbcs » 07 Oct 2017, 14:14

Mattley30 wrote: 07 Oct 2017, 12:58 Hi,
Your new plugin with the solution to include the blinds works fine. In fact with this solution there is not even a need to put a delay time between one switch and the other because the communications with domoticz work well and the blind engine has no problems.
Congratulations still on your job, I think other people will use it well.
Now I do other tests with actions on domoticz for up, down and stop.
Thank you for testing! Binary attached to first post of this thread, source code uploaded to github!
Last edited by enesbcs on 07 Oct 2017, 14:23, edited 1 time in total.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#41 Post by enesbcs » 07 Oct 2017, 14:16

papperone wrote: 07 Oct 2017, 13:36 I think this idea of dual relays control for blinds should be implemented in a more generic plugin.
Like you can select the output (SonoffDual, or 2 GPIOs controlling to normal relays) and have all the logic applied when UP/DOWN (or left/right in case of curtains!) commands are sent to it.
We can call this "Blind Control" plugin... :D

PS: I do not have personally any automated blinds as I dont' have actually blinds in my house.... But my wife has always asked me to automate our curtains (and the logic should be similar).
Currently i have no blinds at all, but not a bad idea. Anyway the source code is uploaded to github. :)

papperone
Normal user
Posts: 497
Joined: 04 Oct 2016, 23:16

Re: Serial MCU controlled relay/switch

#42 Post by papperone » 08 Oct 2017, 12:41

@enesbcs: watch out that your plugin cannot work properly in all conditions due to limitation design of ESPEasy PLUGIN_WRITE call.
Basically while executing PLUGIN_WRITE you have 2 limits:
1) only first device of the same "plugin type" will execute the commands sent (in this case not relevant as it makes no sense to define more than one :) )
2) when PLUGIN_WRITE is called the EventStruc of the device is not passed interely so you cannot be sure you can access the right Device parameters :(
To test point 2 you can define something as device 1, then setup P165 as device 2, and play a round and you will see a loooooot of issues when sending commands (PLUG_WRITE) :o
It shoudl be as well sufficient while device works to reboot the ESP and try to send commands without doing anythign else before and commands wont' be executed most probably...
My TINDIE Store where you can find all ESP8266 boards I manufacture --> https://www.tindie.com/stores/GiovanniCas/
My Wiki Project page with self-made PCB/devices --> https://www.letscontrolit.com/wiki/inde ... :Papperone

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#43 Post by enesbcs » 09 Oct 2017, 19:24

papperone wrote: 08 Oct 2017, 12:41 @enesbcs: watch out that your plugin cannot work properly in all conditions due to limitation design of ESPEasy PLUGIN_WRITE call.
Basically while executing PLUGIN_WRITE you have 2 limits:
1) only first device of the same "plugin type" will execute the commands sent (in this case not relevant as it makes no sense to define more than one :) )
2) when PLUGIN_WRITE is called the EventStruc of the device is not passed interely so you cannot be sure you can access the right Device parameters :(
To test point 2 you can define something as device 1, then setup P165 as device 2, and play a round and you will see a loooooot of issues when sending commands (PLUG_WRITE) :o
It shoudl be as well sufficient while device works to reboot the ESP and try to send commands without doing anythign else before and commands wont' be executed most probably...
On point 1: I see, but P165 is made for specific devices, that hardwired to hardware UART, i can not think any real world scenario, when two of the P165 plugin will be necessery on the same physical device, on the same time. In fact, if there are any method to disable multiple usage of the plugin, i will do it. :)

On point 2: it can be a problem, i tought that Eventstruct *event is declared in global scope, so i do not expect any problem.. thank you for pointing to it, i think i fixed it with global variables - ugly but works- tested with sonoff dual 165 as second device. Binaries updated in first post.
https://github.com/enesbcs/ESPEasyPlugi ... Switch.ino

papperone
Normal user
Posts: 497
Joined: 04 Oct 2016, 23:16

Re: Serial MCU controlled relay/switch

#44 Post by papperone » 09 Oct 2017, 21:07

Thanks to the "God" of ESPEasy we have a neat solution here --> https://github.com/letscontrolit/ESPEas ... -335028103
So defintely it's not a blocking limit, just required a bit of code to access proper device parameters specially useful when you could have more than one device of the same plugin (not your case thou)...
My TINDIE Store where you can find all ESP8266 boards I manufacture --> https://www.tindie.com/stores/GiovanniCas/
My Wiki Project page with self-made PCB/devices --> https://www.letscontrolit.com/wiki/inde ... :Papperone

mcfarlde
New user
Posts: 1
Joined: 20 Oct 2017, 13:05

Re: Serial MCU controlled relay/switch

#45 Post by mcfarlde » 20 Oct 2017, 13:09

Can you share the binary, I have the same boards.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#46 Post by enesbcs » 20 Oct 2017, 19:11

mcfarlde wrote: 20 Oct 2017, 13:09 Can you share the binary, I have the same boards.
Yes of course, the binary is always being uploaded to the first post of this thread, and the source is uploaded to the github.
download/file.php?id=1581

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#47 Post by enesbcs » 17 Nov 2017, 10:55

I've compiled the binary against ESP8266 Arduino Core 2.4.0 rc2, attached to the first post of this thread:
download/file.php?id=1715

saundersrg
New user
Posts: 5
Joined: 13 Dec 2017, 10:18

Re: Serial MCU controlled relay/switch

#48 Post by saundersrg » 13 Dec 2017, 13:26

Perhaps I've missed the boat completely, but been tearing my hair out with a Sonoff Dual V2.0. Between ESPEasy, ESPurna, and Tasmota, none of them work. Other people seem to be having the same issue on other forums.

I don't know if maybe its a slight difference in the boards, but I just cannot get the relays to fire no matter what I do. Anyone else seeing this issue?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Serial MCU controlled relay/switch

#49 Post by grovkillen » 13 Dec 2017, 13:34

saundersrg wrote: 13 Dec 2017, 13:26 Perhaps I've missed the boat completely, but been tearing my hair out with a Sonoff Dual V2.0. Between ESPEasy, ESPurna, and Tasmota, none of them work. Other people seem to be having the same issue on other forums.

I don't know if maybe its a slight difference in the boards, but I just cannot get the relays to fire no matter what I do. Anyone else seeing this issue?
If you take a picture of the board we might see if the ESP MCU is doing the actual pulling of the relay or if they (itead) has started to put in a middle hand MCU which is controlled via the ESP MCU.

EDIT: sorry, I see that it is in fact discussed in this thread. It i a serial controlled MCU. So how are you trying to make the relay trigger? Using serial commands?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#50 Post by enesbcs » 13 Dec 2017, 17:16

saundersrg wrote: 13 Dec 2017, 13:26 Perhaps I've missed the boat completely, but been tearing my hair out with a Sonoff Dual V2.0. Between ESPEasy, ESPurna, and Tasmota, none of them work. Other people seem to be having the same issue on other forums.

I don't know if maybe its a slight difference in the boards, but I just cannot get the relays to fire no matter what I do. Anyone else seeing this issue?
If you have a Sonoff Dual R2 there are no more MCU, relays are directly attached to 8285 GPIO, you have to choose R2 modell in Tasmota, or use GPIO directly in ESPEasy
https://github.com/arendst/Sonoff-Tasmo ... nd-Dual-R2

If you have an old Sonoff Dual, then please read the first post of this thread, and use the binary attached to it. If it is not working for some reason and this board is definitely is not an R2, then you can test with ESPEasy+SER2NET plugin the serial status messages, that this board reply when you short the onboard button0 and button1 pins.

saundersrg
New user
Posts: 5
Joined: 13 Dec 2017, 10:18

Re: Serial MCU controlled relay/switch

#51 Post by saundersrg » 16 Dec 2017, 06:35

enesbcs wrote: 13 Dec 2017, 17:16
If you have a Sonoff Dual R2 there are no more MCU, relays are directly attached to 8285 GPIO, you have to choose R2 modell in Tasmota, or use GPIO directly in ESPEasy
https://github.com/arendst/Sonoff-Tasmo ... nd-Dual-R2

If you have an old Sonoff Dual, then please read the first post of this thread, and use the binary attached to it. If it is not working for some reason and this board is definitely is not an R2, then you can test with ESPEasy+SER2NET plugin the serial status messages, that this board reply when you short the onboard button0 and button1 pins.
[/quote]

Well, from what I've seen it's a V2 not R2. Compiled the binary into Dev 11, no luck. Will try out SER2NET in the next couple of days. Thanks!

saundersrg
New user
Posts: 5
Joined: 13 Dec 2017, 10:18

Re: Serial MCU controlled relay/switch

#52 Post by saundersrg » 16 Dec 2017, 06:37

grovkillen wrote: 13 Dec 2017, 13:34
If you take a picture of the board we might see if the ESP MCU is doing the actual pulling of the relay or if they (itead) has started to put in a middle hand MCU which is controlled via the ESP MCU.

EDIT: sorry, I see that it is in fact discussed in this thread. It i a serial controlled MCU. So how are you trying to make the relay trigger? Using serial commands?
Not able to trigger at all, it's like the relays are disconnected entirely. Have tried 3 different firmwares and none work.

Will try the suggestion of SER2NET and see what I can get.

saundersrg
New user
Posts: 5
Joined: 13 Dec 2017, 10:18

Re: Serial MCU controlled relay/switch

#53 Post by saundersrg » 16 Dec 2017, 07:39

saundersrg wrote: 16 Dec 2017, 06:35
Well, from what I've seen it's a V2 not R2. Compiled the binary into Dev 11, no luck. Will try out SER2NET in the next couple of days. Thanks!
SER2NET sadly returns absolutely nothing. The LED changes on the unit when closing button 0 / 1 jumpers, but the relays themselves don't seem to fire.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#54 Post by enesbcs » 16 Dec 2017, 09:50

saundersrg wrote: 16 Dec 2017, 07:39 SER2NET sadly returns absolutely nothing. The LED changes on the unit when closing button 0 / 1 jumpers, but the relays themselves don't seem to fire.
If the relay do not fire when you physically close button jumpers, i think it is simply a faulty one. :(
Was it worked with the original firmware? I always try every Sonoff that i get with the original firmware, before i flash it. Can you post pictures from the panel (back&front)?

mixycsabi
New user
Posts: 1
Joined: 19 Dec 2017, 11:47

Re: Serial MCU controlled relay/switch

#55 Post by mixycsabi » 19 Dec 2017, 11:49

Same situation here...

[Edit]
Sorry, my mistake... I used wrong bin file.
After when I chose a good file, everything works fine :)

saundersrg
New user
Posts: 5
Joined: 13 Dec 2017, 10:18

Re: Serial MCU controlled relay/switch

#56 Post by saundersrg » 29 Dec 2017, 15:21

enesbcs wrote: 16 Dec 2017, 09:50 If the relay do not fire when you physically close button jumpers, i think it is simply a faulty one. :(
Was it worked with the original firmware? I always try every Sonoff that i get with the original firmware, before i flash it. Can you post pictures from the panel (back&front)?
In a sad twist, the dual was the only one that I a) didn't test beforehand and b) didn't dump the original firmware beforehand.

I will perhaps fiddle again sometime, for now it's been packed in a box.

Images here:

Image
Image
Image
Image

Chips to right of ESP8266EX are as follows from what I can see.

XTX
BN25F08
1(?)644Q0R

SIL
F330
B0GAZ
1624+

itanczos
New user
Posts: 4
Joined: 25 Jan 2018, 00:05

Re: Serial MCU controlled relay/switch

#57 Post by itanczos » 25 Jan 2018, 12:24

Hello nesbcs!

Is it possible to use button1 or button2 input for pulse counting? Or is it possible to count impulse with Sonoff Dual?

(Van arra lehetőség, hogy a 2 gomb bemenetet figyeljük és impulzus számlálásra használjuk? Vagy egyéb más lehetőség Sonoff Dual-lal? A lefordított binárisban benne van az impulzus számláló plugin?)

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#58 Post by enesbcs » 25 Jan 2018, 18:47

itanczos wrote: 25 Jan 2018, 12:24 Hello nesbcs!

Is it possible to use button1 or button2 input for pulse counting? Or is it possible to count impulse with Sonoff Dual?

(Van arra lehetőség, hogy a 2 gomb bemenetet figyeljük és impulzus számlálásra használjuk? Vagy egyéb más lehetőség Sonoff Dual-lal? A lefordított binárisban benne van az impulzus számláló plugin?)
I am not familiar with the P003 Pulse plugin, however, it is compiled in the binary. If P003 is not watching GPIO's but device variables, it can work... but because the serial communication, i doubt that it will be fast.

riker1
Normal user
Posts: 344
Joined: 26 Dec 2017, 18:02

Re: Serial MCU controlled relay/switch

#59 Post by riker1 » 28 Jan 2018, 15:31

@enesbcs,

just to let you knwo lc tech is also available with 2 relais

http://www.chinalctech.com/index.php?_m ... &p_id=1261

mabye you can update your plugin to support 2 releais.

Thanks T

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#60 Post by enesbcs » 28 Jan 2018, 21:17

riker1 wrote: 28 Jan 2018, 15:31 @enesbcs,
just to let you knwo lc tech is also available with 2 relais

http://www.chinalctech.com/index.php?_m ... &p_id=1261

mabye you can update your plugin to support 2 releais.
Thanks T
Good to know, LCTECH 2 relay support added, i compiled binaries for ESPEasy Mega, R147 and R120 for testing, attached to this post.

riker1
Normal user
Posts: 344
Joined: 26 Dec 2017, 18:02

Re: Serial MCU controlled relay/switch

#61 Post by riker1 » 29 Jan 2018, 07:57

perfect thanks
will try to test

riker1
Normal user
Posts: 344
Joined: 26 Dec 2017, 18:02

Re: Serial MCU controlled relay/switch

#62 Post by riker1 » 29 Jan 2018, 15:18

Hi
I tried the R147 but did not manage to switch the relay.

as there are 3 relays , I assume only first 2 are mapped to LCTech .

but cmd=relay,0,1 does not switch anything.

any way to monitor debug this?

if I http://192.168.0.143/control?cmd=relay,1,1 then in relay1 in device overview it is not reflected. relay1 is still 0
it is only working for relay0, showing 1 , after switching. (but not the relay itself).

how do serial definition interact?

maybe it should be good to have a variable baud rate also in the plugin.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#63 Post by enesbcs » 29 Jan 2018, 19:47

riker1 wrote: 29 Jan 2018, 15:18 Hi
I tried the R147 but did not manage to switch the relay.

as there are 3 relays , I assume only first 2 are mapped to LCTech .

but cmd=relay,0,1 does not switch anything.

any way to monitor debug this?

if I http://192.168.0.143/control?cmd=relay,1,1 then in relay1 in device overview it is not reflected. relay1 is still 0
it is only working for relay0, showing 1 , after switching. (but not the relay itself).

how do serial definition interact?

maybe it should be good to have a variable baud rate also in the plugin.
You can see the ESPEasy log about details.

Th plugin sends the following commands:
relay,0,1 = A0 01 01 A2
relay,0,0 = A0 01 00 A1
relay,1,1 = A0 02 01 A3
relay,1,0 = A0 02 00 A2

In the documentation, i found 115200 as the recommended speed. It is weird, it was 9600 in the one relay version. Now i made the speed selectable in the plugin.
New test version attached to this post. I made some nasty mistakes in the previous binary, as this plugin created for ESP Mega WEBFORM LOAD/SAVE versions originally. I think i corrected it, sorry.
Last edited by enesbcs on 30 Jan 2018, 19:09, edited 1 time in total.

riker1
Normal user
Posts: 344
Joined: 26 Dec 2017, 18:02

Re: Serial MCU controlled relay/switch

#64 Post by riker1 » 30 Jan 2018, 08:37

Hi

thanks a lot for the fast support.

a lot of progress.

Now I can switch relay with 115200 baut.

Problem is:
relais open and close directly with command relay,0,1 : open and immediate close after half a second without any command.

Do you have and idea?

Thanks a lot

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#65 Post by enesbcs » 30 Jan 2018, 19:19

riker1 wrote: 30 Jan 2018, 08:37 Problem is:
relais open and close directly with command relay,0,1 : open and immediate close after half a second without any command.

Do you have and idea?
The LCTECH 1 relay version is reported to be veery slow, so i send every on and off command twice, this worked until now. It seems that this 2relay version is faster, and maybe does not tolerate multiple ON commands? Anyway i compiled a new binary with a new option "Use command doubling". (attached) Please make sure to set it off, and reboot the ESP if needed. In the ESPEasy Tools->Log menu you can see the sent commands.
I have no more idea at software level.

On hardware side:
The device has a chinese documentation, describing the S1 and S2 buttons, and below that some text says - according to Google Translator - that Mode2 is the phone mode, when these serial commands can be executed. Also this panel has some undocumented jumpers...
This LCTech 2 relay module is a strange thing, the original Itead module have a button that can choose between inching/self-lock mode:
https://www.itead.cc/inching-self-locki ... witch.html

riker1
Normal user
Posts: 344
Joined: 26 Dec 2017, 18:02

Re: Serial MCU controlled relay/switch

#66 Post by riker1 » 30 Jan 2018, 20:01

Hi
I tested it, but not really a difference.

I tried mode 1 and 2 , no change

same with the jumper, without jumpers, no switching at all.

Vendor is saying: Under normal conditions, the Jumpers should be plug on the board. You'd better unplug the jumpers when you need send AT conmand to debug the ESP8266, the function of the jumpers is avoid the UART disturbance that from STM8S003/N76E003

with AT Firmware ,
switching : echo -e '\xA0\x01\x01\xA2' | nc -q 1 192.168.0.143 8080
the relay persists in position open .

all strange.

Thanks for your help

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#67 Post by enesbcs » 30 Jan 2018, 21:09

riker1 wrote: 30 Jan 2018, 20:01 with AT Firmware ,
switching : echo -e '\xA0\x01\x01\xA2' | nc -q 1 192.168.0.143 8080
the relay persists in position open .

all strange.
Strange indeed.
In ESPEasy under Tools->Advanced, the Enable serial port is unchecked and Serial log level is 0?

There are also a P020 Serial Server plugin in ESPEasy, that you can test directly with nc.

(I am using 2.4.0-rc2 core to compile, so if in my binary the P020 plugin also does not works, than maybe R147 needs to be compiled with 2.3.0)

riker1
Normal user
Posts: 344
Joined: 26 Dec 2017, 18:02

Re: Serial MCU controlled relay/switch

#68 Post by riker1 » 01 Feb 2018, 12:18

Hi
nc is not working with serial server for this relay. Not sure why.

disable command doubling option does not help. relay is closing immediatly.

I follow two approaches:
AT-Firmware
and EspEasy.

Now I recognized that relay is rebooting the ESP (with AT Frimware) after switching a relay. this is not stable.

I think I throw this out of the window. LC Tech is not supporting and relay is instable

Thanks for your work

cheers T

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#69 Post by enesbcs » 01 Feb 2018, 17:39

riker1 wrote: 01 Feb 2018, 12:18 Now I recognized that relay is rebooting the ESP (with AT Frimware) after switching a relay. this is not stable.
It's very sad, i am very curious about new gadgets. :( There were no such errors with the LCTech 1 relay version.. maybe the relays draw to much current + the power supply is not stable enough. Perhaps you can try to apply a 1000uf capacitor between the ESP 3.3V power line and GND to stabilize.
https://iot-playground.com/images/artic ... titled.png

TD-er
Core team member
Posts: 8755
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Serial MCU controlled relay/switch

#70 Post by TD-er » 01 Feb 2018, 19:36

enesbcs wrote: 01 Feb 2018, 17:39
riker1 wrote: 01 Feb 2018, 12:18 Now I recognized that relay is rebooting the ESP (with AT Frimware) after switching a relay. this is not stable.
It's very sad, i am very curious about new gadgets. :( There were no such errors with the LCTech 1 relay version.. maybe the relays draw to much current + the power supply is not stable enough. Perhaps you can try to apply a 1000uf capacitor between the ESP 3.3V power line and GND to stabilize.
https://iot-playground.com/images/artic ... titled.png
Please note that an empty capacitor will draw as much current as it can get.
Depending on the capacity of the capacitor, it may take some time.
So if you're using bigger capacitors, it may very well be you can overload (damage) the power regulator that stabilizes the 3.3V.
Those 3V3 versions are often not the most powerful ones.
When a separate 3V3 line is present, which powers the ESP, you may want to add a small resistor (order of 1 ... 10 Ohm) between the power and the ESP and put such a capacitor directly over the Vcc and GND lines of the ESP.

If the 3V3 comes from an onboard stabilizer, like on a NodeMCU, I would suggest to add the capacitor over de 5V line instead.

riker1
Normal user
Posts: 344
Joined: 26 Dec 2017, 18:02

Re: Serial MCU controlled relay/switch

#71 Post by riker1 » 02 Feb 2018, 08:30

Hi
I am using a b3603 buck converter.
showing esp01 only on 80mA and additional 50 mA for each relay. Power should be stable.

I set input power to 5 V 1 A, when 2 Relay were open, current was 200mA.

Hard to put resistors and capacitator in the relay ESP is onboard plugged on.

maybe it is also possible to control / program the onboard STM8S003 SWIM.

hard to give up....

riker1
Normal user
Posts: 344
Joined: 26 Dec 2017, 18:02

Re: Serial MCU controlled relay/switch

#72 Post by riker1 » 05 Feb 2018, 15:34

Hi
good news,

problem was related to power supply via breadboard.

all working now. Thanks for your support.

will p165 be part of a normal release?

compiling a release myself failed with always different errors....

TD-er
Core team member
Posts: 8755
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Serial MCU controlled relay/switch

#73 Post by TD-er » 05 Feb 2018, 17:08

riker1 wrote: 05 Feb 2018, 15:34 [...]
will p165 be part of a normal release?

compiling a release myself failed with always different errors....
If it is considered stable, you can always make an issue for it on Github.
I think there are lots of plugins on the playground which may benefit others.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#74 Post by enesbcs » 05 Feb 2018, 18:45

TD-er wrote: 05 Feb 2018, 17:08
riker1 wrote: 05 Feb 2018, 15:34 [...]
will p165 be part of a normal release?

compiling a release myself failed with always different errors....
If it is considered stable, you can always make an issue for it on Github.
I think there are lots of plugins on the playground which may benefit others.
Plugin is currently working only with Arduino core 2.4.0-rc or newer, so compilation with default settings is not straightforward. I think the plugin status is better than "DEVELOPMENT", but reported to run out of memory on Sonoff Dual after a month uptime. On my Tuya wall light switch, i have no such problems, but it is moderately used by me. So i guess my plugin falls under "TESTING" category.
The supported 3 type of hardware: Sonoff Dual, Tuya touch light switch and LCTech relays is not typically used as sensors (only a few GPIOs accessible) so i remove a lots of plugin before compiling it, for speed and size reasons.
I think i will offer pre-compiled binaries in 3 versions for users who have problems with compilation:
1. ESPEasy Mega 4MB/1MB SPIFFS
2. ESPEasy Mega 1MB/128k SPIFFS
3. ESPEasy R147 1MB/64k SPIFFS (legacy version for PUYA - SPIFFS not used in this release, but checked by ESPEasy to be greater than 0 for some reasons)

In these binaries i will include the following:
Controllers: All (C001-C011)
Notification plugins: All (N001-N002)
Plugins: P165 SerSwitch, P001 Switch, P002 ADC, P003 Pulse, P020 Ser2Net (for debugging purposes), P021 Level, P026 Sysinfo, P029 Output, P033 Dummy, P037 MQTTImport, P043 ClkOutput (not sure if it can be useful for this devices), and for in case also including my Modemsleep plugin P166 just in case. :)

If anyone has other needs, write it.

riker1
Normal user
Posts: 344
Joined: 26 Dec 2017, 18:02

Re: Serial MCU controlled relay/switch

#75 Post by riker1 » 05 Feb 2018, 19:48

Hi
that sounds great.

one hint maybe.

looks like for lc Tech relays with 2 relays, only statsu of 1. rleay is send to fhem

message is rel:on rel:off

but only for first relay0 not relay1

thanks Thomas

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#76 Post by enesbcs » 05 Feb 2018, 22:24

riker1 wrote: 05 Feb 2018, 19:48 one hint maybe.

looks like for lc Tech relays with 2 relays, only statsu of 1. rleay is send to fhem

message is rel:on rel:off

but only for first relay0 not relay1
Yes from the beginning this device reports itself as SWITCH, and in ESPEasy it can report exactly one value, the first. This is why i am using Rules, to report back each relays separately, as this mentioned in the first post.
To address this issue, now i changed it to SENSOR_TYPE_TRIPLE and tried to change it according the selected number of buttons.
Hint: if selecting the LCTECH type for the first time in the device settings, please refresh the page and Submit another time, after selecting the number of buttons, and other options, to make sure to save it.
Binary attached to the first post of this thread:
download/file.php?id=1930

riker1
Normal user
Posts: 344
Joined: 26 Dec 2017, 18:02

Re: Serial MCU controlled relay/switch

#77 Post by riker1 » 06 Feb 2018, 07:38

Hi

ok top thanks

will try

it is working,
only small thing. relay names must be short to be distinguished in fhem:
fhem is showing Rel: 0 Rel: 0

changed in EasyESP : shorter names : R1: 0 R2: 0 appears in fhem

Thanks

dent
New user
Posts: 8
Joined: 01 Mar 2018, 12:04

Re: Serial MCU controlled relay/switch

#78 Post by dent » 01 Mar 2018, 18:30

Hi!

Thank you very much taking the time to produce this. I admire your work here and greatly appreciate what you accomplished.

I have recently purchased a Tuya clone 1-gang wall switch from aliexpress. I like them since they don’t have any branding in the glass pane like sonoff and their glass cover color matches the case color.

I’ve disassembled the switch, luckily I saw the pins out there with labels on the back.

I am quite new to these things and don’t have any electronics background but have some programming knowledge. I had previously flashed sonoff devices with tasmota with success and have embedded them into my home assistant network running on a raspberry pi 3. On the other hand, I have tried to use your firmware but to no luck. I have listed the steps I have followed below. I will be glad if you can help me figure out how to make it work with the device I have.

1) I connected the ESP8266 module to a raspberry pi 3 running on raspbian in flashing mode. I don’t have a USB-UART device, so I am limited to using linux based solutions for flashing
2) I downloaded the compiled version of your plugin for Tuya
3) I backed up the existing firmware using esptool.py (just in case I need to revert to the original firmware in the future)
4) power cycled, erased the existing firmware
5) power cycled, uploaded the new firmware, namely ESPEasy_Mega_P165_4M_1MS.bin from the zip file in the first post.
6) exited flashing mode (disconnected GPIO0 from ground) and power cycled
7) I was now able to see ESP_XXXX access point available in the wireless networks list. However, when I connected, I was unable to open the webpage on 192.168.4.1. I tried to ping and it worked, but the webpage did not show up
8) Still connected to raspberry pi, I ran miniterm.py to listen to the serial log. See the log output below. Seems like ESP was constantly rebooting itself due to an error (which I cannot figure out) and repeats the same error message continously.
9) I also tested powering the switch from a wall plug instead of raspberry pi, but the results were the same/

Any ideas how I can make this work? Is there something that I am missing?
By the way, the product works fine with the vendor app and other third party software on its original firmware.

Thanks!
ets Jan 8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v4ceabea9
~ld
�U

INIT : Booting version: (custom)
INIT : Warm boot #10
FS : Mounting...
FS : Mount failed
FS : Mount failed
RESET: Resetting factory defaults...
RESET: Warm boot, reset count: 3
RESET: Too many resets, protecting your flash memory (powercycle to solve this)
CRC : No program memory checksum found. Check output of crc2.py
FS : Error while reading/writing config.dat in 1091

PID:0
Version:0
INIT : Incorrect PID or version!
RESET: Resetting factory defaults...
RESET: Warm boot, reset count: 3
RESET: Too many resets, protecting your flash memory (powercycle to solve this)

Exception (0):
epc1=0x4000e25d epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: cont
sp: 3fff3bf0 end: 3fff3e50 offset: 01a0

>>>stack>>>
3fff3d90: 3fff4e8c 00000100 00000001 40201980
3fff3da0: 40202a82 3fff4ebc 00000001 40202b88
3fff3db0: 00000000 0000001c 00000003 3fff4ea4
3fff3dc0: 3fffdad0 3fff2e20 3fff2d60 3fff2e20
3fff3dd0: 3fffdad0 00000001 3fff2d60 4022d0f8
3fff3de0: 00000000 0000001c 00000000 40202932
3fff3df0: 402018b6 3fff2d60 3fff1d48 40207e61
3fff3e00: 3fffdad0 3fff2d60 3fff1d48 402251ac
3fff3e10: 00000000 00000000 00000000 3fff4fc4
3fff3e20: 0000002f 00000014 feefeffe feefeffe
3fff3e30: 3fffdad0 00000000 3fff2e1a 4022ee20
3fff3e40: feefeffe feefeffe 3fff2e30 40100710
<<<stack<<<
Attachments
195B67E3-370A-42C0-B532-D97FD03C7457.png
195B67E3-370A-42C0-B532-D97FD03C7457.png (1.28 MiB) Viewed 74049 times
6610B890-DBB9-4A5F-A952-8EF72A8FB0C8.jpeg
6610B890-DBB9-4A5F-A952-8EF72A8FB0C8.jpeg (1.85 MiB) Viewed 74049 times
4A5207F2-76D4-47AB-AD1D-B18F442E5A62.jpeg
4A5207F2-76D4-47AB-AD1D-B18F442E5A62.jpeg (1.88 MiB) Viewed 74049 times
4176A19F-4944-4F08-9881-667E8E894E1B.jpeg
4176A19F-4944-4F08-9881-667E8E894E1B.jpeg (1.64 MiB) Viewed 74049 times

itanczos
New user
Posts: 4
Joined: 25 Jan 2018, 00:05

Re: Serial MCU controlled relay/switch

#79 Post by itanczos » 01 Mar 2018, 18:57

dent wrote: 01 Mar 2018, 18:30 ...
5) power cycled, uploaded the new firmware, namely ESPEasy_Mega_P165_4M_1MS.bin from the zip file in the first post.
Please try the ESPEasy_Mega_P165_1M_128kS.bin flash image.
I think this ESP module has only 1MB of flash.

itanczos
New user
Posts: 4
Joined: 25 Jan 2018, 00:05

Re: Serial MCU controlled relay/switch

#80 Post by itanczos » 01 Mar 2018, 19:02

I'm using the downloadable P165_18 version.
The problem is that if I restart the router, it will not re-connect the ESPEasy to the router, but switch to the AP mode.
The rest of ESPEasy will re-connect to the router.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 135 guests