You are reading a single comment by @DrAzzy and its replies. Click here to read the full conversation.
  • Man, I just can't seem to get receiving to work on the Espruino.

    I've got transmit and receive working on arduino, and transmit working on Espruino...

    Does anyone have any idea why my code isn't working?

    I'm using the same protocol that I posted the transmit code for above - it is unchanged.

    I based the receiver code on the demo code for the remote sockets. I just can't get it to work.

    With the console.log()'s in, it was constantly reporting things that looked like the start of a message (I don't recall this happening on the Arduino - there were a few false starts, but nothing like this many). With or without logging, it bogs the Espruino down something fierce.

    
    var t,n;
    var b;
    var d;
    var wr;
    var wf;
    
    // When the signal rises, check if it was after ~2ms of delay - if so (and if we have a code) display it.
    function sigOn(e) {
      var d = e.time-t;
      if (d>0.0017 && d<0.0022) {
        //console.log("starting receive "+d);
        n=0;
        b=0;
        c=0;
      }
      t = e.time;
    }
    
    // When the signal falls, measure the length of our pulse. 
    // If it was within range, record a 1 or a 0 depending on the length. 
    // If it wasn't in range, zero it
    function sigOff(e) {
      var d = e.time-t;
      t = e.time;
      if (d>0.0004 && d<0.0013){
        b++;
        if (b < 28){
          n = (n<<1) | ((d>=0.0007)?1:0);
        } else {
          c = (c<<1) | ((d>=0.0007)?1:0);
        }
      } else if (b>0) {
        n=0;
        b=0;
        c=0;
        if (b > 8) {
          console.log(b);
        }
      }
      if (b==32) {
        parseRx();
      }
    }
    
    function parseRx() {
      var ext=n&0x0F;
      var b2=(n>>4)&0xFF;
      var b1=(n>>12)&0xFF;
      var b0=(n>>20)&0xFF;
      var csc=c&0x0F;
      ncsc=b0^b1^b2;
      ncsc=(ncsc&0x0F)^((ncsc>>4)&0x0F)^ext;
      console.log("B0:"+b0+" B1:"+b1+" B2:"+b2+" ext:"+ext+" csc:"+csc+" calccsc:"+ncsc);
      if (ncsc==csc) {
        processRx(b0,b1,b2,ext);
      } else {
        console.log("Bad checksum!");
      }
    }
    
    function startListen() {
      wr=setWatch(sigOn,C6,{repeat:true,edge:"rising"});
      wf=setWatch(sigOff,C6,{repeat:true,edge:"falling"});
      console.log("Listening started");
    }
    
    function stopListen() {
      clearWatch(wr);
      clearWatch(wf);
      n=0;b=0;c=0;
    }
    
    

    Any thoughts?

About

Avatar for DrAzzy @DrAzzy started