Serial MCU controlled relay/switch

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
Mravko
Normal user
Posts: 26
Joined: 18 Feb 2019, 04:48

Re: Serial MCU controlled relay/switch

#251 Post by Mravko » 04 May 2019, 07:33

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

Bohbe
Normal user
Posts: 10
Joined: 02 May 2019, 09:14
Location: Uppsala, Sweden

Re: Serial MCU controlled relay/switch

#252 Post by Bohbe » 04 May 2019, 10:26

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?

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

Re: Serial MCU controlled relay/switch

#253 Post by enesbcs » 04 May 2019, 16:38

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.

Bohbe
Normal user
Posts: 10
Joined: 02 May 2019, 09:14
Location: Uppsala, Sweden

Re: Serial MCU controlled relay/switch

#254 Post by Bohbe » 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...

Mravko
Normal user
Posts: 26
Joined: 18 Feb 2019, 04:48

Re: Serial MCU controlled relay/switch

#255 Post by Mravko » 07 May 2019, 07:40

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.

Mravko
Normal user
Posts: 26
Joined: 18 Feb 2019, 04:48

Re: Serial MCU controlled relay/switch

#256 Post by Mravko » 07 May 2019, 08:17

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

Mravko
Normal user
Posts: 26
Joined: 18 Feb 2019, 04:48

Re: Serial MCU controlled relay/switch

#257 Post by Mravko » 08 May 2019, 16:03

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

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

Re: Serial MCU controlled relay/switch

#258 Post by enesbcs » 08 May 2019, 17:33

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.

bkarpe
Normal user
Posts: 2
Joined: 25 Dec 2017, 15:52

Re: Serial MCU controlled relay/switch

#259 Post by bkarpe » 11 May 2019, 22:07

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.

bkarpe
Normal user
Posts: 2
Joined: 25 Dec 2017, 15:52

Re: Serial MCU controlled relay/switch

#260 Post by bkarpe » 12 May 2019, 22:10

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.

Bohbe
Normal user
Posts: 10
Joined: 02 May 2019, 09:14
Location: Uppsala, Sweden

Re: Serial MCU controlled relay/switch

#261 Post by Bohbe » 18 May 2019, 20:08

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

muppet96
Normal user
Posts: 7
Joined: 17 May 2019, 13:31

Re: Serial MCU controlled relay/switch

#262 Post by muppet96 » 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.

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

Re: Serial MCU controlled relay/switch

#263 Post by enesbcs » 18 May 2019, 21:34

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

Bohbe
Normal user
Posts: 10
Joined: 02 May 2019, 09:14
Location: Uppsala, Sweden

Re: Serial MCU controlled relay/switch

#264 Post by Bohbe » 19 May 2019, 17:18

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?

Bohbe
Normal user
Posts: 10
Joined: 02 May 2019, 09:14
Location: Uppsala, Sweden

Re: Serial MCU controlled relay/switch

#265 Post by Bohbe » 20 May 2019, 01:05

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.

Bohbe
Normal user
Posts: 10
Joined: 02 May 2019, 09:14
Location: Uppsala, Sweden

Re: Serial MCU controlled relay/switch

#266 Post by Bohbe » 26 May 2019, 17:10

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!

Farrukh
Normal user
Posts: 4
Joined: 28 May 2019, 17:27

Re: Serial MCU controlled relay/switch

#267 Post by Farrukh » 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
Attachments
Capture.PNG
Capture.PNG (22.45 KiB) Viewed 1211 times

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

Re: Serial MCU controlled relay/switch

#268 Post by enesbcs » 28 May 2019, 18:33

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

Farrukh
Normal user
Posts: 4
Joined: 28 May 2019, 17:27

Re: Serial MCU controlled relay/switch

#269 Post by Farrukh » 29 May 2019, 10:16

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.

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

Re: Serial MCU controlled relay/switch

#270 Post by grovkillen » 29 May 2019, 11:19

What type of relay are you using? Many relays need 5V to trigger, the ESP only deliver 3.3V on the GPIO?
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: 375
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#271 Post by enesbcs » 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

Bohbe
Normal user
Posts: 10
Joined: 02 May 2019, 09:14
Location: Uppsala, Sweden

Re: Serial MCU controlled relay/switch

#272 Post by Bohbe » 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 ;)

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

Re: Serial MCU controlled relay/switch

#273 Post by enesbcs » 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"

Farrukh
Normal user
Posts: 4
Joined: 28 May 2019, 17:27

Re: Serial MCU controlled relay/switch

#274 Post by Farrukh » 30 May 2019, 11:42

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.

Bohbe
Normal user
Posts: 10
Joined: 02 May 2019, 09:14
Location: Uppsala, Sweden

Re: Serial MCU controlled relay/switch

#275 Post by Bohbe » 30 May 2019, 11:45

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)

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

Re: Serial MCU controlled relay/switch

#276 Post by enesbcs » 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?
Attachments
ESPEasy_P165_2019.zip
(1.25 MiB) Downloaded 64 times

Bohbe
Normal user
Posts: 10
Joined: 02 May 2019, 09:14
Location: Uppsala, Sweden

Re: Serial MCU controlled relay/switch

#277 Post by Bohbe » 31 May 2019, 20:39

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

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

Re: Serial MCU controlled relay/switch

#278 Post by enesbcs » 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?

Farrukh
Normal user
Posts: 4
Joined: 28 May 2019, 17:27

Re: Serial MCU controlled relay/switch

#279 Post by Farrukh » 01 Jun 2019, 12:24

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.

Mravko
Normal user
Posts: 26
Joined: 18 Feb 2019, 04:48

Re: Serial MCU controlled relay/switch

#280 Post by Mravko » 13 Jun 2019, 14:39

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?

kallipso.v@gmail.com
Normal user
Posts: 3
Joined: 23 Jun 2019, 16:22

Re: Serial MCU controlled relay/switch

#281 Post by kallipso.v@gmail.com » 29 Jun 2019, 12:11

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

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

Re: Serial MCU controlled relay/switch

#282 Post by enesbcs » 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)

kallipso.v@gmail.com
Normal user
Posts: 3
Joined: 23 Jun 2019, 16:22

Re: Serial MCU controlled relay/switch

#283 Post by kallipso.v@gmail.com » 30 Jun 2019, 16:25

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?
Attachments
Untitled.jpg
Untitled.jpg (23.77 KiB) Viewed 391 times

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

Re: Serial MCU controlled relay/switch

#284 Post by enesbcs » 30 Jun 2019, 19:30

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/

kallipso.v@gmail.com
Normal user
Posts: 3
Joined: 23 Jun 2019, 16:22

Re: Serial MCU controlled relay/switch

#285 Post by kallipso.v@gmail.com » 01 Jul 2019, 00:03

and what about feedback ?
state_topic:

Post Reply

Who is online

Users browsing this forum: No registered users and 39 guests