Copyright ©

Mongoose OS Forum


Sensors | bmp280

I'm in love with Mongoose! But I'd like to integrate temperature and pressure sensors with it and I can't seem to find a way.
Does Mongoose supports BMP280 sensor from Bosch? And 1-Wire sensors, like DHT11?
Basically how can I get readings from a BMP280? Any code samples?


  • SergeySergey Dublin, Ireland

    The datasheet at says it's an I2C sensor.

    You can:
    a) read the datasheet and use JS api_i2c.js
    b) just copy the C driver code into the firmware and rebuild the firmware

    Do you intend to use C or JS ?

  • Hum, that sounds awfully technical! :)
    Thank you for your answer and for point me in the right direction.
    I intend to use JS.

  • SergeySergey Dublin, Ireland

    Ok, then please use api_i2c.js and ask specific questions on the way!

  • Hi!
    So, I did this:

    • mos init --arch esp8266
    • mkdir vendor
    • added vendor under sources in mos.yml
    • putted the BMP280 driver in vendor/ directory
    • mos build

    And this happened!

  • Lol! Figured it out! Removed bmp280_support.c from vendor/

  • Ok, now i need to flash to device, trivial.
    Not sure what is the next step.

  • SergeySergey Dublin, Ireland

    Take a look at the .h header file. What API functions from that file you intend to call, in order to get pressure values?

  • Ok, but do i need to create init.js?

    • Files on device - click to edit
    • DST_Root_CA_X3.pem
    • conf.json
    • conf_defaults.json
    • example.txt
    • index.html
    • sys_config_schema.json
    • sys_ro_vars_schema.json
  • So, i need this, i think:

    • BMP280_RETURN_FUNCTION_TYPE bmp280_init(struct bmp280_t *bmp280);
    • s32 bmp280_compensate_temperature_int32(s32 v_uncomp_temperature_s32);
    • u32 bmp280_compensate_pressure_int32(s32 v_uncomp_pressure_s32);
  • SergeySergey Dublin, Ireland

    In mos.yml, add these functions as exports:


    The bmp280_init please call from the C code.
    Then rebuild and reflash the firmware:

      cp -r mjs_base my_firmware
      cd my_firmware
      ... modify mos.yml ...
      ... add driver ...
      ... modify src/main.c to call bmp280_init() ...
      mos build --arch esp8266
      mos flash
  • edited March 2017


    src/main.c:50:3: error: implicit declaration of function 'bmp280_init' [-Werror=implicit-function-declaration]
  • edited March 2017

    cp: skipping file '/app/build/gen/sys_config_defaults.json', as it was replaced while being copied
    /mongoose-os/fw/src/ recipe for target '/app/build/gen/conf_defaults.json' failed
    make: *** [/app/build/gen/conf_defaults.json] Error 1
    make: *** Waiting for unfinished jobs....
    LD /app/build/objs/rboot.elf
    E2 /app/build/objs/rboot.bin
      CC    ./src/core/tcp.c -> /app/build/objs/lwip/tcp.o
      CC    ./src/core/sntp.c -> /app/build/objs/lwip/sntp.o
      CC    ./src/core/def.c -> /app/build/objs/lwip/def.o
      AR    /app/build/objs/atca/libatca.a
      CC    ./src/core/netif.c -> /app/build/objs/lwip/netif.o
      CC    ./src/core/sys.c -> /app/build/objs/lwip/sys.o
      CC    ./src/core/timers.c -> /app/build/objs/lwip/timers.o
      CC    ./src/core/pbuf.c -> /app/build/objs/lwip/pbuf.o
      CC    ./src/core/udp.c -> /app/build/objs/lwip/udp.o
      CC    ./src/core/tcp_out.c -> /app/build/objs/lwip/tcp_out.o
      CC    ./src/core/ipv4/ip_frag.c -> /app/build/objs/lwip/ip_frag.o
      CC    ./src/core/ipv4/inet.c -> /app/build/objs/lwip/inet.o
      CC    ./src/core/ipv4/ip_addr.c -> /app/build/objs/lwip/ip_addr.o
      CC    ./src/core/ipv4/igmp.c -> /app/build/objs/lwip/igmp.o
      CC    ./src/core/ipv4/ip.c -> /app/build/objs/lwip/ip.o
      CC    ./src/core/ipv4/autoip.c -> /app/build/objs/lwip/autoip.o
      CC    ./src/core/ipv4/inet_chksum.c -> /app/build/objs/lwip/inet_chksum.o
      CC    ./src/core/ipv4/icmp.c -> /app/build/objs/lwip/icmp.o
      CC    ./src/api/netbuf.c -> /app/build/objs/lwip/netbuf.o
      CC    ./src/api/api_lib.c -> /app/build/objs/lwip/api_lib.o
      CC    ./src/api/netifapi.c -> /app/build/objs/lwip/netifapi.o
      CC    ./src/api/tcpip.c -> /app/build/objs/lwip/tcpip.o
      CC    ./src/api/netdb.c -> /app/build/objs/lwip/netdb.o
      CC    ./src/api/err.c -> /app/build/objs/lwip/err.o
      CC    ./src/api/api_msg.c -> /app/build/objs/lwip/api_msg.o
      CC    ./src/api/sockets.c -> /app/build/objs/lwip/sockets.o
      CC    ./espressif/app/espconn.c -> /app/build/objs/lwip/espconn.o
      CC    ./espressif/app/espconn_buf.c -> /app/build/objs/lwip/espconn_buf.o
      CC    ./espressif/app/netio.c -> /app/build/objs/lwip/netio.o
      CC    ./espressif/app/espconn_tcp.c -> /app/build/objs/lwip/espconn_tcp.o
      CC    ./espressif/app/ping.c -> /app/build/objs/lwip/ping.o
      CC    ./espressif/app/dhcpserver.c -> /app/build/objs/lwip/dhcpserver.o
      CC    ./espressif/app/espconn_mdns.c -> /app/build/objs/lwip/espconn_mdns.o
      CC    ./espressif/app/espconn_udp.c -> /app/build/objs/lwip/espconn_udp.o
      AR /app/build/objs/lwip/liblwip_cs.a
    make: *** wait: No child processes.  Stop.
    mongoose-os/fw/ recipe for target 'all' failed
    make: *** [all] Error 2
    Error: exit status 2
    Error: build failed
  • SergeySergey Dublin, Ireland

    @rikkman thanks ! for bmp280_init you need to include a header file with API definition. Do you have much experience with C?

  • A long time ago learned in school. I know things like header files and stuff...
    I was trying to make sense of the bmp280_support.c file that Bosch included in github...

  • edited March 2017

    I alter in main.c

    int bmp_start(void) {
      return bmp280_init(struct bmp280_t *bmp280);


    src/main.c: In function 'bmp_start':
    src/main.c:51:22: error: expected expression before 'struct'
       return bmp280_init(struct bmp280_t *bmp280);
    src/main.c:52:1: error: control reaches end of non-void function [-Werror=return-type]
  • Finally! It's build! In main.c:

    float bmp(){
      struct bmp280_t bmp280;
      bmp280.dev_addr = 0x77;
      return bmp280_init(&bmp280);
  • Now mos hangs at
    Calling FS.List
    But in console Tick Tock still runs...

  • SergeySergey Dublin, Ireland
      struct bmp280_t bmp280;  <--- the rest of bmp280 struct contains garbage!
      bmp280.dev_addr = 0x77;

    And, since these is garbage in there, i doubt it gets properly initialized.
    I suggest to search for an examples of proper initialization of that sensor.

Sign In or Register to comment.