XIAO ESP32C3 with Arduino IoT cloud,an easy way to build a wifi APP, so we can control XIAO and get information form XIAO from long distance. This demo show sending messages from Arduino IoT APP to XIAO ESP32C3.
Hardware connectingEnter: https://create.arduino.cc/iot/things
Step 1:
Create Thing:
Step 2:
Create variables
Step 3:
Create a Dashboard
step 4:
Download the Arduino Create Agent
step 5:
Add the Display:
If you send a message from APP(the message change) then XIAO will display the message at once.
Complete code:
remember to change your wifi ssid and password.
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
#include <WiFi.h>
const char* ssid = "***";
const char* password = "***";
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_MIRROR, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // ESP32 Thing, HW I2C with pin remapping
#include "thingProperties.h"
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);
//OLED
u8g2.begin();
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
u8g2.drawStr(50, 50,"Hello world"); // write something to the internal memory
u8g2.sendBuffer();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
//Serial.print(".");
}
// 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();
// We start by connecting to a WiFi network
/*Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());*/
}
void loop() {
ArduinoCloud.update();
}
/*
Since LoveStr is READ_WRITE variable, onLoveStrChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLoveStrChange() {
// Add your code here to act upon LoveStr change
//Serial.println("strchange");
char* strshow = (char*)love_str.c_str();
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
u8g2.drawStr(50, 50,strshow); // write something to the internal memory
u8g2.sendBuffer();
}
Step 6:
upload
Download the APP on our phone:
Login then you can find the Dashboard you create.
Now you can send the message to you XIAO ESP32C3!
Comments
Please log in or sign up to comment.