Skip to content

Commit cf3c1be

Browse files
committed
Adding minimal example for ESP8266 connecting to ArduinoIoTCloud
1 parent 7f5bc98 commit cf3c1be

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Minimal demo example how to connect with the
3+
* Arduino IoT Cloud and a ESP8266 based WiFi board.
4+
*/
5+
6+
#include "arduino_secrets.h"
7+
#include "thingProperties.h"
8+
9+
#define ARDUINO_CLOUD_DEVICE_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" /* Entry "Board ID" when selecting board within Arduino Create */
10+
#define ARDUINO_CLOUD_DEVICE_PASS "my-password" /* Password set via IoT API */
11+
12+
void setup() {
13+
14+
pinMode(LED_BUILTIN, OUTPUT);
15+
16+
Serial.begin(115200);
17+
18+
/* Wait up to 5 seconds for user to open serial port */
19+
unsigned long serialBeginTime = millis();
20+
while (!Serial && (millis() - serialBeginTime > 5000));
21+
22+
initProperties();
23+
24+
setDebugMessageLevel(DBG_INFO);
25+
26+
ArduinoCloud.begin(ArduinoIoTPreferredConnection, ARDUINO_CLOUD_DEVICE_ID, ARDUINO_CLOUD_DEVICE_PASS);
27+
}
28+
29+
void loop() {
30+
ArduinoCloud.update();
31+
}
32+
33+
34+
void onLedChange() {
35+
Serial.print("LED set to ");
36+
Serial.println(led);
37+
digitalWrite(LED_BUILTIN, !led);
38+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <Arduino_ConnectionHandler.h>
2+
3+
#define SECRET_SSID "my-wifi-ssid"
4+
#define SECRET_PASS "my-wifi-password"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <ArduinoIoTCloud.h>
2+
#include <Arduino_ConnectionHandler.h>
3+
4+
#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" /* "Thing ID" when selecting thing within Arduino Create */
5+
6+
void onLedChange();
7+
8+
bool led;
9+
10+
void initProperties() {
11+
ArduinoCloud.setThingId(THING_ID);
12+
ArduinoCloud.addProperty(led, READWRITE, ON_CHANGE, onLedChange);
13+
}
14+
15+
WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);

0 commit comments

Comments
 (0)