DTH22 example code error Mongoose OS


I am following through with the quick start guide of Mongoose and using ESP32. In the second stage of the tutorial, a DHT22 sensor is interfaced with ESP32 and the firmware is updated using OTA. I have followed all the steps but finally, when I tried to build it in the web-based or regular Mongoose OS, it showed me few errors in the console log (I did not add the whole console log due to the number of character restrictions on a post). I would really appreciate it if someone can help solve these errors.


Console Log:

    CC /data/fwbuild-volumes/2.19.0/apps/app2/esp32/build_contexts/build_ctx_027669643/build/objs/wpa_supplicant/src/crypto/sha256-prf.o
    CC /data/fwbuild-volumes/2.19.0/apps/app2/esp32/build_contexts/build_ctx_027669643/build/objs/wpa_supplicant/src/crypto/rc4.o
    /data/fwbuild-volumes/2.19.0/apps/app2/esp32/build_contexts/build_ctx_027669643/src/main.c: In function 'mgos_app_init':
    /data/fwbuild-volumes/2.19.0/apps/app2/esp32/build_contexts/build_ctx_027669643/src/main.c:26:42: error: implicit declaration of function 'mgos_sys_config_get_app_pin'; did you mean 'mgos_sys_config_get_wifi'? [-Werror=implicit-function-declaration]
       struct mgos_dht *dht = mgos_dht_create(mgos_sys_config_get_app_pin(), DHT22);
    /data/fwbuild-volumes/2.19.0/apps/app2/esp32/build_contexts/build_ctx_027669643/src/main.c: At top level:
    /data/fwbuild-volumes/2.19.0/apps/app2/esp32/build_contexts/build_ctx_027669643/src/main.c:31:13: error: redefinition of 'timer_cb'
     static void timer_cb(void *arg) {
    /data/fwbuild-volumes/2.19.0/apps/app2/esp32/build_contexts/build_ctx_027669643/src/main.c:21:13: note: previous definition of 'timer_cb' was here
     static void timer_cb(void *dht) {
    /data/fwbuild-volumes/2.19.0/apps/app2/esp32/build_contexts/build_ctx_027669643/src/main.c:31:13: warning: 'timer_cb' defined but not used [-Wunused-function]
     static void timer_cb(void *arg) {
    cc1: all warnings being treated as errors
    make[1]: *** [main.c.o] Error 1
    make[1]: *** Waiting for unfinished jobs....
    /mongoose-os/platforms/esp32/src/esp32_src.mk:102: recipe for target 'main.c.o' failed

Here is my main.c code:

     * Copyright (c) 2014-2018 Cesanta Software Limited
     * All rights reserved
     * Licensed under the Apache License, Version 2.0 (the ""License"");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *     http://www.apache.org/licenses/LICENSE-2.0
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an ""AS IS"" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
    #include "mgos_dht.h"
    #include "mgos.h"

    static void timer_cb(void *dht) {
      LOG(LL_INFO, ("Temperature: %lf", mgos_dht_get_temp(dht)));

    enum mgos_app_init_result mgos_app_init(void) {
      struct mgos_dht *dht = mgos_dht_create(mgos_sys_config_get_app_pin(), DHT22);
      mgos_set_timer(1000, true, timer_cb, dht);

    static void timer_cb(void *arg) {
      static bool s_tick_tock = false;
          ("%s uptime: %.2lf, RAM: %lu, %lu free", (s_tick_tock ? "Tick" : "Tock"),
           mgos_uptime(), (unsigned long) mgos_get_heap_size(),
           (unsigned long) mgos_get_free_heap_size()));
      s_tick_tock = !s_tick_tock;
    #ifdef LED_PIN
      (void) arg;

And here is the mos.yml code:

    author: mongoose-os
    description: A Mongoose OS app skeleton
    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:

      - ["app.pin", "i", 5, {title: "GPIO pin a sensor is attached to"}] 
    #  - ["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", mgos_sys_config_get_device_id());
    # Settings are cool: can be modified remotely without full firmware upgrade!
    # To see all available compiled settings, buid the firmware and open
    # build/gen/mgos_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]

      - origin: https://github.com/mongoose-os-libs/boards
      - origin: https://github.com/mongoose-os-libs/ca-bundle
      - origin: https://github.com/mongoose-os-libs/rpc-service-config
      - origin: https://github.com/mongoose-os-libs/rpc-service-fs
      - origin: https://github.com/mongoose-os-libs/rpc-uart
      - origin: https://github.com/mongoose-os-libs/wifi
      - origin: https://github.com/mongoose-os-libs/dht  # <-- Add this line!
    # Used by the mos tool to catch mos binaries incompatible with this file format
    manifest_version: 2017-09-29

The error is very clear: you have 2 timer_cb definitions (lines 21 and 31).

Also move #include "mgos_dht.h" after #include "mgos.h"


Hello @nliviu, I did not notice that part, that’s embarrassing :sweat_smile:
Thank you, it’s working now. I still don’t have the sensor that’s why on the console I am just getting “Temperature: nan”. But I can display other stuff on the console as well, as I have a bit more understanding of the platform and also because I have now a functional console.

Best Regards,