Page 6 of 7

Re: Serial MCU controlled relay/switch

Posted: 04 May 2019, 07:33
by Mravko
enesbcs wrote:
04 May 2019, 00:53
Mravko wrote:
03 May 2019, 09:07
1. looking into the following code:

line 681:
I'm interested in the byte "btnnum". What's confusing is this line "Serial.write( (btnnum + 1) ); // relay number 1,2,3"
Are we adding "+ 1" because btnnum = 01 for the first relay?
Yes the Tuya addresses buttons from 1, the plugin addresses EVERYTHING from 0.
Incoming switch numbers decoded at line 426:

Code: Select all

byte btnnum = (serial_buf[6] - 1);
Who has worked with arrays knows why starting from 0 is handy.
Mravko wrote:
03 May 2019, 09:07
I'm wondering if the hex of switch 3 and 4 are not read correctly in the read section. you know 0x00, 0x01, 0x0a and 0x0b.
I'm wondering if a and b are not interpreted correctly when reading.
I don't quite understand your point, it does not matter if you write it in hex or decimal, everything is binary. Byte values arriving from serial which do not need any interpreting.
Mravko wrote:
03 May 2019, 09:07
As I don't really follow the reading of the status, I cant figure out what bytes it's expecting for switch 3 and switch 4?
The same as switch 1 and switch 2 as the packet format is equal. You wont find a difference where there are no difference, this is handled by the case from line 434.
Mravko wrote:
03 May 2019, 09:07
Could the dimmer selection be interfering with the reading?
I noticed it's 8 bytes and I think my logs show that it is sending those valies, so when it is processing 2, 3 and 4 is it expecting dimmer values or switch values?
If you see "SerSW : Dimmer" it does not process anything but execute a sendto() command which may update the device status in MQTT.. but if it bother you, i can hide it.
If you see "SerSW : Dimmer d1:" or "SerSW : Dimmer d2:" in your logs, than yes, it may interfere.
Not for now, I’m ok with it reporting.
In fact, soon I may get some wifi dimmers, from the same series and we can deal with it then. I don’t know what the logs will look like but will let you know when I get them

MM

Re: Serial MCU controlled relay/switch

Posted: 04 May 2019, 10:26
by Bohbe
enesbcs wrote:
04 May 2019, 00:28
Bohbe wrote:
03 May 2019, 21:29
This is my first post in this forum, so bare with me. I went to Aliexpress and got some LCTech 2ch relays. I have a really hard time to get it to work with ESP Easy. I realized that the 2-channel version I got had a Nuvoton N76E003 MCU instedad of the STM.
Url? At the description page the seller usually writes about the usable commands...
I see now that I in the end bought it from Wish (I went around for best price including the ridiculus post import fee in Sweden, Wish has it included)... But it has all the functionality with the LCTech apps and everything, so I believe it's an "original"
enesbcs wrote:
04 May 2019, 00:28
Bohbe wrote:
03 May 2019, 21:29
Relay 1 on : (Hex) 0D 0A 2B 49 50 44 2C 30 2C 34 3A A0 01 01 A2
Relay 1 off: (Hex) 0D 0A 2B 49 50 44 2C 30 2C 34 3A A0 01 00 A1
Relay 2 on : (Hex) 0D 0A 2B 49 50 44 2C 30 2C 34 3A A0 02 01 A3
Relay 2 off: (Hex) 0D 0A 2B 49 50 44 2C 30 2C 34 3A A0 02 00 A2

They have added 11 bytes of the same data, maybe as an address
If you convert "0D 0A 2B 49 50 44 2C 30 2C 34 3A" to ASCII you'll get
"
+IPD,0,4:" which is a simple AT modem command for the ESP (means transfer the following 4 bytes)... the real commands for the MCU seems to be the same as always: A0 01 01 A2, A0 01 00 A1, etc... which is already supported by this plugin.
Thanks for the interpretation of the message! As I said, I'm a hardware guy... :geek: It seems like the ESP original software just is pushing out on the UART what it got from the command over IP, as it is stated in the Espressif guide: https://www.espressif.com/sites/default ... les_en.pdf

And the Nuvoton N76E003 I got is programmed to interpret just that. When reprogram the ESP with ESP Easy it just sends the "correct" command with the 4 bytes, which is not seen as a "correct" command by theN76E003. Is there a simpler way to test this theory with the "Command" tool in the web interface, or do I have to set up a compiler environment and code it?

Re: Serial MCU controlled relay/switch

Posted: 04 May 2019, 16:38
by enesbcs
Bohbe wrote:
04 May 2019, 10:26
And the Nuvoton N76E003 I got is programmed to interpret just that. When reprogram the ESP with ESP Easy it just sends the "correct" command with the 4 bytes, which is not seen as a "correct" command by theN76E003. Is there a simpler way to test this theory with the "Command" tool in the web interface, or do I have to set up a compiler environment and code it?
Debug:
- Enable serial port usage, but disable serial logging, also disable all plugin (P165) and device that using serial pins.
- Setup "Communication - Serial Server" plugin for debugging (port 23, baud 9600, 8n1)
https://www.letscontrolit.com/wiki/index.php/Ser2Net
- install Realterm to your PC, setup for displaying in hexadecimal in Display menu, in Capture write the ESP device IP address and port (23) and set the serial settings that matches with the ESP Ser2Net plugin

As i remember, you can premade a binary file with the necesarry command bytes, and you can send it with Realterm to the Ser2Net for testing purposes.

Re: Serial MCU controlled relay/switch

Posted: 05 May 2019, 19:26
by Bohbe
enesbcs wrote:
04 May 2019, 16:38
Debug:
- Enable serial port usage, but disable serial logging, also disable all plugin (P165) and device that using serial pins.
- Setup "Communication - Serial Server" plugin for debugging (port 23, baud 9600, 8n1)
https://www.letscontrolit.com/wiki/index.php/Ser2Net
- install Realterm to your PC, setup for displaying in hexadecimal in Display menu, in Capture write the ESP device IP address and port (23) and set the serial settings that matches with the ESP Ser2Net plugin

As i remember, you can premade a binary file with the necesarry command bytes, and you can send it with Realterm to the Ser2Net for testing purposes.
Thanks! I have tried to do what you described and ran into two problems:

1. I get 9600 baud rate on the serial port to the MCU and can't find a way to get it to work with 115200, which is the baud rate I communicate with
2. It sends 12 bytes, even though the file is 11 bytes. And the strange thing is that the second byte is the one inserted with "0x00". :? Thank god for a good logic analyzer!

I also realized that serial logging was on originally and thought for a while that that would have interfered with the messaging, but nooo. :cry:

I will work on this more later on, try to figure out what happens. I'm in parallel installing Platformio but haven't a clue right now how to merge in P165 into the rest of the code...

Re: Serial MCU controlled relay/switch

Posted: 07 May 2019, 07:40
by Mravko
Bohbe wrote:
05 May 2019, 19:26
enesbcs wrote:
04 May 2019, 16:38
Debug:
- Enable serial port usage, but disable serial logging, also disable all plugin (P165) and device that using serial pins.
- Setup "Communication - Serial Server" plugin for debugging (port 23, baud 9600, 8n1)
https://www.letscontrolit.com/wiki/index.php/Ser2Net
- install Realterm to your PC, setup for displaying in hexadecimal in Display menu, in Capture write the ESP device IP address and port (23) and set the serial settings that matches with the ESP Ser2Net plugin

As i remember, you can premade a binary file with the necesarry command bytes, and you can send it with Realterm to the Ser2Net for testing purposes.
Thanks! I have tried to do what you described and ran into two problems:

1. I get 9600 baud rate on the serial port to the MCU and can't find a way to get it to work with 115200, which is the baud rate I communicate with
2. It sends 12 bytes, even though the file is 11 bytes. And the strange thing is that the second byte is the one inserted with "0x00". :? Thank god for a good logic analyzer!

I also realized that serial logging was on originally and thought for a while that that would have interfered with the messaging, but nooo. :cry:

I will work on this more later on, try to figure out what happens. I'm in parallel installing Platformio but haven't a clue right now how to merge in P165 into the rest of the code...
I've just gone through that painstaking exercise of setting up PlatformIO and incorporating the plugin. I have worked it out.
basically there are a couple of things you need to do.

1. Add #ifdef USES_P165 to the first line and #endif // USES_P165 the very last line of the plugin. (This should be done to the plugin itself in github but can only be done once the plugin becomes a core plugin).
2. set up custom set of plugins in the define_plugin_sets.h e.g.:
#ifdef PLUGIN_SET_ONLY_TUYA
#ifndef PLUGIN_SET_NONE
#define PLUGIN_SET_NONE
#endif
#ifndef USES_P001
#define USES_P001 // switch input - Switch
#endif
#ifndef USES_P002
#define USES_P002 // Analogue input - internal
#endif
#ifndef USES_P003
#define USES_P003 // Pulse Counter
#endif
#ifndef USES_P020
#define USES_P020 // Communication - Serial Server
#endif
#ifndef USES_P021
#define USES_P021 // Regulator - Level Control
#endif
#ifndef USES_P026
#define USES_P026 // SysInfo
#endif
#ifndef USES_P029
#define USES_P029 // Output - Domoticz MQTT Helper
#endif
#ifndef USES_P033
#define USES_P033 // Dummy Device
#endif
#ifndef USES_P043
#define USES_P043 // Output - Clock
#endif
#ifndef USES_P165
#define USES_P165 // Serial MCU controlled Switch
#endif
#endif

3. define an environment in platformio.ini that calls the set of plugins. e.g.:
; Easy Tuya (1M) device ----------------------
[env:easy_TUYA_1M]
upload_speed = ${common.upload_speed}
monitor_speed = ${common.monitor_speed}
framework = ${common.framework}
platform = ${common.platform}
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
lib_ldf_mode = ${common.lib_ldf_mode}
lib_archive = ${common.lib_archive}
board_upload.maximum_size = ${esp8266_1M.board_upload.maximum_size}
board_build.flash_mode = ${esp8266_1M.board_build.flash_mode}
board = esp01_1m
build_flags = ${esp8266_1M.build_flags} -D PLUGIN_SET_ONLY_TUYA

4. call that environment at the start of platformio.ini:

[platformio]
;env_default = esp32dev
;env_default = dev_ESP8266_4096
env_default = easy_TUYA_1M
;env_default = normal_ESP8266_4096
; ..etc

5. (oh and obviously! :) ) copy the plugin to the src/ directory


..and that's it.

Re: Serial MCU controlled relay/switch

Posted: 07 May 2019, 08:17
by Mravko
Hi enesbcs,

Ok, so I've done some major debugging of the plugin and here are my findings:

Everything in the plugin works great except the reading of the tuya MCU.

rationale: First I have to add a delay to the reading. The plugin will eventually read all four lines. It may take up to 20 minutes for it to stumble across the 3rd and fourth line because, at least in my case, the MCU will pump out the 168 bytes every 5 seconds.

55AA0107000501010001000F55AA0107000502010001001055AA0107000503010001001155AA0107000504010001011355AA0107000807020004000000001C55AA0107000808020004000000001D55AA0107000809020004000000001E55AA010700080A020004000000001F55AA0107000865020004000000047E55AA01070008660200040000844E4D5AA01070008670200040000BEA5DF55AA01070008680200040000097A00

The read function doesn't know where it should start reading, it almost randomly starts reading the byte waiting for 55AA (which works) but I think it only processes one (or a couple of) 55AA at a time (this is what I'm trying to figure out now). Then it'll do another one the next time it reads. It may be any of the 12 sets:
1. 55AA0107000501010001000F
2. 55AA01070005020100010010
3. 55AA01070005030100010011
4. 55AA01070005040100010113
5. 55AA0107000807020004000000001C
6. 55AA0107000808020004000000001D
7. 55AA0107000809020004000000001E
8. 55AA010700080A020004000000001F
9. 55AA0107000865020004000000047E
10. 55AA01070008660200040000844E4D
11. 55AA01070008670200040000BEA5DF
12. 55AA01070008680200040000097A00

Conclusion:
I'm trying to think of a better way to handle the reading of the stream. Perhaps before it just starts reading a stream there should be a check for the start of the stream and not just start reading randomly.
Something like: "Wait for when there is no talk from the MCU" - which means wait for it to finish the last pumping of the stream; Then start reading the new stream and loop through each of the 12 sets. so a for loop that processes each 55AA set.
The first 4 sets will be 12 bytes and the consecutive 8 will be 15 bytes.
Perhaps we don't even care about the length as the loop will start processing when it hits the next 55AA.

I have watched the plugin process it and it does seem like it may start reading the stream randomly (anywhere in the sequence) and eventually it'll process them all but it'll take a hundred goes because it doesn't care where the beginning is, it just starts reading.

Reading the code, I'm not convinced that it reads and parses the whole stream every time. In fact, I am positive that it doesn't as it would change all the states at once. I have gone through the code numerous times and cannot find the logic of processing the whole stream in the classic "for loop" style.
Now, I understand that your Tuya send a streal for a changed state. That may be version "00" but, at least for version "01" of the tuya protocol, it sends the whole stream every 5 seconds.

The other thing I'm going to find out is can the plugin be interrupted by the MCU pumping the stream. i.e. Can the function be interrupt driven? this way, each time the MCU sends data, the function will be called and it can parse the stream.

Mravko...

Re: Serial MCU controlled relay/switch

Posted: 08 May 2019, 16:03
by Mravko
Hi enesbcs,

I've been thinking...

Looking at the code, it seems that in the Read function only ever processes the first 12 or 15 bytes. I don't see that it increments.

First check: if (bytes_read == 0) { // packet start --> check if byte 0 is "0x55"
Second check: if (bytes_read == 1) { // check if packet is valid --> check if byte 1 is "0xAA"

but there are 12 valid packets in my case

second check
if (bytes_read == 12) { // packet start --> check if byte 0 is "0x55"
if (bytes_read == 13) { // check if packet is valid --> check if byte 1 is "0xAA"

third check
if (bytes_read == 25) { // packet start --> check if byte 0 is "0x55"
if (bytes_read == 26) { // check if packet is valid --> check if byte 1 is "0xAA"
...and so on

Then again it only needs to check the first two bytes to determine the validity of the stream, so I'm good with that.

What I cannot follow in the code is when does it ready bytes 12-23, 24-35, 36-47, ....and so on
i.e.
1. 55AA0107000501010001000F 00-11
2. 55AA01070005020100010010 12-23
3. 55AA01070005030100010011 24-35
4. 55AA01070005040100010113 36-47
5. 55AA0107000807020004000000001C 48-62
6. 55AA0107000808020004000000001D 63-77
7. 55AA0107000809020004000000001E 78-92
8. 55AA010700080A020004000000001F 93-107
9. 55AA0107000865020004000000047E 108-122
10. 55AA01070008660200040000844E4D 123-137
11. 55AA01070008670200040000BEA5DF 138-152
12. 55AA01070008680200040000097A00 153-167

Re: Serial MCU controlled relay/switch

Posted: 08 May 2019, 17:33
by enesbcs
Mravko wrote:
08 May 2019, 16:03
third check
if (bytes_read == 25) { // packet start --> check if byte 0 is "0x55"
if (bytes_read == 26) { // check if packet is valid --> check if byte 1 is "0xAA"
You are on a bad track, "bytes_read" will never above 20. As i mentioned before only one package held at a time in the plugin buffer which is rollover on the next package everything else is held on the ESP serial buffer until it.

Re: Serial MCU controlled relay/switch

Posted: 11 May 2019, 22:07
by bkarpe
I got the LC-Tech module working using ESP Easy. As I understand it, the Serial MCU device communicates to the controller via TX. Does anyone know if this device is one-way or two-way? In other words, is the RX pin available? Also, are the GPIO0 and/or GPIO2 pins available? I want to attach a DHT22 to the relay to control a heater for a reptile tank on one relay. A light would be controller by a timer on the second relay.

Re: Serial MCU controlled relay/switch

Posted: 12 May 2019, 22:10
by bkarpe
Also, are the GPIO0 and/or GPIO2 pins available?
I have determined that both GPIO0 and GPIO2 pins are available. I have two devices (BME280 and an OLED) running on I2C (scl=GPIO2, sda=GPIO0), and the relays still work. I expect there would be no problem using a DHT22, but I'd have to give up the I2C interface. I will probably stick with the BME280. I haven't tested the RX pin, but I saw a schematic for the LC-Tech, and it looks like it's connected to the on-board processor.

It's amazing what you can do with a little ESP-01. I have a load of them. My NodeMCUs and Esp-32s seem like overkill.

Re: Serial MCU controlled relay/switch

Posted: 18 May 2019, 20:08
by Bohbe
I've just gone through that painstaking exercise of setting up PlatformIO and incorporating the plugin. I have worked it out.
basically there are a couple of things you need to do.
Mvrako, thanks for helping me out here! Sorry for the silence. One week away from home... I followed your excellent guide, and everything makes sense to me, but I ran in to one problem in the Platformio.ini file when trying to build. It says: "Error: Invalid `platformio.ini`, project configuration file: 'No option 'platform' in section: 'common''"

I can find the option 'platform' in section 'common' but in section 'normal' or other definitions:

[common]
board_build.f_cpu = 80000000L
build_flags = ${debug_flags.build_flags}
build_unflags = -DDEBUG_ESP_PORT
lib_deps = ""
lib_ignore = ESP32_ping, ESP32WebServer, IRremoteESP8266
lib_ldf_mode = chain
lib_archive = false
upload_speed = 115200
framework = arduino
board = esp12e
monitor_speed = 115200
;targets = size, checkprogsize
targets =

[regular_platform]
build_unflags =
build_flags = ${core_2_4_2.build_flags} ${common.build_flags}
platform = ${core_2_4_2.platform}

[beta_platform]
build_unflags =
build_flags = ${core_stage.build_flags} ${common.build_flags} -DARDUINO_ESP8266_RELEASE='"2.6.0-dev"'
platform = ${core_stage.platform}



[normal]
platform = ${regular_platform.platform}
build_flags = ${regular_platform.build_flags}

Are we looking at different Platformio.ini versions or am I stupid? Tried to find out from other builds what to use, but became a bit insecure here... :?

Re: Serial MCU controlled relay/switch

Posted: 18 May 2019, 20:19
by muppet96
Is there any reason that this doesn't work with an LCTECH relay on the latest firmware ESP82xx Core 2_4_2, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3 PUYA support
It works fine on an older version "Core Version: 2_4_0_RC2"
As far as I can see all the settings are the same, compiled on PlatformIO
Thanks.

Re: Serial MCU controlled relay/switch

Posted: 18 May 2019, 21:34
by enesbcs
muppet96 wrote:
18 May 2019, 20:19
Is there any reason that this doesn't work with an LCTECH relay on the latest firmware ESP82xx Core 2_4_2, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3 PUYA support
It works fine on an older version "Core Version: 2_4_0_RC2"
As far as I can see all the settings are the same, compiled on PlatformIO
Thanks.
I guess that the ESP Core 2.4.2 serial library changed, and into a wrong direction...

Re: Serial MCU controlled relay/switch

Posted: 19 May 2019, 17:18
by Bohbe
I guess that the ESP Core 2.4.2 serial library changed, and into a wrong direction...
Ahh, so I need to get back to 2_4_0 as well?

Re: Serial MCU controlled relay/switch

Posted: 20 May 2019, 01:05
by Bohbe
Mvrako, I'm still struggling with Platformio to compile. Getting closer though. I think I have some discrepancies in versions. I get the following Error

Code: Select all

Compiling .pioenvs\easy_TUYA_1M\lib69a\SerialDevices\SensorSerialBuffer.cpp.o

lib\ESPEasySerial\ESPeasySerial_ESP8266.cpp: In member function 'bool ESPeasySerial::hasOverrun()':
lib\ESPEasySerial\ESPeasySerial_ESP8266.cpp:228:21: error: 'class HardwareSerial' has no member named 'hasOverrun'
return getHW()->hasOverrun();
^
lib\ESPEasySerial\ESPeasySerial_ESP8266.cpp: In member function 'bool ESPeasySerial::hasRxError()':
lib\ESPEasySerial\ESPeasySerial_ESP8266.cpp:277:19: error: 'class HardwareSerial' has no member named 'hasRxError'
return getHW()->hasRxError();
^
lib\ESPEasySerial\ESPeasySerial_ESP8266.cpp: In member function 'void ESPeasySerial::startDetectBaudrate()':
lib\ESPEasySerial\ESPeasySerial_ESP8266.cpp:290:12: error: 'class HardwareSerial' has no member named 'startDetectBaudrate'
getHW()->startDetectBaudrate();
^
lib\ESPEasySerial\ESPeasySerial_ESP8266.cpp: In member function 'long unsigned int ESPeasySerial::testBaudrate()':
lib\ESPEasySerial\ESPeasySerial_ESP8266.cpp:301:19: error: 'class HardwareSerial' has no member named 'testBaudrate'
return getHW()->testBaudrate();
^
lib\ESPEasySerial\ESPeasySerial_ESP8266.cpp: In member function 'long unsigned int ESPeasySerial::detectBaudrate(time_t)':
lib\ESPEasySerial\ESPeasySerial_ESP8266.cpp:312:19: error: 'class HardwareSerial' has no member named 'detectBaudrate'
return getHW()->detectBaudrate(timeoutMillis);
^
*** [.pioenvs\easy_TUYA_1M\lib9e9\ESPEasySerial\ESPeasySerial_ESP8266.cpp.o] Error 1
I needed to get the platform defined and currently is 'platform = ${core_2_4_0.platform}', and I have tried several others with no luck. platformio.ini looks like this:

Code: Select all

; Easy Tuya (1M) device ----------------------
[env:easy_TUYA_1M]
upload_speed = ${common.upload_speed}
monitor_speed = ${common.monitor_speed}
framework = ${common.framework}
platform = ${core_2_4_0.platform}
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
lib_ldf_mode = ${common.lib_ldf_mode}
lib_archive = ${common.lib_archive}
board_upload.maximum_size = ${esp8266_1M.board_upload.maximum_size}
board_build.flash_mode = ${esp8266_1M.board_build.flash_mode}
board = ${esp8266_1M.board}
build_flags = ${esp8266_1M.build_flags} -D PLUGIN_SET_ONLY_TUYA
I'm probably doing some mixup with versions, so could you give me a clue what version you used when getting it into Platformio? Or should i use a differnt build environment? Thanks.

Re: Serial MCU controlled relay/switch

Posted: 26 May 2019, 17:10
by Bohbe
I'm probably doing some mixup with versions, so could you give me a clue what version you used when getting it into Platformio? Or should i use a differnt build environment? Thanks.
I gave up... After numerous tries to find out why the HardwareSerial class error in the build failed I also ordered new relays. They worked right out of the box... Thanks for trying to help anyhow!

Re: Serial MCU controlled relay/switch

Posted: 28 May 2019, 17:39
by Farrukh
Hello nygma,

I have the exact hardware as you have. I set up the whole thing as you have explained here and in your youtube video. My ESP module is receiving MQTT messages and changing the relay states on the http page, but the actual relays on the LC Tech board are not changing states.
<a href="https://ibb.co/37dP38s"><img src="https://i.ibb.co/37dP38s/Capture.png" alt="Capture" border="0"></a>

Please help

Re: Serial MCU controlled relay/switch

Posted: 28 May 2019, 18:33
by enesbcs
Farrukh wrote:
28 May 2019, 17:39
... changing the relay states on the http page, but the actual relays on the LC Tech board are not changing states.
Old firmware version, wrong type selected in plugin, weak power supply, not correctly soldered relays on panel?
viewtopic.php?p=34341#p34341

Re: Serial MCU controlled relay/switch

Posted: 29 May 2019, 10:16
by Farrukh
The firmware version is ESPEasy_1M_128kSPIFFS_PUYA.zip as specified in post# 120. The power supply or soldering is not an issue because I checked the functionality of the hardware with EasyTCP first, both relays were switching properly. As per instructions given in post# 138 I updated the firmware and configured ESP Easy. When I inject a command in Node-RED the MQTT message is published, the esp module receives the command, and the http page shows that the relay state has changed but the actual relays on the board are not switching.
It appears as if the esp module is not driving the relays on board, even though the esp module is subscribed/publishing MQTT messages properly.

Re: Serial MCU controlled relay/switch

Posted: 29 May 2019, 11:19
by grovkillen
What type of relay are you using? Many relays need 5V to trigger, the ESP only deliver 3.3V on the GPIO?

Re: Serial MCU controlled relay/switch

Posted: 29 May 2019, 17:47
by enesbcs
Farrukh wrote:
29 May 2019, 10:16
...
It appears as if the esp module is not driving the relays on board, even though the esp module is subscribed/publishing MQTT messages properly.
Please make sure that:
- at ESPEasy Tools-Advanced settings Serial is enabled but serial logging is disabled (level 0)
- the correct LCTECH relay type and button number selected in Serial MCU plugin settings page
- adjust serial speed at this page if it seems that the communication did not work normally (19200 is normal, someday 9600 or i saw similar design that worked with 115200 bps)
- reboot ESP
- go to Tools/Command and execute relay,0,1 command to see if it is working than try to operate it with URL commands:
viewtopic.php?p=16998#p16998

Re: Serial MCU controlled relay/switch

Posted: 29 May 2019, 22:36
by Bohbe
It appears as if the esp module is not driving the relays on board, even though the esp module is subscribed/publishing MQTT messages properly.
Maybe you are experiencing the same problem i had, see viewtopic.php?p=36707#p36707. I checked with the original code that the LC tech relay worked, and sent the longer sequence to the slave, but when reprogramming with ESPEasy the slave did not interpret the shorter 4-byte message at al. Hence no reaction from the relays and still "correct" behaviour from ESPEasy. I checked it with a logic analyzer to verify this as well. I did not get the Platformio to build and gave up and bougth new relays from another vendor that worked. But i still would like to compile a version of ESPEasy to send the longer message... Or reprogram the Nuvoton N76E003 slave MCU.
Otherwise I have three 2-ch "LCTech" realys for sale ;)

Re: Serial MCU controlled relay/switch

Posted: 30 May 2019, 07:11
by enesbcs
Bohbe wrote:
29 May 2019, 22:36
It appears as if the esp module is not driving the relays on board, even though the esp module is subscribed/publishing MQTT messages properly.
Maybe you are experiencing the same problem i had, see viewtopic.php?p=36707#p36707. I checked with the original code that the LC tech relay worked, and sent the longer sequence to the slave, but when reprogramming with ESPEasy the slave did not interpret the shorter 4-byte message at al. Hence no reaction from the relays and still "correct" behaviour from ESPEasy. I checked it with a logic analyzer to verify this as well. I did not get the Platformio to build and gave up and bougth new relays from another vendor that worked. But i still would like to compile a version of ESPEasy to send the longer message... Or reprogram the Nuvoton N76E003 slave MCU.
Otherwise I have three 2-ch "LCTech" realys for sale ;)
If the start of the command packet is always ""0D 0A 2B 49 50 44 2C 30 2C 34 3A" i can integrate it to the plugin through a selectable checkbox like "Send IPD command always"

Re: Serial MCU controlled relay/switch

Posted: 30 May 2019, 11:42
by Farrukh
enesbcs wrote:
29 May 2019, 17:47
Farrukh wrote:
29 May 2019, 10:16
...
It appears as if the esp module is not driving the relays on board, even though the esp module is subscribed/publishing MQTT messages properly.
Please make sure that:
- at ESPEasy Tools-Advanced settings Serial is enabled but serial logging is disabled (level 0)
- the correct LCTECH relay type and button number selected in Serial MCU plugin settings page
- adjust serial speed at this page if it seems that the communication did not work normally (19200 is normal, someday 9600 or i saw similar design that worked with 115200 bps)
- reboot ESP
- go to Tools/Command and execute relay,0,1 command to see if it is working than try to operate it with URL commands:
viewtopic.php?p=16998#p16998
- In advanced settings serial is enabled with baud rate 115200, serial logging is disabled.
- In devices I have selected "Serial MCU controlled switch", the plugin is "LC Tech" and the number of relays is set to 2. Serial speed is set to 115200. I tried 19200 but the problem persists.
- When I execute the command "relay,0,1" the relay state changes from 0 to 1 on the http page. With url command "http://192.168.18.119/control?cmd=relay,0,1" the same thing happens. But the actual relays are still not switching.

Re: Serial MCU controlled relay/switch

Posted: 30 May 2019, 11:45
by Bohbe
enesbcs wrote:
30 May 2019, 07:11
Bohbe wrote:
29 May 2019, 22:36
It appears as if the esp module is not driving the relays on board, even though the esp module is subscribed/publishing MQTT messages properly.
Maybe you are experiencing the same problem i had, see viewtopic.php?p=36707#p36707. I checked with the original code that the LC tech relay worked, and sent the longer sequence to the slave, but when reprogramming with ESPEasy the slave did not interpret the shorter 4-byte message at al. Hence no reaction from the relays and still "correct" behaviour from ESPEasy. I checked it with a logic analyzer to verify this as well. I did not get the Platformio to build and gave up and bougth new relays from another vendor that worked. But i still would like to compile a version of ESPEasy to send the longer message... Or reprogram the Nuvoton N76E003 slave MCU.
Otherwise I have three 2-ch "LCTech" realys for sale ;)
If the start of the command packet is always ""0D 0A 2B 49 50 44 2C 30 2C 34 3A" i can integrate it to the plugin through a selectable checkbox like "Send IPD command always"
THAT would be a big favour enesbcs!!! :) :) :) It seems like there are two communication versions out there. LC Tech original with only 4 byte message and copies (think so since they are little cheaper, but contains the same hardware (visually at least) but different code in the slave CPU, and only on the Nuvoton version so far (Taiwanese mfg of 8051 core MCU)

Re: Serial MCU controlled relay/switch

Posted: 30 May 2019, 20:57
by enesbcs
Bohbe wrote:
30 May 2019, 11:45
enesbcs wrote:
30 May 2019, 07:11
If the start of the command packet is always ""0D 0A 2B 49 50 44 2C 30 2C 34 3A" i can integrate it to the plugin through a selectable checkbox like "Send IPD command always"
THAT would be a big favour enesbcs!!! :) :) :) It seems like there are two communication versions out there. LC Tech original with only 4 byte message and copies (think so since they are little cheaper, but contains the same hardware (visually at least) but different code in the slave CPU, and only on the Nuvoton version so far (Taiwanese mfg of 8051 core MCU)
IPD preamble is now selectable in plugin page.
Farrukh wrote:
30 May 2019, 11:42
- When I execute the command "relay,0,1" the relay state changes from 0 to 1 on the http page. With url command "http://192.168.18.119/control?cmd=relay,0,1" the same thing happens. But the actual relays are still not switching.
This build might also help, if your relay is shipped from the same mis-programmed batch that Bohbe has.
Can you show us where did you bought it?

Re: Serial MCU controlled relay/switch

Posted: 31 May 2019, 20:39
by Bohbe
enesbcs wrote:
30 May 2019, 20:57
Bohbe wrote:
30 May 2019, 11:45
enesbcs wrote:
30 May 2019, 07:11
If the start of the command packet is always ""0D 0A 2B 49 50 44 2C 30 2C 34 3A" i can integrate it to the plugin through a selectable checkbox like "Send IPD command always"
THAT would be a big favour enesbcs!!! :) :) :) It seems like there are two communication versions out there. LC Tech original with only 4 byte message and copies (think so since they are little cheaper, but contains the same hardware (visually at least) but different code in the slave CPU, and only on the Nuvoton version so far (Taiwanese mfg of 8051 core MCU)
IPD preamble is now selectable in plugin page.
Farrukh wrote:
30 May 2019, 11:42
- When I execute the command "relay,0,1" the relay state changes from 0 to 1 on the http page. With url command "http://192.168.18.119/control?cmd=relay,0,1" the same thing happens. But the actual relays are still not switching.
This build might also help, if your relay is shipped from the same mis-programmed batch that Bohbe has.
Can you show us where did you bought it?
Thanks enesbcs! I tested it on the 2-channel switch relays I bought at first. As long as you get the board in the right mode (red led instead of blue) by pressing S2 at powerup the first time it works like a clock now with "IPD preamble" checked !!! Big thanks! Although I now have a lot of automation to do since i have a couple of 2-channel relays extra... ;) But thats a nice problem :) By the way, I bought the first relays on Wish (no import fees for Wish in Sweden), https://www.wish.com/product/5c5164a970e55d550efd5214

Again enesbcs, big thanks for your effort!!!

Re: Serial MCU controlled relay/switch

Posted: 31 May 2019, 21:20
by enesbcs
Bohbe wrote:
31 May 2019, 20:39
Thanks enesbcs! I tested it on the 2-channel switch relays I bought at first. As long as you get the board in the right mode (red led instead of blue) by pressing S2 at powerup the first time it works like a clock now with "IPD preamble" checked !!! Big thanks! Although I now have a lot of automation to do since i have a couple of 2-channel relays extra... ;) But thats a nice problem :) By the way, I bought the first relays on Wish (no import fees for Wish in Sweden), https://www.wish.com/product/5c5164a970e55d550efd5214

Again enesbcs, big thanks for your effort!!!
You are welcome. I am wondering if @Farrukh's device is suffered from the same problem?

Re: Serial MCU controlled relay/switch

Posted: 01 Jun 2019, 12:24
by Farrukh
enesbcs wrote:
31 May 2019, 21:20
Bohbe wrote:
31 May 2019, 20:39
Thanks enesbcs! I tested it on the 2-channel switch relays I bought at first. As long as you get the board in the right mode (red led instead of blue) by pressing S2 at powerup the first time it works like a clock now with "IPD preamble" checked !!! Big thanks! Although I now have a lot of automation to do since i have a couple of 2-channel relays extra... ;) But thats a nice problem :) By the way, I bought the first relays on Wish (no import fees for Wish in Sweden), https://www.wish.com/product/5c5164a970e55d550efd5214

Again enesbcs, big thanks for your effort!!!
You are welcome. I am wondering if @Farrukh's device is suffered from the same problem?
After reading Bohbe post which suggested that the red led should be on instead of the blue one, my relays are switching properly now.
Thank you enesbcs and Bohbe for your help.

Re: Serial MCU controlled relay/switch

Posted: 13 Jun 2019, 14:39
by Mravko
Hi again,

There seems to be at least two areas in the platform that are competing for the hardware serial interrupt.
1. Serial.ino
2. _p165_SerSwitch.ino

both of them are evaluating "while (Serial.available())".

I'm not sure how that is resolved but I suspect Serial.ino has precedence?

Re: Serial MCU controlled relay/switch

Posted: 29 Jun 2019, 12:11
by kallipso.v@gmail.com
Farrukh wrote:
28 May 2019, 17:39
Hello nygma,

I have the exact hardware as you have. I set up the whole thing as you have explained here and in your youtube video. My ESP module is receiving MQTT messages and changing the relay states on the http page, but the actual relays on the LC Tech board are not changing states.
<a href="https://ibb.co/37dP38s"><img src="https://i.ibb.co/37dP38s/Capture.png" alt="Capture" border="0"></a>

Please help
HI
did you find a solution for it? I have the same problem

Re: Serial MCU controlled relay/switch

Posted: 29 Jun 2019, 19:50
by enesbcs
kallipso.v@gmail.com wrote:
29 Jun 2019, 12:11
HI
did you find a solution for it? I have the same problem
Farrukh wrote previously that when the red led is on, than the unit is working. (there are buttons on the unit, press them until the led color changes)

Re: Serial MCU controlled relay/switch

Posted: 30 Jun 2019, 16:25
by kallipso.v@gmail.com
enesbcs wrote:
29 Jun 2019, 19:50
kallipso.v@gmail.com wrote:
29 Jun 2019, 12:11
HI
did you find a solution for it? I have the same problem
Farrukh wrote previously that when the red led is on, than the unit is working. (there are buttons on the unit, press them until the led color changes)
THanks now that works :)

If anybody know, how can I add this switches to home assistant?

Re: Serial MCU controlled relay/switch

Posted: 30 Jun 2019, 19:30
by enesbcs
kallipso.v@gmail.com wrote:
30 Jun 2019, 16:25
If anybody know, how can I add this switches to home assistant?
If you are adding an "OpenHAB MQTT" controller with the proper IP and port settings, and
with the default Controller Subscribe /%sysname%/#
,and your unit name is for example "lctech2x":

Than you can send MQTT messages to
set 1st relay ON: (payload_on)
topic: '/lctech2x/cmd' with message 'relay,0,1'

set 1st relay OFF: (payload_off)
topic: '/lctech2x/cmd' with message 'relay,0,0'
etc...

This needs to be added somehow to the mysterious YAML thing in HA...
https://www.home-assistant.io/components/switch.mqtt/

Re: Serial MCU controlled relay/switch

Posted: 01 Jul 2019, 00:03
by kallipso.v@gmail.com
and what about feedback ?
state_topic:

Re: Serial MCU controlled relay/switch

Posted: 18 Jul 2019, 22:49
by beavis6511
Hello,
I've read all the previous post but I have a problem with my board (https://fr.banggood.com/12V-ESP8266-Dua ... rehouse=CN).
I've tried ESPEasy_R147_1M_64kS.bin and ESPEasy_1M_128kSPIFFS_PUYA.bin, everything is configured well (I think) but when I go to
http://<lctechip>/control?cmd=relay,0,1
http://<lctechip>/control?cmd=relay,1,1
Relays are not activated whereas I can see their state changing in the GUI (Device page). "OK" is displayed in my web browser.

I've tried to boot while holding S2, the D7 LED is now red, the D6 blinks slowly green.

In the log I see:

Code: Select all

"159423 : SerSW : SetSwitch r0:1"
...
"135439 : SerSW : SetSwitch r1:1"
I have a power supply 12V/2A

Thanks for your help ! I'm desperate !

Re: Serial MCU controlled relay/switch

Posted: 19 Jul 2019, 07:06
by enesbcs
beavis6511 wrote:
18 Jul 2019, 22:49
I've tried ESPEasy_R147_1M_64kS.bin and ESPEasy_1M_128kSPIFFS_PUYA.bin, everything is configured well (I think) but when I go to
http://<lctechip>/control?cmd=relay,0,1
http://<lctechip>/control?cmd=relay,1,1
Relays are not activated whereas I can see their state changing in the GUI (Device page). "OK" is displayed in my web browser.

I've tried to boot while holding S2, the D7 LED is now red, the D6 blinks slowly green.

In the log I see:

Code: Select all

"159423 : SerSW : SetSwitch r0:1"
...
"135439 : SerSW : SetSwitch r1:1"
I have a power supply 12V/2A

Thanks for your help ! I'm desperate !
According to the purchase site you provided the commands has to be the same. A0 01...
1. Try using the latest binaries:
download/file.php?id=3878
2. Try to set different baud rates, for example 9600 or 115200 (reboot if needed)
3. Try to enable IPD preamble (this helps only if the mcu firmware is buggy, otherwise disable it)

Re: Serial MCU controlled relay/switch

Posted: 19 Jul 2019, 10:21
by beavis6511
enesbcs wrote:
19 Jul 2019, 07:06
beavis6511 wrote:
18 Jul 2019, 22:49
I've tried ESPEasy_R147_1M_64kS.bin and ESPEasy_1M_128kSPIFFS_PUYA.bin, everything is configured well (I think) but when I go to
http://<lctechip>/control?cmd=relay,0,1
http://<lctechip>/control?cmd=relay,1,1
Relays are not activated whereas I can see their state changing in the GUI (Device page). "OK" is displayed in my web browser.

I've tried to boot while holding S2, the D7 LED is now red, the D6 blinks slowly green.

In the log I see:

Code: Select all

"159423 : SerSW : SetSwitch r0:1"
...
"135439 : SerSW : SetSwitch r1:1"
I have a power supply 12V/2A

Thanks for your help ! I'm desperate !
According to the purchase site you provided the commands has to be the same. A0 01...
1. Try using the latest binaries:
download/file.php?id=3878
2. Try to set different baud rates, for example 9600 or 115200 (reboot if needed)
3. Try to enable IPD preamble (this helps only if the mcu firmware is buggy, otherwise disable it)
So I flashed with ESPEasy_P165.1M_128kS_PUYA.bin, factory reset (from Tools).
It's working now !! thanks ! (115200 bauds, no IPD)

Re: Serial MCU controlled relay/switch

Posted: 19 Jul 2019, 11:49
by chubber
hello, first time post here. Thank you for making the binaries available! So I have a few problems to report.

I happen to have the LCTech (clone) 4x channel relay with PUYA SPIFFS. So I got it up and running working with OpenHAB 2.4. I'm using the relaypulse,[relay_number],[status],[delay] method over MQTT to trigger the garage door and another LCTech module to trigger the alarm.

issue 1:

I'm running into some problems with the firmware on both modules, and it seems that both are unable to recover gracefully when it is forced to reconnect to the Wireless Access Point, or when the MQTT server restarted.

I can verify this after, by connecting to http. On the Main page, the IP: shows as 0.0.0.0 (yet the old IP I'm using to connect still works!) then what follows after a while, http completely stops responding. However the MQTT server keeps getting status updates connected. I am also able to send commands using MQTT, but there is a big delay (or nothing happens) and the response is very slow.

This is what my firmware reports:

Code: Select all

Build		20102 - Mega
Libraries	ESP82xx Core 2_4_0, NONOS SDK 2.1.0(deb1901), LWIP: 2.0.3
GIT version	(custom)
Plugins		11 [Normal]
Build Md5	4d44355f4d44355f4d44355f4d44355f
Build time	Sep 20 2018 20:18:40
Binary filename	ThisIsTheDummyPlaceHolderForTheBinaryFilename64ByteLongFilenames
So I tried to find out if there is a way to reboot the ESP-01 by sending a MQTT command, which I can then monitor by OpenHAB and trigger a reboot. This topic viewtopic.php?t=4029 refers to a task method. This topic https://github.com/letscontrolit/ESPEasy/issues/2338 refers to a rule method. Luckily rules are still available, so maybe I can look into something likes this.

issue 2:

when using the relaypulse method over MQTT, the response returns with "linefeed" + Ok or:

Code: Select all

\nOk
Not the end of the world. Just something I had to work around with in my rules with OpenHAB.

Re: Serial MCU controlled relay/switch

Posted: 19 Jul 2019, 17:09
by enesbcs
chubber wrote:
19 Jul 2019, 11:49
issue 1:
I'm running into some problems with the firmware on both modules, and it seems that both are unable to recover gracefully when it is forced to reconnect to the Wireless Access Point, or when the MQTT server restarted.

I can verify this after, by connecting to http. On the Main page, the IP: shows as 0.0.0.0 (yet the old IP I'm using to connect still works!) then what follows after a while, http completely stops responding. However the MQTT server keeps getting status updates
Could you try ESPEasy_P165_1M128kS.core242.bin from this package? It is using Core 2.4.2 which handles wifi a bit better.
download/file.php?id=3807&sid=9c5b654c7 ... 96d2c5713d
chubber wrote:
19 Jul 2019, 11:49
issue 2:
when using the relaypulse method over MQTT, the response returns with "linefeed" + Ok or:

Code: Select all

\nOk
Not the end of the world. Just something I had to work around with in my rules with OpenHAB.
The plugin replies \nOK regardless of the controller. It is necessary for HTTP based controlling to reply with a non-empty packet. What is the problem with that?

Re: Serial MCU controlled relay/switch

Posted: 20 Jul 2019, 16:44
by chubber
enesbcs wrote:
19 Jul 2019, 17:09
Could you try ESPEasy_P165_1M128kS.core242.bin from this package? It is using Core 2.4.2 which handles wifi a bit better.
download/file.php?id=3807&sid=9c5b654c7 ... 96d2c5713d
Hello, thank you for getting back to me! Inside the zip file I found these two files:
  • ESPEasy_P165_1M128kS.core242.bin
    ESPEasy_P165_1M128kS.core240.bin
Which one should I try and are they PUYA safe?
enesbcs wrote:
19 Jul 2019, 17:09
The plugin replies \nOK regardless of the controller. It is necessary for HTTP based controlling to reply with a non-empty packet. What is the problem with that?
This is my first time bringing ESPEasy into my projects and to me, it just seemed out of place, to see a response in MQTT with leading \n character, while observing using MQTT Explorer. Is there a reason why the plugin must include a leading \n in the response? Thank you for your contribution and great plugin!

Re: Serial MCU controlled relay/switch

Posted: 20 Jul 2019, 19:54
by enesbcs
chubber wrote:
20 Jul 2019, 16:44
Which one should I try and are they PUYA safe?
Oops, attached a new one.
chubber wrote:
20 Jul 2019, 16:44
This is my first time bringing ESPEasy into my projects and to me, it just seemed out of place, to see a response in MQTT with leading \n character, while observing using MQTT Explorer. Is there a reason why the plugin must include a leading \n in the response? Thank you for your contribution and great plugin!
I dont know, just copied the \nOK part from another ESPEasy plugin, i assumed if that works there, it will be ok here also..

Re: Serial MCU controlled relay/switch

Posted: 29 Jul 2019, 00:07
by chubber
enesbcs wrote:
20 Jul 2019, 19:54
I dont know, just copied the \nOK part from another ESPEasy plugin, i assumed if that works there, it will be ok here also..
I tried the last PUYA safe bin file, but it was lacking the OpenHAB MQTT Controller option, so my existing configuration didn't work.

Would it be possible to include OpenHAB MQTT controller and MQTT Import?

Re: Serial MCU controlled relay/switch

Posted: 29 Jul 2019, 22:06
by BerlinSnoop
Hi enesbcs,

is possible to include the FHEM controller option too? Because I have a similar relay card like chubber with the Puya memory chip. I have lost so much time with it because the label was not readable. So now I was happy to find the hint within your and chubber's posts. My dual relay card seems to be working now with your last version, so many thanks for your great work. Only the FHEM controller entry is missing.

Many Thanx in advance

Re: Serial MCU controlled relay/switch

Posted: 29 Jul 2019, 22:49
by enesbcs
chubber wrote:
29 Jul 2019, 00:07
enesbcs wrote:
20 Jul 2019, 19:54
I dont know, just copied the \nOK part from another ESPEasy plugin, i assumed if that works there, it will be ok here also..
I tried the last PUYA safe bin file, but it was lacking the OpenHAB MQTT Controller option, so my existing configuration didn't work.

Would it be possible to include OpenHAB MQTT controller and MQTT Import?
I'll start a paid espeasy compiler service ... :D
Openhab and Fhem also included in this one.

Re: Serial MCU controlled relay/switch

Posted: 01 Aug 2019, 00:29
by BerlinSnoop
Hi enesbcs,
it is working perfect! (FHEM+Relays) :D

Many thanks again

Re: Serial MCU controlled relay/switch

Posted: 03 Aug 2019, 16:37
by fiets
Hi,

I also flashed the esp with version ESPEasy_P165.1M_128kS_PUYA3.bin

But it doesn't work.

Ik see a differnce in the gui, I don't see the option "send to controller", it is not there.

I tried to switch te relais (2) with the folowing rules:
On TurnOn do
TaskValueSet 1,1,1 //set Var#State to 1
EndOn
On TurnOff do
TaskValueSet 1,1,0 //set Var#State to 0
EndOn
On TurnOn2 do
TaskValueSet 1,2,1 //set Var#State to 1
EndOn
On TurnOff2 do
TaskValueSet 1,2,0 //set Var#State to 0
EndOn

And I use the following command in the browser http://192.168.0.133/control?cmd=event,TurnOn" and TurnOff to switch the relais. So then I see the status of the device change from 0 to 1 (TurnOn) and from 1 to 0 (TurnOff)

But the relais doesn't do anything.

What can be wrong?

Thanks!

Re: Serial MCU controlled relay/switch

Posted: 03 Aug 2019, 16:45
by enesbcs
fiets wrote:
03 Aug 2019, 16:37
TaskValueSet 1,1,1 //set Var#State to 1
I do not really understand what do you wan to achieve with taskvalueset? This plugin works with relay command, see the first post in this thread...

Re: Serial MCU controlled relay/switch

Posted: 03 Aug 2019, 16:58
by marcov
New MCU Firmware for ESP-01 + relay from LC Technology.

My first post as a newbie

I did have a device from https://nl.aliexpress.com/item/32889057 ... 4c4dSpilT1
Where the MCU was NOT flashed ( blinking led on relay board) followed instructions found on : https://www.esp8266.com/viewtopic.php?f ... =68#p74262
procedure to flash this controller and also some new commands.


MCU firmware here has been updated with 3 new functions.

B0 01 01 B2 -> Reading relay in text format ("ON" and "OFF" ending with a linefeed).
B0 01 00 B1 -> Relay reading in binary format (00 = ON and 01 = OFF).
B0 00 01 B1 -> Reading the firmware version in text format ending with a linefeed.

So now its possible to solve the problem, that when you reboot the ESP the status if the relay(s) are wrong when one of the relay where active.
Now it can be read back from MCU chip who realy controls the relay(s).

Re: Serial MCU controlled relay/switch

Posted: 03 Aug 2019, 18:58
by fiets
Mmmm, I still don't understand how to switch the relais.

I tried http://192.168.0.133/control?cmd=relay,1,0 and http://192.168.0.133/control?cmd=relay,1,1

But also then, I seen the device change in the gui but the relais is not switching....

Can you give me an example?

Thanks....