Copyright ©

Mongoose OS Forum


Prototyping 433mhz receiver


I'm trying create a prototype with a 433mhz receiver which usually works with the Arduino IDE for the ESP8266 using the RCSwitch library. However, since MongooseOS is a great platform with a lot of default stuff already builtin, I'm trying to get the 433mhz receiver to work with mos aswell.

Following the attempt to at least receive something:

GPIO.set_mode(pin, GPIO.MODE_INPUT);

let pin = 4;

GPIO.set_int_handler(pin, GPIO.INT_EDGE_ANY, function(pin){

// print('Received interrupt on pin',pin); // This spams if connected to console

// Trying to mimic the RCSwitch interrupt handler func here

let time = Sys.uptime()*1000; //convert to millis

let duration = time - lastTime;

if(duration > 4300) { //nSeperationLimit

//This doesn't print

print('Long stretch');


lastTime = time;



It seems that there are no long stretches. Printing in the interrupt function receives a lot of spam.

Is it even possible to do this in javascript, or should I implement this in C? And is it possible to use the library as is (C++) or do I have to convert it to C?

Thanks in advance.

Ps. How do I markup multiline code?


  • rojerrojer Dublin, Ireland

    what kind of timing are we talking here? if you need microseconds-level timing, you will have to do it in C, JS is just not fast enough.

  • CacoCaco The Netherlands

    Seeing that millis() is used in the original RCSwitch library, I guess it's millisecond timing. But still, the interrupt handler seems to get called a lot.

  • rojerrojer Dublin, Ireland

    i worked with a 433 mhz receiver myself (Quasar QAM RX2) and it's very noisy.
    there's a lot of noise around, and it's constantly receiving stuff - mostly noise.
    welcome to the RF world, i guess :)
    i ended up implementing my own version of manchester encoding to get the data over the air.

  • CacoCaco The Netherlands

    Ok, but then I don't understand why the RCSwitch library works with the duration > 4300 check in place, since the noise doesn't change.

    I'll see if I can add some logging to the Arduino version in the interrupt handler and check whether that behaves the same.

    And start on porting it to C I guess.

  • Did you try

    ...3rd party C libraries could be included in the build in two different ways. First, you can just copy library sources into some directory along with src/ directory, and add that directory to the list of source directories:

    Or any news?

  • CacoCaco The Netherlands

    The problem is not including a library to be built, but the fact that the library uses the Arduino interrupt code. I have tried changing it to use the interrupt handler of mongoose-os, but the esp8266 hangs frequently if I do that. I don't know what the problem is.

    It's been a while since I looked into this, might give it a try again tonight.

  • SergeySergey Dublin, Ireland

    @Caco could you publish your app sources please?

  • i installed mongoose yesterday and i am trying to include rcswitch lib which i can't...

    Please can you help to go faster?

    Check these lines in rcswitch.cpp, i think ICACHE_RAM_ATTR makes hangs problem.

    #ifdef ESP8266
        // interrupt handler and related code must be in RAM on ESP8266,
        // according to issue #46.
        #define RECEIVE_ATTR
  • CacoCaco The Netherlands

    This code already crashes the esp8266 last time I tried it

    void handleInterrupt(int pin, void *arg) {
      static unsigned long lastTime = 0;
      //const long time = mg_time() * 1000;
      //const unsigned int duration = time - lastTime;
      if (lastTime > 4300) {
           LOG(LL_INFO, ("duration: %d pin: %d\n", lastTime,pin));
           lastTime = 0;
           if(arg == NULL){}
    enum mgos_app_init_result mgos_app_init(void) {
      struct mjs *mjs = mjs_create();
      mjs_set_ffi_resolver(mjs, mgos_dlsym);
      mjs_err_t err = mjs_exec_file(mjs, "init.js", NULL);
      if (err != MJS_OK) {
        LOG(LL_ERROR, ("MJS exec error: %s\n", mjs_strerror(mjs, err)));
      mgos_gpio_set_int_handler(4, 3, handleInterrupt, NULL);
  • SergeySergey Dublin, Ireland
    edited May 2017

    Hm. static void gpio_int_handler(int pin, void *arg) { of fw/examples/c_mqtt works.

    If you set ICACHE_RAM_ATTR in your example, does it stop crashing?

    Anyhow, if you want to speed up things, publish your app sources as e.g. github project. We are workin on making sharing easy, but for now, it should be done manually.

  • CacoCaco The Netherlands
    I'll try that. This is the only code, since I was just trying to see if I could make it work.

    Eventually it would be easier to use the RCSwitch library, but then the MOS os Arduino code needs to implement the interrupt handling somehow
  • Hi! Did you succeed in implementing RcSwitch with Mongoose? I was hoping to use it too.


Sign In or Register to comment.