Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

ESP8266 freezes when using IR and Timer

ProFiLeR4100ProFiLeR4100 Ukraine, Odessa
edited February 8 in Mongoose OS

Hello.
I have next problem:
If device have Timer and IR receiver, then device freezes when I rapidly press button on remote control.

Test Case:
1) Clone "demo-js" project
2) Add IR library to mos.yml ( https://github.com/mongoose-os-libs/ir/ )
3) Add code from example to the top of init.js .

load('api_config.js');
load('api_events.js');
load('api_gpio.js');
load('api_mqtt.js');
load('api_net.js');
load('api_sys.js');
load('api_timer.js');
load("api_ir.js");

// TSOP on pin 14, NEC protocol
let ir = IR.Receiver.NEC.create(5, function(code) {
    print("IR", code);
}, null);

let led = Cfg.get('pins.led');
let button = Cfg.get('pins.button');
let topic = '/devices/' + Cfg.get('device.id') + '/events';

print('LED GPIO:', led, 'button GPIO:', button);

let getInfo = function() {
  return JSON.stringify({
    total_ram: Sys.total_ram(),
    free_ram: Sys.free_ram()
  });
};


// Blink built-in LED every second
GPIO.set_mode(led, GPIO.MODE_OUTPUT);
Timer.set(1000 /* 1 sec */, Timer.REPEAT, function() {
  let value = GPIO.toggle(led);
  print(value ? 'Tick' : 'Tock', 'uptime:', Sys.uptime(), getInfo());
}, null);


// Publish to MQTT topic on a button press. Button is wired to GPIO pin 0
GPIO.set_button_handler(button, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 200, function() {
  let message = getInfo();
  let ok = MQTT.pub(topic, message, 1);
  print('Published:', ok, topic, '->', message);
}, null);

// Monitor network connectivity.
Event.addGroupHandler(Net.EVENT_GRP, function(ev, evdata, arg) {
  let evs = '???';
  if (ev === Net.STATUS_DISCONNECTED) {
    evs = 'DISCONNECTED';
  } else if (ev === Net.STATUS_CONNECTING) {
    evs = 'CONNECTING';
  } else if (ev === Net.STATUS_CONNECTED) {
    evs = 'CONNECTED';
  } else if (ev === Net.STATUS_GOT_IP) {
    evs = 'GOT_IP';
  }
  print('== Net event:', ev, evs);
}, null);

4) Connect receiver (TSOP1838) to pin GPIO5.
5) Rapidly press button on remote control.
6) ESP is freezing.
7) Press "Reset" button on ESP.
8) Remove timer code:

// Blink built-in LED every second
GPIO.set_mode(led, GPIO.MODE_OUTPUT);
Timer.set(1000 /* 1 sec */, Timer.REPEAT, function() {
  let value = GPIO.toggle(led);
  print(value ? 'Tick' : 'Tock', 'uptime:', Sys.uptime(), getInfo());
}, null);

9) Upload & reboot.
10) Rapidly press button on remote control.
11) ESP is not freezing.

I think device comes to deadlock when interrupts for both events (Timer, IR receive) happen simultaneously.

Comments

Sign In or Register to comment.