You are reading a single comment by @thomc and its replies. Click here to read the full conversation.
  • Hi!

    LightwaveRF is a popular 433MHz home automation product line in the UK, sold in B&Q, Maplin etc.

    I have an Arduino controlling things using the same kind of 433 transmitter used in the Espruino tutorial, so I thought I'd try to port it to the Espruino at the weekend and had no luck :(

    The code for the Arduino which works is here: https://github.com/lawrie/LightwaveRF/bl­ob/master/LightwaveRF.cpp#L188

    The protocol with some more accurate values for timings is described here:
    https://wiki.somakeit.org.uk/wiki/Lightw­aveRF_RF_Protocol

    I have tried timings and values from the Arduino code and also made it to spec according to the protocol. My code was orginially written to be compact and efficient but when it didn't work I rewrote it to make debugging easier. This is based on the Arduino code:

    var TX = A0;
    
    function sendBits(bitStream) {
      bitStream.forEach(function(bit) {
        digitalPulse(TX,0,0.025); //delay 25us
        digitalPulse(TX,bit,0.28); //pulse 280us
        digitalPulse(TX,0,0.28); //pulse 280us
        if (bit === 0) digitalPulse(TX,0,0.3); //pulse 300us
      });
    }
    
    function sendMsg(command) {
      var repeat = 12;
      var bitStream = [];
      bitStream.push(1); //msg start bit
      for (var b=0;b<10;b++) { //for 10 bytes
        bitStream.push(1); //byte start bit
        for (var i = 7; i >= 0; i--) { //split byte into bits
          bitStream.push( command[b] & (1 << i) ? 1 : 0 );
        }
      }
      bitStream.push(1); //msg end bit
      var interval = setInterval(function() {
        //console.log(bitStream);
        sendBits(bitStream);
        if (repeat-- == 1) clearInterval(interval);
      }, 10.25); // delay 10250us between repeats
    }
    
    var on = [0xf6,0xf6,0xf6,0xee,0x6f,0xeb,0xbe,0xed­,0xb7,0x7b];
    var off =[0xf6,0xf6,0xf6,0xf6,0x6f,0xeb,0xbe,0xe­d,0xb7,0x7b];
    var socketOn = false;
    setWatch(function() {
      socketOn = !socketOn;
      digitalWrite(LED2,socketOn);
      sendMsg(socketOn ? on : off);
    }, BTN1, { repeat:true, edge:"rising", debounce:10 });
    

    I am pretty certain the bitStream is correct, I checked it manually. So I guess the issue is sending the bits. The LightwaveRF protocol is a bit weird, and I wrote the code several different ways. I think it is because I'm not understanding how digitalPulse is working compared to the delays in the Arduino code. For example, I set the TX to an LED and when it finished "sending" the LED remained on when surely it should be low.

    Any help would be really appreciated, we could do a lot with Espruino and LightwaveRF!

About

Avatar for thomc @thomc started