Skip to content

Commit 8de9d03

Browse files
committed
add images
1 parent 3e6d97d commit 8de9d03

File tree

4 files changed

+313
-366
lines changed

4 files changed

+313
-366
lines changed

content/arduino-cloud/01.getting-started/02.technical-reference/iot-cloud-tech-ref.md

Lines changed: 2 additions & 356 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ The steps below can be used as guidance when **setting up a Thing**:
153153

154154
## Variables
155155

156+
***Visit the main article on [Cloud Variables](arduino-cloud/getting-started/cloud-variables) for a more detailed coverage.***
157+
156158
A thing can have one or more variables. A variable can be used for multiple purposes:
157159

158160
* 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:
177179

178180
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.
179181

180-
### Basic Types
181-
182-
| Type | Declaration |
183-
| --------------------- | ---------------------- |
184-
| Boolean | `bool variableName;` |
185-
| Character String | `String variableName;` |
186-
| Floating Point Number | `float variableName;` |
187-
| Integer Number | `int variableName;` |
188-
189-
190-
### Specialized Types
191-
192-
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.
195-
196-
| Type | Declaration | Wrapped data type |
197-
| -------------------- | ---------------------------------------- | ----------------- |
198-
| Acceleration | `CloudAcceleration variableName;` | `float` |
199-
| Angle | `CloudAngle variableName;` | `float` |
200-
| Area | `CloudArea variableName;` | `float` |
201-
| Capacitance | `CloudCapacitance variableName;` | `float` |
202-
| Color | `CloudColor variableName;` | `float` |
203-
| Contact Sensor | `CloudContactSensor variableName;` | `bool` |
204-
| Counter | `CloudCounter variableName;` | `int` |
205-
| Data Rate | `CloudDataRate variableName;` | `float` |
206-
| Electric Current | `CloudElectricCurrent variableName;` | `float` |
207-
| Electric Potention | `CloudElectricPotention variableName;` | `float` |
208-
| Electric Resistance | `CloudElectricResistance variableName;` | `float` |
209-
| Energy | `CloudEnergy variableName;` | `float` |
210-
| Flow Rate | `CloudFlowRate variableName;` | `float` |
211-
| Force | `CloudForce variableName;` | `float` |
212-
| Frequency | `CloudFrequency variableName;` | `float` |
213-
| Heart Rate | `CloudHeartRate variableName;` | `float` |
214-
| Information Content | `CloudInformationContent variableName;` | `int` |
215-
| Length | `CloudLength variableName;` | `float` |
216-
| Light | `CloudLight variableName;` | `bool` |
217-
| Location | `CloudLocation variableName;` | `float` |
218-
| Logarithmic Quantity | `CloudLogarithmicQuantity variableName;` | `float` |
219-
| Luminance | `CloudLuminance variableName;` | `float` |
220-
| Luminous Flux | `CloudLuminousFlux variableName;` | `float` |
221-
| Luminous Intensity | `CloudLuminousIntensity variableName;` | `float` |
222-
| Mass | `CloudMass variableName;` | `float` |
223-
| Motion Sensor | `CloudMotionSensor variableName;` | `bool` |
224-
| Percentage | `CloudPercentage variableName;` | `float` |
225-
| Power | `CloudPower variableName;` | `float` |
226-
| Pressure | `CloudPressure variableName;` | `float` |
227-
| Relative Humidity | `CloudRelativeHumidity variableName;` | `float` |
228-
| Smart Plug | `CloudSmartPlug variableName;` | `bool` |
229-
| Switch | `CloudSwitch variableName;` | `bool` |
230-
| CloudTemperature | `CloudTemperature variableName;` | `float` |
231-
| Temperature Sensor | `CloudTemperatureSensor variableName;` | `float` |
232-
| Time | `CloudTime variableName;` | `float` |
233-
| Velocity | `CloudVelocity variableName;` | `float` |
234-
| Volume | `CloudVolume variableName;` | `float` |
235-
236-
237-
### Complex Types
238-
239-
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.
240-
241-
#### DimmedLight
242-
243-
Declared as `CloudDimmedLight x;`
244-
245-
| Property | Type | Read value | Set value |
246-
| ---------- | --------------- | ------------------- | ------------------- |
247-
| Brightness | `float` (0-100) | `x.getBrightness()` | `x.setBrightness()` |
248-
| Switch | `bool` | `x.getSwitch()` | `x.setSwitch()` |
249-
250-
#### ColoredLight
251-
252-
Declared as `CloudColoredLight x;`
253-
254-
| Property | Type | Read value | Set value |
255-
| ---------- | --------------- | ------------------- | ------------------- |
256-
| Switch | `bool` | `x.getSwitch()` | `x.setSwitch()` |
257-
| Hue | `float` (0-360) | `x.getHue()` | `x.setHue()` |
258-
| Saturation | `float` (0-100) | `x.getSaturation()` | `x.setSaturation()` |
259-
| Brightness | `float` (0-100) | `x.getBrightness()` | `x.setBrightness()` |
260-
261-
#### CloudColor
262-
263-
Declared as `CloudColor x;`.
264-
265-
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.
266-
267-
| Property | Type | Read value | Set value |
268-
| ---------- | ------- | ----------------- | -------------------------------------- |
269-
| Hue | `float` | `colorValues.hue` | `x = Color(hue,saturation,brightness)` |
270-
| Saturation | `float` | `colorValues.sat` | `x = Color(hue,saturation,brightness)` |
271-
| Brightness | `float` | `colorValues.bri` | `x = Color(hue,saturation,brightness)` |
272-
273-
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)`.
280-
281-
| Property | Type | Read value | Set value |
282-
| --------- | ------- | ----------------- | --------------------------- |
283-
| Latitude | `float` | `coordinates.lat` | This variable is ready only |
284-
| Longitude | `float` | `coordinates.lon` | This variable is ready only |
285-
286-
***The format of the `lat` and `lon` is in Decimal Degrees (DD), for example `41.40338`, `2.17403`.***
287-
288-
#### Television
289-
290-
Declared as `CloudTelevision x;`
291-
292-
| Property | Type | Read Value | Set value |
293-
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | ------------------------ |
294-
| Switch | `bool` | `x.getSwitch()` | `x.setSwitch()` |
295-
| Volume | `int`(0-100) | `x.getVolume()` | `x.setVolume()` |
296-
| Mute | `bool` | `x.getMute()` | `x.setMute()` |
297-
| PlaybackCommands | `PlaybackCommands` (FastForward, Next, Pause, Play, Previous, Rewind, StartOver, Stop) | `x.getPlaybackCommand()` | `x.setPlaybackCommand()` |
298-
| 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()` |
299-
| Channel | `int` | `x.getChannel()` | `x.setChannel()` |
300-
301-
302-
### Utilities
303-
304-
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
349-
delay(1500);
350-
351-
// Defined in thingProperties.h
352-
initProperties();
353-
354-
// Connect to Arduino IoT Cloud
355-
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
356-
setDebugMessageLevel(2);
357-
ArduinoCloud.printDebugInfo();
358-
359-
if (!MATRIX.begin()) {
360-
Serial.println("Failed to initialize MKR RGB shield!");
361-
while (1);
362-
}
363-
364-
// set the brightness, supported values are 0 - 255
365-
MATRIX.brightness(10);
366-
}
367-
368-
void loop() {
369-
ArduinoCloud.update();
370-
}
371-
372-
void onCLightChange() {
373-
uint8_t r, g, b;
374-
cLight.getValue().getRGB(r, g, b);
375-
376-
MATRIX.beginDraw();
377-
378-
if (cLight.getSwitch()) {
379-
Serial.println("R:"+String(r)+" G:"+String(g)+ " B:"+String(b));
380-
MATRIX.fill(r, g, b);
381-
MATRIX.rect(0, 0, MATRIX.width(), MATRIX.height());
382-
}else{
383-
MATRIX.clear();
384-
}
385-
386-
MATRIX.endDraw();
387-
}
388-
389-
```
390-
391-
#### Television
392-
393-
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
420-
delay(1500);
421-
422-
// Defined in thingProperties.h
423-
initProperties();
424-
425-
// Connect to Arduino IoT Cloud
426-
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
427-
setDebugMessageLevel(2);
428-
ArduinoCloud.printDebugInfo();
429-
430-
first = true;
431-
pinMode(LED_BUILTIN, OUTPUT);
432-
}
433-
434-
void loop() {
435-
ArduinoCloud.update();
436-
}
437-
438-
/******* HANDLING THE IR TRANSMITTER********/
439-
void sendIR(const unsigned int buf[]) {
440-
digitalWrite(LED_BUILTIN, HIGH);
441-
irsend.sendRaw(buf, 67, freq);
442-
delay(300);
443-
digitalWrite(LED_BUILTIN, LOW);
444-
}
445-
446-
void onTvChange() {
447-
448-
Serial.println("==================");
449-
Serial.println("Switch:"+String(tv.getSwitch()));
450-
Serial.println("Volume:"+String(tv.getVolume()));
451-
Serial.println("Channel:"+String(tv.getChannel()));
452-
Serial.println("Mute:"+String(tv.getMute()));
453-
Serial.println("==================");
454-
455-
if (first){
456-
prevSwitch = tv.getSwitch();
457-
prevVolume = tv.getVolume();
458-
prevChannel = tv.getChannel();
459-
prevMute = tv.getMute();
460-
first = false;
461-
return;
462-
}
463-
464-
465-
// Volume changed
466-
if (tv.getVolume() > prevVolume) {
467-
tv.setMute(false);
468-
prevMute = false;
469-
for (int k = prevVolume + 1 ; k<=tv.getVolume(); k++) {
470-
sendIR(volUp);
471-
Serial.println("Volume requested:"+String(tv.getVolume())+" Set:"+String(k));
472-
}
473-
prevVolume = tv.getVolume();
474-
}
475-
else if (tv.getVolume() < prevVolume) {
476-
tv.setMute(false);
477-
prevMute = false;
478-
for (int k = prevVolume - 1; k>=tv.getVolume(); k--) {
479-
sendIR(volDown);
480-
Serial.println("Volume changed:"+String(tv.getVolume())+" Set:"+String(k));
481-
}
482-
prevVolume = tv.getVolume();
483-
}
484-
485-
486-
// Mute changed
487-
if (tv.getMute() != prevMute && tv.getMute()) {
488-
prevMute = tv.getMute();
489-
sendIR(mute);
490-
Serial.println("Mute changed:"+String(tv.getMute()));
491-
}
492-
else if (tv.getMute() != prevMute && !tv.getMute()) {
493-
prevMute = tv.getMute();
494-
sendIR(mute);
495-
Serial.println("Mute changed:"+String(tv.getMute()));
496-
}
497-
498-
499-
// Channel changed
500-
if (tv.getChannel() != prevChannel) {
501-
int newChannel = tv.getChannel();
502-
if (newChannel > 0 && newChannel < 10) {
503-
sendIR(chan[newChannel-1]);
504-
} else if (newChannel > 9) {
505-
if (newChannel > prevChannel) {
506-
for (int ch = prevChannel; ch < newChannel; ch++) {
507-
sendIR(chanUp);
508-
Serial.println("Chan requested:"+String(newChannel)+" Set:"+String(ch));
509-
}
510-
} else if (newChannel < prevChannel) {
511-
for (int ch = prevChannel; ch > newChannel; ch--) {
512-
sendIR(chanDown);
513-
Serial.println("Chan requested:"+String(newChannel)+" Set:"+String(ch));
514-
}
515-
}
516-
}
517-
prevChannel = newChannel;
518-
Serial.println("Channel changed:"+String(tv.getChannel()));
519-
}
520-
521-
522-
// On/Off changed
523-
if (tv.getSwitch() != prevSwitch) {
524-
prevSwitch = tv.getSwitch();
525-
if (tv.getSwitch()) {
526-
sendIR(chan[6]);
527-
} else {
528-
sendIR(onoff);
529-
}
530-
Serial.println("Switch changed:"+String(tv.getSwitch()));
531-
}
532-
}
533-
534-
```
535-
536182
## Configuring Network
537183

538184
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.
Loading

0 commit comments

Comments
 (0)