Copyright ©

Mongoose OS Forum

ATTENTION! This forum has moved to:

Do not post any new messages.

Button Any Edge trigger not working

It seems since the update that registering a button callback with the MGOS_GPIO_INT_EDGE_ANY trigger no longer works.


  • Please, repeat the following exercise as it is written below:

    /mos.yml (excerpt):
    - ["pins", "o", {title: "Object pins"}]
    - ["pins.led", "i", 2, {title: "GPIO2:D4"}]
    - ["pins.btn_switch", "i", 12, {title: "GPIO12:D6"}]

      - origin:
      - origin: 
      - origin:
      - origin:
      - origin:
      - origin:
      - origin:


    let pinButton = Cfg.get('pins.btn_switch');
    GPIO.set_mode(pinButton, GPIO.MODE_INPUT);
    GPIO.set_pull(pinButton, GPIO.PULL_DOWN); 
    let pinLed = Cfg.get('pins.led');
    GPIO.set_mode(pinLed, GPIO.MODE_OUTPUT); 
    function switchCallback(){
        let isSwitchOn =;
        GPIO.write(pinLed, isSwitchOn);
        print("read(", pinButton, ") --> The statement 'The switch is on' currently is " , isSwitchOn ? "TRUE" : "FALSE");   
    //Init during first start to accuire current SwitchState
    let StateResponse = {
      callback: switchCallback 
    GPIO.set_int_handler(pinButton, GPIO.INT_EDGE_ANY, StateResponse.callback, null);
  • jonwjonw USA
    edited July 2018

    @shockich It is a problem with the newer releases of the mos SDK. Look at these 2 lines:

    By adding this restriction to the mgos_gpio_set_button_handler, they have removed the ability to use the MGOS_GPIO_INT_EDGE_ANY trigger:
    !(int_mode == MGOS_GPIO_INT_EDGE_POS || int_mode == MGOS_GPIO_INT_EDGE_NEG)

    I tried modifying the code to allow for the MGOS_GPIO_INT_EDGE_ANY trigger, but when I did I noticed it was no longer reliable and my button releases were only detected 10% of the time. Therefore, I am assuming, something in the update broke the MGOS_GPIO_INT_EDGE_ANY trigger and mongoose decided to restrict the button handler registration to positive or negative edges only.

    I have since registered a timer to check the button status every 200ms until it is released as a (somewhat messy) workaround.

  • @shockich
    I am working on a project using esp8266, leds, 3 buttons( 1 flash on the chip, and 2 more created on diff chips)

    I would like to have 3 buttons for up, down, set respectively and have 2 leds attached to the esp board.
    Press button 1-- led 1 turns on (also should have an option to tell the time at which it turns on ), Button 2 for set menu(so just displays the time for now), button 3 pressed makes led 2 on

    Any suggestions regarding the function for the flash press button or outline or if someone has worked with something similar in C ?

    many thanks!

Sign In or Register to comment.