Hi evryone, Newbie here working hard at my first IoT. As simple as I can make it.
TDS sensor connected to Pin 34. Inside IoT a variable linked to a gauge set to 0 to 900.
I know the sensor works. I tested that separetly. I generate a sketch in IoT and added code. I have the connect agent installed. I am able to compile and upload to my ESP32 sucessfully. Problem is the device ESP32 always shows offline and nothing is showing on the gage. See my errors and code in the attached file. Maybe it is a simple thing to change in my code. Thank you for thew help.
MYFIRSTIOT.txt (2.2 KB)
WOuld you mind posting your code in code tags?
Not at all I want to follow the rules. I will try to find what post tag means. Thank you
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
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.
*/
#define SensorPin 34
#include "thingProperties.h"
void setup() {
pinMode(SensorPin,INPUT);
// 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);
// 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
analogRead(SensorPin);
temperature = SensorPin;
delay(1000);
}
I did more research and it seems that I cannot use my ESP32 or ESP8266 with IoT cloud. On the Arduino site they post this list of compatible boards. But I saw many videos IoT projects with ESP32 so I am confused. Can someone confirm if I can use my ESP8266 and ESP32 with IoT cloud? Thank you.
The following Arduino boards and devices can be used with IoT Cloud:
Your ESP32 needs to connect to your AP, otherwise there's no internet
... that's the part missing in your code.
ok thank you zwieblum. Could you help me on how to code that?
What I don't understand is in the IoT setup of my ESP32 I did enter the SSID password and secret key. When I click on Sketch, the sketch does not contain the code to connect to my network. I followed this example on YT and he does not either have the code specifying SSID etc. But his example works. Any help would be greatly apppreciated. Thank you.
I confirm you can use these boards with Arduino IoT Cloud. It is documented here:
https://docs.arduino.cc/arduino-cloud/getting-started/iot-cloud-getting-started#esp32--esp8266
Thank you ptillisch. I did setup my ESP32 as a third party device. I can successfully upload the code to it. ziewieblum beleive that code is missing to connect to my AP.
What I don't understand is in the IoT setup of my ESP32 I did enter the SSID name, password and secret key. When I click on Sketch, the sketch does not contain the code to connect to my network. Any idea? Thank you.
That is handled by the code that is automatically generated by Arduino IoT Cloud. You only need to provide the network credentials during the Thing setup and everything else is handled automagically.
It's not really necessary to know the details, but in case you are interested, the connection is made when you call ArduinoCloud.begin(ArduinoIoTPreferredConnection) in the Thing sketch (this line is added automatically to the generated sketch by Arduino IoT Cloud). Below the hood, it is the "Arduino_ConnectionHandler" library that handles the network connection.
Thank you so much. That is my understanding as well. Everything went smooth, i created my small code below but nothing happens when I push the button. Do you see a problem with this code? Thank you.
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/1XXXXXXXXXXXXXXXXXX435388047e1
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
bool ledSwitch;
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"
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
pinMode(2,OUTPUT);
// 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();
// Your code here
}
/*
Since LedSwitch is READ_WRITE variable, onLedSwitchChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLedSwitchChange() {
if(ledSwitch==1)
{
digitalWrite(2,HIGH);
}
else
{
digitalWrite(2,LOW);
}
}
Thank you ptillisch I got the button to work. You were right no additional code is necessary. What I did different is when I start the Arduino Create Agent I right click and run as administrator. Uploaded my sketch and voila! I am very happy now I can progresss! Thank you again.
You are welcome. I'm glad it is working now.
Regards,
Per