You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/arduino-cloud/01.getting-started/02.technical-reference/iot-cloud-tech-ref.md
+2-356Lines changed: 2 additions & 356 deletions
Original file line number
Diff line number
Diff line change
@@ -153,6 +153,8 @@ The steps below can be used as guidance when **setting up a Thing**:
153
153
154
154
## Variables
155
155
156
+
***Visit the main article on [Cloud Variables](arduino-cloud/getting-started/cloud-variables) for a more detailed coverage.***
157
+
156
158
A thing can have one or more variables. A variable can be used for multiple purposes:
157
159
158
160
* collect data over time in the cloud (sensor readings, status changes, log messages etc.)
@@ -177,362 +179,6 @@ When adding a variable the following values need to be determined:
177
179
178
180
5. The **Variable Update Policy**, which may be either **On Change** or **Periodically**. If **On Change** is chosen, the variable will be updated to the cloud whenever the change in value is greater than or equal to the set **threshold**. If **Periodically** is chosen, the variable will be updated to the cloud each time the number of seconds set is elapsed.
For your convenience, IoT Cloud provides specialized types which are just wrappers around basic types but declare the variable semantics more explicitly. This enables smarter integrations with third-party services (such as Alexa) and better visualization of widgets in dashboards.
193
-
194
-
You can use them just like a normal variable of the wrapped type, since they support assignment and comparison operators.
The following variable types hold multiple values internally and are used to represent more complex data. In order to access such values, methods are provided.
To read the Color values, we can use the following method `Color colorValues = x.getValue();`. This will assign the hue, saturation, and brightness values to the `colorValues` variable.
To set the color, we can assign the CloudColor variable directly to float variables `x = {hue,saturation,brightness}`, or using the method ` x = Color(hue,saturation,brightness)`.
274
-
275
-
#### CloudLocation
276
-
277
-
Declared as `CloudLocation x;`.
278
-
279
-
To read the location values, we can use the following method `Location coordinates = x.getValue();`. This will assign the longitude and latitude values to the coordinates variable. If we want too access the values individually we can use `Serial.println(coordinates.lat)` and `Serial.println(coordinates.lon)`.
| Input |`InputValue` ([Up to 60 values](https://github.com/arduino-libraries/ArduinoIoTCloud/blob/master/src/property/types/automation/CloudTelevision.h) such as HDMI1, HDMI2, DVD, GAME...etc.) |`x.getInput()`|`x.setInput()`|
The following utilities are available using any IoT Cloud sketch.
305
-
306
-
#### Check Connection Status
307
-
308
-
To check connection to the cloud, use:
309
-
310
-
```arduino
311
-
ArduinoCloud.connected()
312
-
```
313
-
314
-
This will return in an `int` format:
315
-
-`0` (not connected)
316
-
-`1` (connected).
317
-
318
-
#### Get Local Time (Unix)
319
-
320
-
To check local time, use:
321
-
322
-
```arduino
323
-
ArduinoCloud.getLocalTime()
324
-
```
325
-
326
-
This will return in a `long` format:
327
-
- Epoch Unix time stamp. Example: `1652442415`.
328
-
329
-
***This utility can be used together with the `CloudTime` variable and the `Time Picker` widget.***
330
-
331
-
### Examples
332
-
333
-
Here are some examples of how to use the variables in a sketch:
334
-
335
-
#### Colored Light
336
-
337
-
ColoredLight is a complex variable declared automatically in the `thingProperties.h` file as `CloudColoredLight variableName;`. The example below shows how the ColoredLight variable (declared with the variableName `cLight`) can be used and modified in the sketch. Note that the `onCLightChange()` function is automatically added and is triggered whenever the value of the Light variable is updated in the Cloud.
338
-
339
-
```arduino
340
-
#include <ArduinoGraphics.h>
341
-
#include <Arduino_MKRRGB.h> // Arduino_MKRRGB depends on ArduinoGraphics
342
-
343
-
#include "thingProperties.h"
344
-
345
-
void setup() {
346
-
// Initialize serial and wait for port to open:
347
-
Serial.begin(9600);
348
-
// This delay gives the chance to wait for a Serial mood without blocking if none is found
CloudTelevision is an automation variable declared automatically in the `thingProperties.h` file as `CloudTelevision variableName;`. The example below shows how the CloudTelevision variable (declared with the variableName `tv`) can be used and modified in the sketch. The example simulates a remote controller by using an IR receiver to read the signals sent from the a remote controller and save them in arrays of unsigned integers. An IR transmitter is then used to send IR signals using the Arduino IoT Cloud. To view the full documentation of the project, [you can check this page](https://create.arduino.cc/projecthub/313276/full-control-of-your-tv-using-alexa-and-arduino-iot-cloud-9e7c4d).
394
-
395
-
Note that the `onTvChange()` function is automatically added and is triggered whenever the value of the tv variable is updated in the Cloud.
396
-
397
-
```arduino
398
-
#include "thingProperties.h"
399
-
#include <IRremote.h>
400
-
401
-
/******* SAVE DATA FROM IR RECEIVER ********/
402
-
const unsigned int chan[9][67] = {};
403
-
const unsigned int volUp[67] = {};
404
-
const unsigned int chanUp[67] = {};
405
-
const unsigned int onoff[67] = {};
406
-
407
-
IRsend irsend;
408
-
const int freq = 38;
409
-
bool first;
410
-
411
-
int prevChannel;
412
-
int prevVolume;
413
-
bool prevSwitch;
414
-
bool prevMute;
415
-
416
-
void setup() {
417
-
// Initialize serial and wait for port to open:
418
-
Serial.begin(9600);
419
-
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
Configuring the network allows for connecting an Arduino, or third party devices to a Wi-Fi network. The credentials entered are saved in the **Secret file**, inside the sketch.
0 commit comments