You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • To get to the bottom of the issue(s), I 'nlined' the 433 module and began to test with the following - single, generalized code, which behaves according to var xMode: 0= receiver, 1=transmitter```

    // x433.js
    var xMode = 1; // mode of operation: 0=rx, 1=tx
    
    // ----- get 433 module from 'inlined' source:
    
    var xDev  = (function(){
      var exports = {};
    
    /* Copyright (c) 2015 Gordon Williams, Pur3 Ltd. See the file LICENSE for copying permission. */
    /*
    // RX
    setTimeout(function() {
      require("433").rx(B13, console.log);
    }, 100);
    
    // TX
    require("433").tx(B13, "Hello", 5, function() {
      console.log("Sent!");
    });
    
    */
    /* Sends and receives data over simple 433Mhz AM radio links */
    
    
    function decode(w) {
      var l = w.data.length;
      var d = new Uint8Array((l+7)>>3);
      for (var i=0;i<l;i+=8)
        d[i>>3] = parseInt(w.data.substr(i,8),2);
      var data = new Uint8Array(d.buffer,0,d.length-1);
      var chksum = data.reduce(function(a,b){return a^b;},0);
      if (chksum == d[d.length-1])
        w.callback(data);
    }
    
    // The handler that gets called when the signal changes state. Ideally this would be compiled, but the Web IDE won't do that at the moment.
    function sig(w,e) {
     //"compiled";
     var d = 0|10000*(e.time-e.lastTime);
     if (d<1 | d>4) {
      if (w.data.length>20) decode(w);
      w.data="";
     } else if (!e.state) w.data+=0|d>2;
    }
    
    /* Set up to receive, and call the callback with a Uint8Array when something
    is received. */
    exports.rx = function(pin, callback) {
      // rcallback = callback; // aOC *** looks to be not in use?
      var w = {
        data : "",
        callback : callback,
        stop : function() { clearWatch(w.intr); }
      };
      // start listening for a change
      setTimeout(function() {
        // do it after a delay so it doesn't mess up the upload (if there's loads of noise)
        w.intr = setWatch(sig.bind(null,w), pin, {repeat:true, edge:"both"});
      }, 3000);
      return w;
    };
    
    // transmit the data using the given pin, repeated the given amount of times (5 seems good)
    exports.tx = function(pin, data, repeat, callback, logger) {
      var pulses = [];
      var arr = E.toUint8Array(data);
      // compute checksum
      var chksum = arr.reduce(function(a,b){return a^b;},0);
      data = new Uint8Array(arr.length+1);
      data.set(arr);
      data[data.length-1]=chksum;
      // output data, MSB first
      data.forEach(function(byt) {
        for (var b=7;b>=0;b--) {
          pulses.push((byt&128)?0.3:0.1, 0.42);
          byt<<=1;
        }
      });
      // finish up with a 1ms 'finish' pulse
      pulses.push(1);
      var msecs = E.sum(pulses)+1;  
      if (logger) logger.log({msecs:msecs,pulses:pulses});­
      // Transmit
      function send() {
        digitalPulse(pin,1,pulses);
        if (repeat-- > 0) {
          // random time gaps between retransmission
          setTimeout(send, msecs+2+Math.random()*10);
        } else if (callback) {
          setTimeout(callback, msecs + 100);
        }
      }
      // one training pulse at the start
      digitalPulse(pin,1,[1]);
      // now start sending data
      setTimeout(send, 1.5);
    };
    
      return exports;
    })();
    
    // var xDev  = require("433");
    var xPin  = B3;   // (PICO.4, 1=GND[USB left], 2=VBAT(5V USB), 3=3.3V)
    
    
    // ----- rx --- xMode=0 -----
    
    function rx() {
      try {
        LED2.set();
        LED1.reset();
        xDev.rx(xPin, function(d){
          console.log(d);
        });
      } catch(x) {
        LED1.set();
        LED2.reset();
        console.log("X2: " + x);
        setTimeout(rx,100);
      }
    }
    
    function rxInit() {
      try {
        pinMode(xPin,"input_pulldown");
        rx();
      } catch(x) {
        console.log("X1: " + x);
        setTimeout(rx,100);
      }
    }
    
    // ----- tx --- xMode=1 -----
    
    var sigLED = LED1; // red blinks while xmitting
    function txStr() { // return string "00" .. "59"
      var s = "0" + Math.floor(getTime()) % 60;
      return s.substr(s.length - 2);
    }  
    function tx() {
      if (sigLED) sigLED.set();
      s = txStr;
      xDev.tx(xPin,s, 3, function(){
        if (sigLED) sigLED.reset();
      }, console);
    }
    function txInit() {
      pinMode(xPin,"output");
      xPin.reset();
      setInterval(tx,3000);
    }
    
    
    // ----- onInit() -----
    
    function onInit() {
      if (xMode) {
        txInit();
      } else {
        rxInit();
      }
    }
    
    setTimeout(onInit,1000);
    

    The only change so far is in the transmitter: logging what pulses will be 'sent' to the transmit device...

    The output (and error) I get in the console is:

     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     1v99 (c) 2018 G.Williams
    >
    =undefined
    { "msecs": 370.16,
      "pulses": [ 0.1, 0.42, 0.3, 0.42, 0.3, 0.42, 0.3, 0.42, 0.1, 0.42, 0.3, 0.42, 0.3, 0.42, ....
    0.42, 1 ]
     }
    { "msecs": 370.16,
      "pulses": [ 0.1, 0.42, 0.3, 0.42, 0.3, 0.42, 0.3, 0.42, 0.1, 0.42, 0.3, 0.42, 0.3, 0.42, ....
    0.42, 1 ]
     }
    ERROR: Ctrl-C while processing interval - removing it.
    Execution Interrupted during event processing.
    New interpreter error: CALLBACK,MEMORY
    >
    

    Which tells me that just two (2) transmits made it before Espruino crashed?... weird is the Ctrl-C bla bla, though never did a Ctrl-C...

    I conclude that There is really something wrong in the State of Espruino.

    This is quite possible, since all the fuss about 315/433 communication stuff happened 3+ years ago...

About

Avatar for allObjects @allObjects started