Ill admit that I jumped onto the Arduino thing with no coding experience at all but I did the Plant Watering Kit and I have been hooked since. I am currently trying to use IoT Cloud and use DHT11 sensor on my rp2040 connect to gain humidity data. When upload a simple DHT program into the sketch with CloudTemperature temperature; sketch I have going on I am getting all sorts of errors. One that is really getting me is
expected constructor, destructor, or type conversion before '(' token dht_sensor (DHT_SENSOR_PIN, DHT_SENSOR_TYPE )
the code that its giving me the error on is
dht_sensor (DHT_SENSOR_PIN, DHT_SENSOR_TYPE);
I have been researching alot about what it could be but nothing that I can truly say that I understand. What does this code want from me, furthermore.. any recommendations for learning C++. I have studied Python a bit but I am finding myself lost on a lot of these projects. Any help would be greatly appreciated.
A lot of this was copy and paste from an Elegoo kit that I have but the code doesnt even compile on the IDE so its kind of all over the place, I didnt write this code
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/1bc1aa78-30b0-4260-bf67-8c0b7a5bc923
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float humidity;
CloudTemperature temperature;
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 <Arduino_LSM6DSOX.h>
#include <EduIntro.h>
#include <SimpleDHT.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
static const int DHT_SENSOR_PIN = 2;
dht_sensor (DHT_SENSOR_PIN, DHT_SENSOR_TYPE);
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
/*
* Poll for a measurement, keeping the state machine alive. Returns
* true if a measurement is available.
*/
static bool measure_environment( float *temperature, float *humidity )
{
static unsigned long measurement_timestamp = millis( );
/* Measure once every four seconds. */
if( millis( ) - measurement_timestamp > 3000ul )
{
if( dht_sensor.measure( temperature, humidity ) == true )
{
measurement_timestamp = millis( );
return( true );
}
}
return( false );
}
// 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();
// Your code here
if (IMU.temperatureAvailable())
{
int temperature_deg = 0;
IMU.readTemperature(temperature_deg);
Serial.print("LSM6DSOX Temperature = ");
Serial.print(temperature_deg);
Serial.println(" °C");
}
*
* Main program loop.
*/
void loop( )
{
float temperature;
float humidity;
/* Measure temperature and humidity. If the functions returns
true, then a measurement is available. */
if( measure_environment( &temperature, &humidity ) == true )
{
Serial.print( "T = " );
Serial.print( temperature, 1 );
Serial.print( " deg. C, H = " );
Serial.print( humidity, 1 );
Serial.println( "%" );
}
}
}
You have a mismatch in { and } or one or more } are in the wrong place
If you use tools -> autoformat, you get the below
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
/*
* Poll for a measurement, keeping the state machine alive. Returns
* true if a measurement is available.
*/
static bool measure_environment( float *temperature, float *humidity )
{
static unsigned long measurement_timestamp = millis( );
...
...
The fact that the function declaration static bool does not start at the beginning of a line after an autoformat indicates that there is a } missing before it.
Note:
This is actually a "programming question" and not related to "IoT Cloud"