OpenSprinkler / OpenSprinkler-Firmware

OpenSprinkler Unified Firmware for OpenSprinkler, OpenSprinkler Pi, and OpenSprinkler Beagle.
http://www.opensprinkler.com
GNU General Public License v3.0
473 stars 284 forks source link

[Feature Request] Add support for ESP-01 controlled relay modules. #195

Closed GregFrost closed 1 year ago

GregFrost commented 2 years ago

I have been able to get the OpenSprinkler firmware (with some modifications) to work on an ESP-01 controlled relay board like the ones shown at these links: AliExpress Link Amazon Link

The trick with these boards is that the relay is controlled by sending a 4 byte binary code on the serial line 115200/8/n/1 from the ESP module (there is another non-reprogrammable MCU on the board that listens to the serial commands and controls the relays). e.g to turn on relay 1 on you send the 4 byte hex code a0, 01, 01, a2. To turn it off you send a0, 01, 00, a1 (so it looks like the first byte a0 is a delimiter, then the second byte is the relay number, the third is on or off, and the last byte is a checksum).

I have also found that I need to add a 20msec delay between controlling different relays for them to reliably switch.

There are many other boards like this, with differing numbers of relays (I have seen single channel relays and 2 channel relay boards).

With these boards, all you likely need to add is a full bridge rectifier with a buck converter to power the board from the solenoid 24V relay line, and you have a very inexpensive headless WIFI sprinkler controller (no display or buttons, you need to rely on the phone/browser interface).

I would love it if support for this type of board could be added to OpenSprinkler. I got mine working by hacking the switching logic for the RF station type in OpenSprinkler::switch_rfstation to send the appropriate serial command. To do it properly, you would have to add a new station type (perhaps named Serial Binary, or something like that), where you specified the binary sequence to send to turn the relay on and the sequence to turn it off. That would require updates to the ui code which is out of my league (hence I only co-opted the RF station type in my copy of the code).

Is this something that you would consider adding?

PS: the forum seems to be broken, as that may have been a more appropriate place to post this, but whenever I am logged in, the forum links give me Page Not Found error, preventing me from being able to post.

GregFrost commented 2 years ago

See it working here: https://www.reddit.com/r/functionalprint/comments/rrtfod/inexpensive_wifi_sprinkler_controller/

GregFrost commented 2 years ago

PS: the hack I did to get this working is in this fork: https://github.com/GregFrost/OpenSprinkler-Firmware

garudaonekh commented 2 years ago

Great! Have you tried this with 8 relay board? By the way, how stable is it?

I never tried with ESP-01, I have used ESP32. I keep the ESP32 running for more than 3 weeks without any problem(However, i don't attached any relay to it yet, just the board).

garudaonekh commented 2 years ago

Can you clarify the part on the Sprinkler App to make it work with your ESP01 board? Which station type to use?

GregFrost commented 2 years ago

Can you clarify the part on the Sprinkler App to make it work with your ESP01 board?

See the fork I posted.

Which station type to use?

RF with the code set to the relay number (single digit). You also need to set the station delay to 5 seconds to space out the commands to the relays.

garudaonekh commented 2 years ago

ok,how many PINs left? Can this work with ESP01 8 relay?

GregFrost commented 2 years ago

ok,how many PINs left? Can this work with ESP01 8 relay?

The relays switch based on sequences sent on the serial connection, so if the 8 relay board works the same way (which it probably does?) then it would still work with the esp-01.

amiseh commented 2 years ago

Dear GregFrost,

during whole day I'm trying to make Your fork working with my LC Technology 4 channel relay board. unfortunately without any success :( it doesn't work for me :(

can You tell me what should I put in RF station type to make it working??

on tasmota I have to configure it like below to allow tamosta to work becuase without the belows configuration it is not turning on and off the relays on the LC board...

can You tell me where You have done any changes/this hack to make LC board (with esp8266 module) work with serial connection??

on System#Boot do Backlog Baudrate 115200; SerialSend5 0 endon on Power1#State=1 do SerialSend5 A00101A2 endon on Power1#State=0 do SerialSend5 A00100A1 endon on Power2#State=1 do SerialSend5 A00201A3 endon on Power2#State=0 do SerialSend5 A00200A2 endon on Power3#State=1 do SerialSend5 A00301A4 endon on Power3#State=0 do SerialSend5 A00300A3 endon on Power4#State=1 do SerialSend5 A00401A5 endon on Power4#State=0 do SerialSend5 A00400A4 endon

THANK YOU in advance for any feedback, help and suggestions.

GregFrost commented 2 years ago

Dear GregFrost,

during whole day I'm trying to make Your fork working with my LC Technology 4 channel relay board. unfortunately without any success :( it doesn't work for me :(

can You tell me what should I put in RF station type to make it working??

If you have burnt my fork to the ESP-01, then when configuring the RF ID for the station, set it to the single digit relay number that you want to switch

on tasmota I have to configure it like below to allow tamosta to work becuase without the belows configuration it is not turning on and off the relays on the LC board...

can You tell me where You have done any changes/this hack to make LC board (with esp8266 module) work with serial connection??

You need to use my fork of OpenSprinkler which has adapted the RF station type to control the LC board relay.

amiseh commented 2 years ago

@GregFrost THX a lot for Your fork and Your "hack" in switch_rfstation function. just have found everything and right now everything works as expected.

THX a lot!

rayshobby commented 1 year ago

Thank you for creating the fork and make the firmware work with the relay module. I am not sure whether we should include this feature in the official firmware, because the changes are quite specific to the particular 4-channel relay module. I am closing this request for now. Your fork can serve as a reference point for anyone who wants to use the same relay module.

By the way, I took a look at your fork and noticed you mentioned SPIFFS and ESP8266 core 3.0.2. While preparing OpenSprinkler firmware 2.2.0, I encountered a similar issue and therefore have to change to use LittleFS. SPIFFS is deprecated in core 3.0.2 so moving forwards LittleFS would be the standard file system.