LCTech relay control via Espurino

Posted on
  • Hi,

    I'm trying to write some simple code to toggle a esp8266 based relay.

    According to all the docs I've seen (and according to this post­66327) all one needs to do is send a series of hex codes out over the serial port to toggle the switch.

    So I've written a very simple bit of code that I think should work, but I'm not overly familar with sending serial data.

    function onInit() {
      var relayOn = [0xA0, 0x01, 0x01, 0xA2];
      var relayOff = [0xA0, 0x01, 0x00, 0xA1];
      var toggle = true;
      setInterval(function() {
        if (toggle) {
          toggle = true;
        } else {
          toggle = false;
      }, 5000);

    Is there any obvious flaw in this code as its not working. I can see the blue led flash every 5 seconds as it sends the data, but is this the correct way to send a set of hex instructions?


  • I've since tried sending the hex directly to the board using my PC and still getting nothing, so I think its something up with the board rather than the espurino code.

  • So you have this module?­66-wifi-5v-1-channel-relay-delay-module-­iot-smart-home-e8a437

    Are you running Espruino on the module itself, or do you have Espruino running elsewhere and you're trying to send data to it?

    If you've flashed Espruino onto the module itself then yeah, what you're doing sounds ok - you could try sending just the String "A00101A2" just in case that was it?

    However, the problem is that when the ESP8266 module is working as it does normally as seems to be described in that link above, it won't just output that hex code - there's some other stuff too. Something along the lines of +IPD0,4:\xA0\x01\x01\xA2

    To be sure, you'd probably have to flash the normal AT command firmware, get it working, then connect your PC and figure out exactly what got sent.

  • I have the 2 channel version of it.

    Here is some code that is supposed to work on it.­ch-relay/blob/master/lctech2ch.ino

    I'm running the code on the ESP8266 that is on the device, so in theory I should just power the device, and it should load the code, and start switching the relay. I just wanted to do a simple test before doing anything else to ensure I could control it.

    I did connect an FTDI to is while it was running and it did seem to be sending more that just those commands to the out. basically anything outputted to the console was getting sent too. Is there a way to redirect the console outputs to another channel that I can observe, whilst keeping the serial1 channel just for the comms to the module?

    I did also try just sending the commands directly from my pc using some node js code, but I still couldn't get it to work at all.

    I have a second relay module so might try that incase there is a fault with that one, but it just seemed very unresponsive.

    Next thing will be to get it working as per the original spec as you suggest to make sure the board actually works!

  • Is there a way to redirect the console outputs to another channel that I can observe, whilst keeping the serial1 channel just for the comms to the module?

    Yes, just use LoopbackA.setConsole() and then add whatever listener you want with LoopbackB.on('data', ...) - or just replace LoopbackA with whatever output device you want the JS console to appear on.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

LCTech relay control via Espurino

Posted by Avatar for Ruprect99 @Ruprect99