Skip to content

Commit 667071b

Browse files
committed
Added multi value example
1 parent 4f362be commit 667071b

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

Diff for: examples/MultiValue example/MultiValue_example.ino

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include "arduino_secrets.h"
2+
/*
3+
Sketch generated by the Arduino IoT Cloud Thing "Test_MultiValue"
4+
https://create-dev.arduino.cc/cloud/things/06012290-ec85-4f5c-aa00-81c0525efa0c
5+
6+
Arduino IoT Cloud Properties description
7+
8+
The following variables are automatically generated and updated when changes are made to the Thing properties
9+
10+
bool Switch;
11+
12+
Properties which are marked as READ/WRITE in the Cloud Thing will also have functions
13+
which are called when their values are changed from the Dashboard.
14+
These functions are generated with the Thing and added at the end of this sketch.
15+
*/
16+
17+
#include "thingProperties.h"
18+
19+
void setup() {
20+
// Initialize serial and wait for port to open:
21+
Serial.begin(9600);
22+
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
23+
delay(1500);
24+
25+
// Defined in thingProperties.h
26+
initProperties();
27+
28+
// Connect to Arduino IoT Cloud
29+
ArduinoCloud.begin(ArduinoIoTPreferredConnection, "mqtts-sa.iot.oniudra.cc");
30+
31+
/*
32+
The following function allows you to obtain more information
33+
related to the state of network and IoT Cloud connection and errors
34+
the higher number the more granular information you’ll get.
35+
The default is 0 (only errors).
36+
Maximum is 4
37+
*/
38+
setDebugMessageLevel(2);
39+
ArduinoCloud.printDebugInfo();
40+
}
41+
42+
float latMov = 45.5058224, lonMov = 9.1628673;
43+
float latArd = 45.0502078, lonArd = 7.6674765;
44+
45+
float hueRed = 0.0, satRed = 100.0, briRed = 100.0;
46+
float hueGreen = 80.0, satGreen = 100.0, briGreen = 100.0;
47+
48+
void loop() {
49+
ArduinoCloud.update();
50+
// Your code here
51+
52+
Switch = !Switch;
53+
if (Switch) {
54+
Loc = { .lat = latMov, .lon = lonMov };
55+
Color = { .hue = hueRed, .sat = satRed, .bri = briRed };
56+
} else {
57+
Loc = { .lat = latArd, .lon = lonArd };
58+
Color = { .hue = hueGreen, .sat = satGreen, .bri = briGreen };
59+
}
60+
delay(5000);
61+
}
62+
63+
64+
void onSwitchChange() {
65+
// Do something
66+
digitalWrite(LED_BUILTIN, Switch);
67+
}
68+
69+
void onColorChange() {
70+
// Do something
71+
Serial.print("Hue = ");
72+
Serial.println(Color.getValue().hue);
73+
Serial.print("Sat = ");
74+
Serial.println(Color.getValue().sat);
75+
Serial.print("Bri = ");
76+
Serial.println(Color.getValue().bri);
77+
}

Diff for: examples/MultiValue example/arduino_secrets.h

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define SECRET_SSID ""
2+
#define SECRET_PASS ""

Diff for: examples/MultiValue example/thingProperties.h

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <ArduinoIoTCloud.h>
2+
#include <WiFiConnectionManager.h>
3+
4+
// Set the Thing Id value
5+
const char THING_ID[] = "";
6+
7+
const char SSID[] = SECRET_SSID; // Network SSID (name)
8+
const char PASS[] = SECRET_PASS; // Network password (use for WPA, or use as key for WEP)
9+
10+
void onSwitchChange();
11+
void onColorChange();
12+
13+
bool Switch;
14+
CloudLocation Loc;
15+
CloudColor Color;
16+
17+
void initProperties(){
18+
ArduinoCloud.setThingId(THING_ID);
19+
ArduinoCloud.addProperty(Switch, READWRITE, ON_CHANGE, onSwitchChange);
20+
ArduinoCloud.addProperty(Loc, READ, ON_CHANGE, NULL);
21+
ArduinoCloud.addProperty(Color, READWRITE, ON_CHANGE, onColorChange);
22+
}
23+
24+
ConnectionManager *ArduinoIoTPreferredConnection = new WiFiConnectionManager(SSID, PASS);

0 commit comments

Comments
 (0)