You are reading a single comment by @thomc and its replies. Click here to read the full conversation.
  • It works! Thanks @Gordon, your code worked great. I realised you'd already added the byte start bit as per your comment once I traced through the code. The sigLength was of course needed, I'd forgotten to adjust that too.

    So for anyone else wanting to try this, hook up the 433 to Espruino as per the tutorial on the Espruino website. Use this piece of test code:

    var TX = A0;
    var encode = [
    "1111010",
    "1110110",
    "1110101",
    "1110011",
    "1101110",
    "1101101",
    "1101011",
    "1011110",
    "1011101",
    "1011011",
    "1010111",
    "0111110",
    "0111101",
    "0111011",
    "0110111",
    "0101111"];
    
    function sendNibbles(nibbles) {
      var repeat = 12;
      var cmdStream = "var p=digitalPulse;";
      var sigLength = 0.5;
      cmdStream+="p(TX,1,0.25);p(TX,0,0.25);"; //msg start bit
      nibbles.forEach(function(nibble) {
        encode[nibble].split("").forEach(function(bit) {
            var length = (bit=="1")?0.25:1.25;
            cmdStream+="p(TX,1,0.25);p(TX,0,"+length+");";
            sigLength += 0.25+length;
        });
      });
      cmdStream+="p(TX,1,0.25);"; //msg end bit
      sigLength += 0.25;
      var interval = setInterval(function() {
        eval(cmdStream);
        if (repeat-- == 1) clearInterval(interval);
      }, sigLength+10.25); // delay 10250us between repeats
    }
    
    var on = [0x0,0x0,0xf,0x1,0xf,0xe,0xf,0xe,0xf,0xe];
    var off =[0x0,0x0,0xf,0x0,0xf,0xe,0xf,0xe,0xf,0xe];
    
    var socketOn = false;
    setWatch(function() {
      socketOn = !socketOn;
      digitalWrite(LED2,socketOn);
      sendNibbles(socketOn ? on : off);
    }, BTN1, { repeat:true, edge:"rising", debounce:10 });
    

    Put the LightwaveRF device into learning mode (usually hold down 1 or 2 buttons until it starts flashing).

    Send the "On" message by pressing the button on the Espruino. Device should blink rapidly to indicate code accepted. Press the Espruino button again to turn the device off.

    You now have control of the LightwaveRF device with the Espruino.

    Now it is time to start working on a more complete implementation...

About

Avatar for thomc @thomc started