Copyright ©

Mongoose OS Forum

ATTENTION! This forum has moved to:

Do not post any new messages.

iot-kit-esp8266-latest ---> issue for using api_dht.js


I am using Nodemcu broad (ESP12E) to develop my DHT 11 sensor app. Here is my code :


let dht = DHT.create(5, DHT.DHT11);
print('Temperature:', dht.getTemp());

I connect my the data port of DHT11 sensor to D1 (GPIO05). The VCC is 3.3v.

I will see the log from "mos tool ui console".

[Aug 26 15:53:40.432] mg_rpc_channel_mqtt 0x3fff106c esp8266_2BCC89/rpc/#
[Aug 26 15:53:40.438] mg_rpc_channel_uart 0x3fff1334 UART0
[Aug 26 15:53:40.443] mgos_init Init done, RAM: 52328 total, 44116 free, 43584 min free
_[Aug 26 15:53:40.524] Hello
[Aug 26 15:53:40.536] Temperature: 9223372036854775807 _

[Aug 26 15:53:40.543] mongoose_poll New heap free LWM: 41304
[Aug 26 15:53:40.548] mgos_net_on_change_c WiFi STA: connecting
[Aug 26 15:53:42.555] scandone

You can see that the Temperature is not correct.

I use the same H/W configuration to test the DHT11 sensor on Arduino IDE. The Temperature is correct. Can anyone tell me how can I solve it ?


Paul Wang


  • I suggest to add these:

    let dht11 = DHT.create(dht_pin, DHT.DHT11);
    if (dht11 === null) print('DHT sensor not detected.');
  • Hi Michael,

    I modified my code:

    let dht11 = DHT.create(5, DHT.DHT11);
    if (dht11 === null) {
    print('DHT sensor not detected.');
    } else {
    print ('DHT sensor detected!');
    print('Temperature:', dht11.getTemp());

    Then I get the following result.

    [Aug 28 10:45:29.268] DHT sensor detected!
    [Aug 28 10:45:29.294] Temperature: 9223372036854775807

    It is a strange thing. If I disconnected DHT11 sensor with ESP12E (Nodemcu board) , I still get the same output message. Do you have any other suggestion ?


    Paul Wang

  • renlehrenleh Taipei
    edited July 2018


    I solve my issue. "My mos tool" version is "latest".

    I use another library "api_arduino_dht.js".

    I don't understand why "api_dht.js" can not work. I hope someone can show me how to use "api_dht.js" correctly.

    Here is my code for "init.js".

    // Call every second
    Timer.set(1000, true, function() {
      let value = GPIO.toggle(2);
      print(value ? 'Tick' : 'Tock');
      let dht = DHT.create(5, DHT.DHT11);
      print("Humidity:", dht.readHumidity(0));
    }, null);

    Here is the code for my "mos.yml".

    author: mongoose-os
    description: An empty app that does nothing
    version: 1.0
    libs_version: ${mos.version}
    modules_version: ${mos.version}
    mongoose_os_version: ${mos.version}
    # Optional. List of tags for online search.
      - c
    # List of files / directories with C sources. No slashes at the end of dir names.
      - src
    # List of dirs. Files from these dirs will be copied to the device filesystem
      - fs
    # Custom configuration entries, settable via "device configuration"
    # Below is a custom firmware configuration example.
    # Uncomment and modify according to your needs:
    # config_schema:
    #  - ["my_app", "o", {title: "My app custom settings"}]
    #  - ["my_app.bool_value", "b", false, {title: "Some boolean value"}]
    #  - ["my_app.string_value", "s", "", {title: "Some string value"}]
    #  - ["my_app.int_value", "i", 123, {title: "Some integer value"}]
    # These settings get compiled into the C structure, and can be accessed
    # from the C code this way:
    # printf("Hello from %s!\n", get_cfg()->;
    # Settings are cool: can be modified remotely without full firmware upgrade!
    # To see all available compiled settings, buid the firmware and open
    # build/gen/sys_config.c or build/gen/sys_config.h file.
    # Also, in this config_schema section, you can override existing
    # settings that has been created by other libraries. For example, debug log
    # level is 2 by default. For this firmware we can override it to 3:
    # config_schema:
    #  - ["debug.level", 3]
    # List of libraries used by this app, in order of initialisation
      - origin:
      - origin:
      - origin:
      - origin:
      - origin:
      - origin:
     _** - origin:**_
    # Used by the mos tool to catch mos binaries incompatible with this file format
    manifest_version: 2017-05-18


    Paul Wang

  • Mongoose OS is still evolving rapidly, so I am not surprised that old code does not work anymore.

  • @renleh, dht lib was fixed for DHT11 sensor. Please check, if this is still relevant.

Sign In or Register to comment.