#include <WiFi.h>
// Code generated by Arduino IoT Cloud, DO NOT EDIT.
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char DEVICE_LOGIN_NAME[] = "91694e2b-aff2-44d7-aca0-b93572b57f45";
const char* SSID = "Wokwi-GUEST"; // Network SSID (name)
const char* PASS = ""; // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[] = "key"; // Secret device password
float accelerometre;
float humidity;
float temp;
void initProperties(){
ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
ArduinoCloud.addProperty(accelerometre, READWRITE, 1 * SECONDS, onAccelerometreChange);
ArduinoCloud.addProperty(humidity, READWRITE, 1 * SECONDS, onHumidityChange);
ArduinoCloud.addProperty(temp, READWRITE, 1 * SECONDS, onTempChange);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
setup_wifi();
// Initialize serial and wait for port to open:
// 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() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
accelerometre = random(0, 100);
humidity = random(0, 100);
temp = random(0, 100);
ArduinoCloud.update();
}
void setup_wifi()
{
delay(100);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(SSID);
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PASS);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
randomSeed(micros());
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
/*
Since Temp is READ_WRITE variable, onTempChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTempChange() {
// Add your code here to act upon Temp change
}
/*
Since Humidity is READ_WRITE variable, onHumidityChange() is
executed every time a new value is received from IoT Cloud.
*/
void onHumidityChange() {
// Add your code here to act upon Humidity change
}
/*
Since Accelerometre is READ_WRITE variable, onAccelerometreChange() is
executed every time a new value is received from IoT Cloud.
*/
void onAccelerometreChange() {
// Add your code here to act upon Accelerometre change
}