Hi there,
I am having problems getting code to compile in the Cloud Editor.
I am trying to hook up a DHT22 sensor to an ESP WROOM32 board.
The code I have used is from the DHTesp library example pasted into the code automatically generated by the Cloud editor when creating the sketch from the Thing.
I pasted in block by block verifying the code at each stage. The one line which seems to cause the compile to fail is -
initTemp(); in void setup()
The bare sketch without the DHT example code compiles and uploads fine.
When I put the DHT example code into the IDE editor I can successfully compile and upload to the board.
It is the combination of the two and using the example code in the Cloud editor that seems to cause the issue.
This is my first post. I'm a pretty new Arduino user. Hopefully I have correctly pasted the code and error messages below.
Help here would be greatly appreciated. Thanks in advance,
Simon
#include <DHTesp.h>
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/5581da4b-8fd5-4b99-9322-232caf1894f1
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float dHT_Hum;
float dHT_Temp;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
//DHT code
#include <Ticker.h>
#ifndef ESP32
#pragma message(THIS EXAMPLE IS FOR ESP32 ONLY!)
#error Select ESP32 board.
#endif
DHTesp dht;
//float localTime;
void tempTask(void *pvParameters);
bool getTemperature();
void triggerGetTemp();
/** Task handle for the light value read task */
TaskHandle_t tempTaskHandle = NULL;
/** Ticker for temperature reading */
Ticker tempTicker;
/** Comfort profile */
ComfortState cf;
/** Flag if task should run */
bool tasksEnabled = false;
/** Pin number for DHT11 data pin */
int dhtPin = 17;
/**
* initTemp
* Setup DHT library
* Setup task and timer for repeated measurement
* @return bool
* true if task and timer are started
* false if task or timer couldn't be started
*/
bool initTemp() {
byte resultValue = 0;
// Initialize temperature sensor
dht.setup(dhtPin, DHTesp::DHT22);
Serial.println("DHT initiated");
// Start task to get temperature
xTaskCreatePinnedToCore(
tempTask, /* Function to implement the task */
"tempTask ", /* Name of the task */
4000, /* Stack size in words */
NULL, /* Task input parameter */
5, /* Priority of the task */
&tempTaskHandle, /* Task handle. */
1); /* Core where the task should run */
if (tempTaskHandle == NULL) {
Serial.println("Failed to start task for temperature update");
return false;
} else {
// Start update of environment data every 20 seconds
tempTicker.attach(20, triggerGetTemp);
}
return true;
}
/**
* triggerGetTemp
* Sets flag dhtUpdated to true for handling in loop()
* called by Ticker getTempTimer
*/
void triggerGetTemp() {
if (tempTaskHandle != NULL) {
xTaskResumeFromISR(tempTaskHandle);
}
}
/**
* Task to reads temperature from DHT11 sensor
* @param pvParameters
* pointer to task parameters
*/
void tempTask(void *pvParameters) {
Serial.println("tempTask loop started");
while (1) // tempTask loop
{
if (tasksEnabled) {
// Get temperature values
getTemperature();
}
// Got sleep again
vTaskSuspend(NULL);
}
}
//All OK so far
/*
* getTemperature
* Reads temperature from DHT11 sensor
* @return bool
* true if temperature could be aquired
* false if aquisition failed
*/
bool getTemperature() {
// Reading temperature for humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
TempAndHumidity newValues = dht.getTempAndHumidity();
// Check if any reads failed and exit early (to try again).
if (dht.getStatus() != 0) {
Serial.println("DHT11 error status: " + String(dht.getStatusString()));
return false;
}
float heatIndex = dht.computeHeatIndex(newValues.temperature, newValues.humidity);
float dewPoint = dht.computeDewPoint(newValues.temperature, newValues.humidity);
float cr = dht.getComfortRatio(cf, newValues.temperature, newValues.humidity);
String comfortStatus;
switch(cf) {
case Comfort_OK:
comfortStatus = "Comfort_OK";
break;
case Comfort_TooHot:
comfortStatus = "Comfort_TooHot";
break;
case Comfort_TooCold:
comfortStatus = "Comfort_TooCold";
break;
case Comfort_TooDry:
comfortStatus = "Comfort_TooDry";
break;
case Comfort_TooHumid:
comfortStatus = "Comfort_TooHumid";
break;
case Comfort_HotAndHumid:
comfortStatus = "Comfort_HotAndHumid";
break;
case Comfort_HotAndDry:
comfortStatus = "Comfort_HotAndDry";
break;
case Comfort_ColdAndHumid:
comfortStatus = "Comfort_ColdAndHumid";
break;
case Comfort_ColdAndDry:
comfortStatus = "Comfort_ColdAndDry";
break;
default:
comfortStatus = "Unknown:";
break;
};
Serial.println(" T:" + String(newValues.temperature) + " H:" + String(newValues.humidity) + " I:" + String(heatIndex) + " D:" + String(dewPoint) + " " + comfortStatus);
return true;
}
#include "thingProperties.h" //Cloud editor code
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(115200);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
/*
Serial.println();
Serial.println("DHT ESP32 example with tasks");
initTemp();
// Signal end of setup() to tasks
tasksEnabled = true;
*/
// This is the one line that causes compile errors in the code
initTemp();
tasksEnabled = true;
}
void loop() {
ArduinoCloud.update();
delay(2000);
// Your code here
/*
if(ArduinoCloud.connected()){
if(ArduinoCloud.getLocalTime()!= 0){
Serial.println(ArduinoCloud.getLocalTime());
//Serial.println(ArduinoCloud.getInternalTime());
//rtc1.setEpoch(ArduinoCloud.getLocalTime());
//Serial.println(rtc1.getHours());
}
}
*/
if (!tasksEnabled) {
// Wait 2 seconds to let system settle down
delay(2000);
// Enable task that will read values from the DHT sensor
tasksEnabled = true;
if (tempTaskHandle != NULL) {
vTaskResume(tempTaskHandle);
}
}
yield();
}
The Error messages are:
/usr/local/bin/arduino-cli compile --fqbn esp32:esp32:esp32da:UploadSpeed=921600,CPUFreq=240,FlashFreq=80,FlashMode=qio,FlashSize=4M,PartitionScheme=default,DebugLevel=none,LoopCore=1,EventsCore=1,EraseFlash=none --build-cache-path /tmp --output-dir /tmp/4077611988/build --build-path /tmp/arduino-build-6ADE5332775E1D980A1D13DEF731FFF0 --library /mnt/create-efs/webide/5f/fd/5ffd4f1a229dfdc095997744f79fa770:curlyfruit/libraries_v2/DHT Sensors Non-Blocking --library /mnt/create-efs/webide/5f/fd/5ffd4f1a229dfdc095997744f79fa770:curlyfruit/libraries_v2/DHT sensor library for ESPx /tmp/4077611988/Test_oct16a
/home/builder/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/arduino-build-6ADE5332775E1D980A1D13DEF731FFF0/sketch/objs.a(Test_oct16a.ino.cpp.o):(.literal._Z8initTempv+0x2c): undefined reference to `DHTesp::setup(unsigned char, DHTesp::DHT_MODEL_t)'
/home/builder/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/arduino-build-6ADE5332775E1D980A1D13DEF731FFF0/sketch/objs.a(Test_oct16a.ino.cpp.o):(.literal._Z14getTemperaturev+0x4c): undefined reference to `DHTesp::getTempAndHumidity()'
/home/builder/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/arduino-build-6ADE5332775E1D980A1D13DEF731FFF0/sketch/objs.a(Test_oct16a.ino.cpp.o):(.literal._Z14getTemperaturev+0x50): undefined reference to `DHTesp::getStatusString()'
/home/builder/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/arduino-build-6ADE5332775E1D980A1D13DEF731FFF0/sketch/objs.a(Test_oct16a.ino.cpp.o):(.literal._Z14getTemperaturev+0x54): undefined reference to `DHTesp::computeHeatIndex(float, float, bool)'
/home/builder/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/arduino-build-6ADE5332775E1D980A1D13DEF731FFF0/sketch/objs.a(Test_oct16a.ino.cpp.o):(.literal._Z14getTemperaturev+0x58): undefined reference to `DHTesp::computeDewPoint(float, float, bool)'
/home/builder/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/arduino-build-6ADE5332775E1D980A1D13DEF731FFF0/sketch/objs.a(Test_oct16a.ino.cpp.o):(.literal._Z14getTemperaturev+0x5c): undefined reference to `DHTesp::getComfortRatio(ComfortState&, float, float, bool)'
/home/builder/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/arduino-build-6ADE5332775E1D980A1D13DEF731FFF0/sketch/objs.a(Test_oct16a.ino.cpp.o): in function `initTemp()':
/tmp/4077611988/Test_oct16a/Test_oct16a.ino:59: undefined reference to `DHTesp::setup(unsigned char, DHTesp::DHT_MODEL_t)'
/home/builder/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/arduino-build-6ADE5332775E1D980A1D13DEF731FFF0/sketch/objs.a(Test_oct16a.ino.cpp.o): in function `getTemperature()':
/tmp/4077611988/Test_oct16a/Test_oct16a.ino:126: undefined reference to `DHTesp::getTempAndHumidity()'
/home/builder/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/4077611988/Test_oct16a/Test_oct16a.ino:129: undefined reference to `DHTesp::getStatusString()'
/home/builder/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/4077611988/Test_oct16a/Test_oct16a.ino:133: undefined reference to `DHTesp::computeHeatIndex(float, float, bool)'
/home/builder/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/4077611988/Test_oct16a/Test_oct16a.ino:134: undefined reference to `DHTesp::computeDewPoint(float, float, bool)'
/home/builder/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/4077611988/Test_oct16a/Test_oct16a.ino:135: undefined reference to `DHTesp::getComfortRatio(ComfortState&, float, float, bool)'
collect2: error: ld returned 1 exit status
Multiple libraries were found for "WiFi.h"
Used: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.17/libraries/WiFi
Not used: /home/builder/opt/libraries/indhilib_3_0_5
Not used: /home/builder/opt/libraries/betterwifinina_1_3_0
Not used: /home/builder/opt/libraries/wifinina_1_8_14
Not used: /home/builder/opt/libraries/wifi_1_2_7
Not used: /home/builder/opt/libraries/da16200_wi_fi_library_for_arduino_1_1_0
Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_1_0
Not used: /home/builder/opt/libraries/nina_wi_fi_1_0_1
Not used: /home/builder/opt/libraries/wifiespat_1_5_0
Not used: /home/builder/opt/libraries/vega_wifinina_1_0_1
Multiple libraries were found for "WiFiClientSecure.h"
Used: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.17/libraries/WiFiClientSecure
Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_1_0
Multiple libraries were found for "Ticker.h"
Used: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.17/libraries/Ticker
Not used: /home/builder/opt/libraries/simpleticker_2_1_0
Not used: /home/builder/opt/libraries/ticker_4_4_0
Multiple libraries were found for "DHTesp.h"
Used: /mnt/create-efs/webide/5f/fd/5ffd4f1a229dfdc095997744f79fa770:curlyfruit/libraries_v2/DHT sensor library for ESPx
Not used: /home/builder/opt/libraries/dht_sensor_library_for_espx_1_19_0
Error during build: exit status 1