Avatar for Ruprect99

Ruprect99

Member since Jun 2016 • Last active Oct 2018
  • 2 conversations
  • 19 comments

Beginner

Most recent activity

  • in ESP8266
    Avatar for Ruprect99

    I have the 2 channel version of it.

    Here is some code that is supposed to work on it.

    https://github.com/mischkasmith/lctech-2­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!

  • in ESP8266
    Avatar for Ruprect99

    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.

  • in ESP8266
    Avatar for Ruprect99

    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 https://www.esp8266.com/viewtopic.php?p=­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() {
    
      Serial1.setup(9600);
    
      var relayOn = [0xA0, 0x01, 0x01, 0xA2];
      var relayOff = [0xA0, 0x01, 0x00, 0xA1];
    
      var toggle = true;
      setInterval(function() {
        if (toggle) {
          console.log('on');
          Serial1.write(relayOn);
          toggle = true;
        } else {
          console.log('off');
          Serial1.write(relayOff);
          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?

    Thanks

  • in ESP8266
    Avatar for Ruprect99

    Don't turn it off, ground out the reset pin

    so turn it on, wait a little while, hit connect, try and type into console. if nothing, hit disconnect, ground out the reset pin and try again.
    what pins have you got wired up

  • in ESP8266
    Avatar for Ruprect99

    This looks interesting

    https://www.hackster.io/rayburne/esp8266­-captive-portal-5798ff

    It looks like its written in C so it might be possible to wrap it up into a module for use in espurino??

  • in ESP8266
    Avatar for Ruprect99

    you don't want to do that....you need to type
    var wifi = require("Wifi");

    it is not that you are requesting the wrong module, its because its not communicating with the esp8266 correctly, which is why you cannot type into the console.

    did you hit reset on the esp8266 before reconnecting? Have you got the ch_pd pin high?

  • in ESP8266
    Avatar for Ruprect99

    try lowering the baud rate, disconnect, hit reset on the esp8266, then connect again.

    it can take a little fiddling till it works

  • in ESP8266
    Avatar for Ruprect99

    you can't just paste all that text in there.
    you just need the the javascript commands not the return values.
    type in the left black panel;

    var wifi = require("Wifi");

    then wait to get the return message which will be function(){[native code]};

    then type wifi.getStatus();
    and see what you get

Actions