Project with error

Hi, I want to build a wifi weather station with arduino uno r4 wifi with Arduino IoT cloud, I connected a dht22 to arduino and wrote this code
`// Adafruit Unified Sensor - Version: Latest
#include <Adafruit_Sensor.h>

// DHT sensor library - Version: Latest
#include <DHT.h>
#include <DHT_U.h>

/*
Sketch generated by the Arduino IoT Cloud Thing "Temperature Monitor"
https://create.arduino.cc/cloud/things/6e4946f5-04a9-4315-859d-b40b86240260

Arduino IoT Cloud Variables description

The following variables are automatically generated and updated when changes are made to the Thing

CloudTemperatureSensor temperature;
int humidity;
bool LED;

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.
*/

#include "thingProperties.h"
#include "DHT.h"
#define DHTPIN 11
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
dht.begin();
// 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();
}

void loop() {
ArduinoCloud.update();
float h = dht.readHumidity();
float t = dht.readTemperature();
// Your code here
temperatura = t;
umidita = h;

}

It gives me this error, how do I fix it?


/tmp/arduino-build-A4D1EDA6EDF608F83F64CA4374A560C7/sketch/objs.a(Untitled_jul27b.ino.cpp.o): In function `initProperties()':

/tmp/1628760945/Untitled_jul27b/thingProperties.h:27: undefined reference to `onUmiditaChange()'

/tmp/1628760945/Untitled_jul27b/thingProperties.h:27: undefined reference to `onLedChange()'

collect2: error: ld returned 1 exit status

Multiple libraries were found for "RTC.h"

Used: /home/builder/.arduino15/packages/arduino/hardware/renesas_uno/1.0.2/libraries/RTC

Not used: /home/builder/opt/libraries/m5stickcplus_0_0_8

Not used: /home/builder/opt/libraries/m5core2_0_1_5

Not used: /home/builder/opt/libraries/m5stickc_0_2_8

Not used: /home/builder/opt/libraries/m5station_0_0_1

Multiple libraries were found for "Adafruit_Sensor.h"

Used: /home/builder/opt/libraries/adafruit_unified_sensor_1_1_11

Not used: /home/builder/opt/libraries/arduav_1_4_2

Multiple libraries were found for "DHT.h"

Used: /home/builder/opt/libraries/dht_sensor_library_1_4_4

Not used: /home/builder/opt/libraries/ukit_explore_1_2_28

Not used: /home/builder/opt/libraries/dht11esp8266_1_0_10

Not used: /home/builder/opt/libraries/esp826611_1_0_16

Not used: /home/builder/opt/libraries/servodht11_1_0_10

Not used: /home/builder/opt/libraries/dht11esp8266examples_1_0_10

Not used: /home/builder/opt/libraries/grove_temperature_and_humidity_sensor_2_0_1

Not used: /home/builder/opt/libraries/dht118266_1_0_16

Not used: /home/builder/opt/libraries/nanoplayboard_0_1_1

Error during build: exit status 1

collect2: error: ld returned 1 exit status

It looks to me like you've only downloaded the .h part of the library, but not the .cpp

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

1 Like

Hi @penrybelly

You selected the "Read & Write" radio button from the "Variable Permission" section of the "Add variable" dialog while adding your umidita and LED Thing variables.

When variables have this configuration, a special "callback" function in your sketch will be called whenever the variable is changed from the Arduino IoT Cloud dashboard. So you must have a definition of that special function for each of the variables in your sketch. Arduino IoT Cloud automatically adds the function to the Thing sketch when you generate a new thing so it seems you probably deleted the function.

In this specific application, there is no point in making it possible for you to change the value of the umidita variables from the dashboard (because the variable is only intended to reflect the sensor reading by the Device). So I think the easiest fix will be to change the configuration of that variable from "Read & Write" to "Read Only". I'll provide instructions you can follow to do that:

  1. Click the following link to open your Arduino IoT Cloud Thing page in the web browser:
    https://create.arduino.cc/cloud/things/6e4946f5-04a9-4315-859d-b40b86240260
  2. Click the icon to the right of the "umidita" variable.
    A context menu will open.
  3. Select "Edit" from the context menu.
    The "Edit variable" dialog will open.
  4. Select the radio button next to "Read Only" under the "Variable Permission" section of the "Edit variable" dialog.
  5. Click the "SAVE" button.

As for the LED variable, you aren't even using it in the sketch so you should probably just delete it:

  1. Click the icon to the right of the "umidita" variable.
    A context menu will open.
  2. Select "Delete" from the context menu.

Now try verifying or uploading your sketch again. Hopefully it will compile successfully this time.