Skip to content

Commit ee2a275

Browse files
authored
Merge pull request #23 from bcmi-labs/connection-manager
ConnectionManager implementation and status of IoT Cloud connection
2 parents 2764c88 + 302956f commit ee2a275

10 files changed

+528
-168
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
This sketch demonstrates how to exchange data between your board and the Arduino IoT Cloud.
3+
4+
Connect a potentiometer (or other analog sensor) to A1 and an LED to Digital Pin 5.
5+
When the potentiometer (or sensor) value changes the data is sent to the Cloud.
6+
When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF.
7+
8+
9+
*/
10+
#include "arduino_secrets.h"
11+
#include "thingProperties.h"
12+
13+
void setup() {
14+
15+
// Initialize serial and wait for port to open:
16+
Serial.begin(9600);
17+
// wait up to 5 seconds for user to open Serial port
18+
unsigned long serialBeginTime = millis();
19+
while (!Serial && (millis() - serialBeginTime > 5000));
20+
21+
Serial.println("Starting Arduino IoT Cloud Example");
22+
23+
// initProperties takes care of connecting your sketch variables to the ArduinoIoTCloud object
24+
initProperties();
25+
// tell ArduinoIoTCloud to use our WiFi connection
26+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
27+
28+
/*
29+
The following function allows you to obtain more information
30+
related to the state of network and IoT Cloud connection and errors
31+
the higher number the more granular information you'll get.
32+
The default is 0 (only errors).
33+
Maximum is 3
34+
35+
setDebugMessageLevel(3);
36+
*/
37+
38+
}
39+
40+
void loop() {
41+
ArduinoCloud.update();
42+
43+
int potentiometer = analogRead(A1);
44+
45+
}
46+
47+
48+
/*
49+
this function is called when the "led" property of your Thing changes
50+
*/
51+
void onLedChange() {
52+
Serial.print("LED set to ");
53+
Serial.println(led);
54+
digitalWrite(LED_BUILTIN, ledSwitch);
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#define SECRET_SSID "YOUR_WIFI_NETWORK_NAME"
2+
#define SECRET_PASS "YOUR_WIFI_PASSWORD"
3+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <ArduinoIoTCloud.h>
2+
#include <WiFiConnectionManager.h>
3+
4+
5+
char ssid[] = SECRET_SSID; // your network SSID (name)
6+
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
7+
// Your THING_ID
8+
#define THING_ID "ARDUINO_IOT_CLOUD_THING_ID"
9+
10+
void onLedChange();
11+
12+
bool led;
13+
int potentiometer;
14+
15+
void initProperties() {
16+
ArduinoCloud.setThingId(THING_ID);
17+
ArduinoCloud.addProperty(led, READWRITE, ON_CHANGE, onLedChange);
18+
ArduinoCloud.addProperty(potentiometer, READ, ON_CHANGE);
19+
}
20+
21+
ConnectionManager *ArduinoIoTPreferredConnection = new WiFiConnectionManager(SECRET_SSID, SECRET_PASS);

examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino

-149
This file was deleted.

examples/MKR1000_Cloud_Blink/arduino_secrets.h

-3
This file was deleted.

0 commit comments

Comments
 (0)