Skip to content

[PC-1480][PC-1492] Arduino PRO Tutorials: Arduino Cloud Interface Resources Update (Docs 2.0) #1691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1492,20 +1492,20 @@ Once the Portenta C33 has been configured, let's create a "Thing" to test the co

Navigate into **Associate Device** and click the **Select Device** button. Select your Portenta C33 board and associate it with your "Thing." Then, navigate into **Network** and click the **Configure** button; enter your network credentials.

The project is now ready to add some variables to your "Thing"; navigate into **Cloud Variables** and click the **ADD VARIABLE** button.
The project is now ready to add some variables to your "Thing"; navigate into **Cloud Variables** and click the **ADD** button to add variable.

![Add variable button](assets/user-manual-19.png)

Add one variable with the following characteristics:

- **Name**: `led`
- **Variable type**: `boolean`
- **Variable type**: `Boolean`
- **Variable permission** `Read & Write`
- **Variable update policy**: `On change`

![Arduino Cloud "Thing" variable setup](assets/user-manual-21.png)

You should see the `led` variable in the **Cloud Variables** section. Navigate into **Dashboards** and select the **BUILD DASHBOARD** button; create a new dashboard and give your dashboard a name.
You should see the `led` variable in the **Cloud Variables** section. Navigate into **Dashboards** and select the **CREATE DASHBOARD** button; create a new dashboard and give your dashboard a name.

Add the following widgets to your dashboard:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,15 +575,15 @@ Sign in to your Arduino Cloud account by adding your credentials, i.e. Username/

![Arduino Cloud Sign in](assets/web_cloud_signin.png "Arduino Cloud Sign in")

You are now logged into your Arduino Cloud space. Go on by clicking on **API keys** in the bottom left-hand corner.
You are now logged into your Arduino Cloud space. Go on by clicking on **API keys** found within the account banner located at the top right corner.

![Arduino Cloud Homepage](assets/web_cloud_homepage.png "Arduino Cloud Homepage")

It is time to generate your API keys. Click on **CREATE API KEY** in the upper right-hand corner.

![Arduino Cloud New API Key](assets/web_cloud_new_api.png "Arduino Cloud New API Key")

Define a name for your API key, in this case *portenta-x8-test-API*, and click on **CONTINUE**. These API Keys are personal and visible just from your account.
Define a name for your API key, in this case *portenta-x8-test-API*, and click on **CREATE**. These API Keys are personal and visible just from your account.

![Arduino Cloud API Key name](assets/web_cloud_API_name.png "Arduino Cloud API Key name")

Expand All @@ -605,7 +605,8 @@ If you are using an Arduino Cloud for Business account with Shared Spaces, you n

![Out-of-the-box successful Cloud provisioning](assets/OOTB_cloud_success.png "Out-of-the-box successful Cloud provisioning")

In order to recover the Organization ID of your Shared Space on Arduino Cloud for Business, open your Arduino Cloud homepage and navigate to **Settings > General Settings** in the sidebar on the left.
In order to recover the Organization ID, known as Space ID, of your Shared Space on Arduino Cloud for Business, open your Arduino Cloud homepage and navigate to **Space Settings > General** in the sidebar on the left.

![Space ID on Cloud Settings](assets/shared-space-settings.png "Space ID on Cloud Settings")

At this point, you can copy the **Space ID** of your Shared Space and paste it into your Out-of-the-box dashboard together with your API keys.
Expand Down Expand Up @@ -641,7 +642,7 @@ Now you can start connecting your Portenta X8 to the Portenta X8 Board Manager.

Check the Arduino Cloud for business plan with Portenta X8 Manager [here](https://cloud.arduino.cc/plans#business) and create your Arduino Cloud account in a couple of steps (see the dedicated documentation at [this link](https://docs.arduino.cc/arduino-cloud/)).

When your Arduino Cloud for business account is correctly set up, log into it [here](https://cloud.arduino.cc/home/) and click on **Portenta X8 Board Manager**.
When your Arduino Cloud for business account is correctly set up, log into it [here](https://cloud.arduino.cc/home/) and click on **Portenta X8 Board Manager**. The feature is located within the **Integrations** section of the Cloud.

![Arduino Cloud homepage with Portenta X8 Manager](assets/web_board_manager_cloud_integration.png "Arduino Cloud homepage with Portenta X8 Manager")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ void loop(){
}
```

Upload the sketch from the **sketch tab** by clicking the second button at the top left of the left side of the sketch bar. Once it has been uploaded, you can see the temperature value just uploaded by going to your **Thing Setup** tab and looking at the last value of the **temperature** variable. You can also open the Serial Monitor to see your data live.
Upload the sketch from the **sketch tab** by clicking the second button at the top left side of the sketch bar.

Once it has been uploaded, you can see the temperature value just uploaded by going to your **Thing Setup** tab and looking at the last value of the **temperature** variable. You can also open the Serial Monitor to see your data live.

![Arduino Cloud - Sketch tab](assets/IoTCloud-thingSketch.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,9 @@ void modbus_line(){
}
```

The header that includes the Arduino Cloud properties is outlined below. Be aware that this file comes from the Arduino Cloud platform, located within the sketch's workspace. It requires prior configuration of Opta™. Due to project specifications, these properties are subject to changes.
The header that includes the Arduino Cloud properties is outlined below. This file comes from the Arduino Cloud platform within the sketch's workspace. It requires prior configuration of Opta™. Due to project specifications, these properties are subject to changes.

If Opta™ was configured to use Wi-Fi® connectivity as the network interface, the `thingProperties.h` header will resemble as follows.

```arduino
// Code generated by Arduino Cloud, DO NOT EDIT.
Expand Down Expand Up @@ -574,6 +576,41 @@ void initProperties(){
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
```

If Opta™ was configured to use Ethernet as the network interface, the `thingProperties.h` header will resemble as follows.

```arduino
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

const char IP[] = SECRET_OPTIONAL_IP;
const char DNS[] = SECRET_OPTIONAL_DNS;
const char GATEWAY[] = SECRET_OPTIONAL_GATEWAY;
const char NETMASK[] = SECRET_OPTIONAL_NETMASK;

void onUOperMarginChange();
void onUWattChange();
void onUWhConChange();
void onDirectOverride1Change();

float uOperMargin;
float uWatt;
float uWhCon;
float uWhOpta;
bool directOverride1;

void initProperties(){

ArduinoCloud.addProperty(uOperMargin, READWRITE, ON_CHANGE, onUOperMarginChange);
ArduinoCloud.addProperty(uWatt, READWRITE, ON_CHANGE, onUWattChange);
ArduinoCloud.addProperty(uWhCon, READWRITE, ON_CHANGE, onUWhConChange);
ArduinoCloud.addProperty(uWhOpta, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(directOverride1, READWRITE, ON_CHANGE, onDirectOverride1Change);

}

EthernetConnectionHandler ArduinoIoTPreferredConnection(IP, DNS, GATEWAY, NETMASK);
```

The header, automatically generated by Arduino Cloud based on the defined variables, is best left unedited. Any additions or deletions of variables should be handled directly within the Cloud environment.

The above header is an illustrative example tailored to a demonstration script. This script can either be employed as-is or adjusted to meet different system requirements per your preference.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,15 @@ hardware:

The home automation systems allow to control electronic devices remotely and to perform automatic routines based on the user's programming preferences, making domestic environments more convenient, comfortable, and efficient, also optimizing energy costs.



Home automation applications allow, for example, smart lights management and HVAC control.
Thanks to its industrial IoT capabilities, Opta™️ is an excellent product for home automation applications.

Home automation applications allow, for example, smart lights management and HVAC control. Thanks to its industrial IoT capabilities, Opta™️ is an excellent product for home automation applications.

![Opta™️ with Wi-Fi® connectivity support](assets/opta-device.png)

## Goals

This application note shows a home automation system based on an Opta™️, capable of controlling a roller window shade, also known as roller blind, based on a programmed scenario. The application note's goals are to:


- Implement the roller window shade control (opening and closing) upon a programmed scenario

- Get inputs from limit switches included in the roller window shade's control system, for feedback and security reinforcement
- Control and monitor the roller window shade via [Arduino Cloud](https://create.arduino.cc/iot/)

Expand Down Expand Up @@ -76,7 +70,9 @@ The Opta™️ controls a DC motor via a driver using the digital output termina

### Application Overview

The first task of the program is to create the connection between the Opta™️ and the predefined Wi-Fi® network by the user in the Arduino Cloud; when the Wi-Fi® connection is established, the internal real-time clock (RTC) of the Opta™️ will be synced using a Network Time Protocol (NTP) server. Opta™️ RTC will be synced with the NTP server periodically (in this example, every 30 minutes) for security and reliability reasons.
The first task of the program is to create the connection between the Opta™️ and the predefined Wi-Fi® network by the user in the Arduino IoT Cloud; when the Wi-Fi® connection is established, the internal real-time clock (RTC) of the Opta™️ will be synced using a Network Time Protocol (NTP) server.

Opta™️ RTC will be synced with the NTP server periodically (in this example, every 30 minutes) for security and reliability reasons.

***The NTP is a protocol used to synchronize the clocks of servers and clients across the Internet; it is intended to synchronize computers participating in the network within a few milliseconds of Coordinated Universal Time (UTC). You can read more about the NTP protocol [here](https://en.wikipedia.org/wiki/Network_Time_Protocol).***

Expand All @@ -85,7 +81,7 @@ After the RTC is synced, Opta™️ will be programmed for **opening** and **clo
- The roller window shade will open automatically in the morning as the sun rises (e.g. 6:00 AM) and close in the evening (e.g. 6:00 PM)
- The NO SPDT limit switches will provide Opta™️ a feedback for the sun shield's upper or lower end limit, triggering the motor's stop

### Example Sketch of the Application
### Example Sketch of the Application

Hereafter the sketch explained. Note that **this code must be updated considering the proper parameters of your roller window shade and DC motor characteristics**.

Expand Down Expand Up @@ -122,9 +118,10 @@ int programmed_minutes_2 = 0;
```

For Wi-Fi® connectivity, we will use [`WiFi`](https://www.arduino.cc/reference/en/libraries/wifi/) library.

For the connection to an NTP server and to retrieve time information from it, we will use [`NTPClient`](https://github.com/arduino-libraries/NTPClient).
We are going to use specific RTC management methods from Mbed™️ to handle the internal RTC of the Opta™️ microcontroller. More information regarding those methods can be found [here](https://os.mbed.com/docs/mbed-os/v6.15/mbed-os-api-doxy/mbed__mktime_8h_source.html).

We are going to use specific RTC management methods from Mbed™️ to handle the internal RTC of the Opta™️ microcontroller. More information regarding those methods can be found [here](https://os.mbed.com/docs/mbed-os/v6.15/mbed-os-api-doxy/mbed__mktime_8h_source.html).

From the code shown above, there are two important lines:

Expand Down Expand Up @@ -589,9 +586,11 @@ We will use a dashboard and widgets to modify the variables explained before. An

In the dashboard shown above:

- `Value`-type widgets are used to show the current value of the `programmed_hour_1`, `programmed_hour_2`, `programmed_minutes_1`, and `programmed_minutes_2` variables. These widgets can also be used to modify the value of the linked variables.
- `LED`-type widget shows the current status of the `shade_state` variable, green when the shade is open and red when the shade is closed.
- `Push button` widgets are used to open or close the shade anytime.
- **`Value`**-type widgets are used to show the current value of the `programmed_hour_1`, `programmed_hour_2`, `programmed_minutes_1`, and `programmed_minutes_2` variables. These widgets can also be used to modify the value of the linked variables.

- **`LED`**-type widget shows the current status of the `shade_state` variable, green when the shade is open and red when the shade is closed.

- **`Push button`** widgets are used to open or close the shade anytime.

The complete example sketch with the Arduino Cloud integration is shown below:

Expand Down Expand Up @@ -642,7 +641,7 @@ void setup() {
open_shade = false;
close_shade = false;
programmed_hour_1 = 6;
programmed_hour_1 = 18;
programmed_hour_2 = 18;
programmed_minutes_1 = 0;
programmed_minutes_2 = 0;

Expand Down
Diff not rendered.
Original file line number Diff line number Diff line change
Expand Up @@ -640,13 +640,49 @@ void modbus_line(){

Thanks to the Arduino Cloud, we can create a simple but useful dashboard to have a professional real-time Human-Computer Interaction (HCI) as it can be seen below:

![Arduino Cloud integration with the tanks](assets/cloud_integration.svg)
![Arduino Cloud integration with the tanks](assets/cloud_integration.png)

Within Arduino Cloud's dashboard, the system status of both the tanks can be monitored and the remote actuation is implemented for both the Opta™ devices' managed tasks. Using this powerful tool, the actuators and emergency stop can be controlled remotely on-demand. The dashboard can also be used to make a simulation, even without the full exact hardware implementation of the application note.

## Full Tank Level Monitoring Example

The complete code for the Small and Big Tank's management implementation with Opta™ can be downloaded [here](assets/tank-level-monitoring-sketch.zip). It is important to know that for both, `thingProperties.h` is included with its respective variables and is generated automatically with Arduino Cloud.
The complete code for the Small and Big Tank's management implementation with Opta™ can be downloaded [here](assets/tank-level-monitoring-sketch.zip). It is important to know that for both, `thingProperties.h` is included with its respective variables and is generated automatically with Arduino Cloud. It also contains essential network interface settings, which in this case is configured using the Wi-Fi® network interface.

The Arduino Cloud automatically generates a specialized header file customized to the configured network interface settings and defined variables. It is recommended to avoid manual edits to this file. Network interface settings or variables should be modified through the Arduino Cloud interface.

Opta™ is set up with Wi-Fi® as the network interface for the present application note's example. Thus, the `thingProperties.h` file includes settings such as the network SSID and password. The highlighted elements of the code for this configuration are shown below:

For example, in this application note, Opta™ uses Wi-Fi® as its network interface. As a result, the `thingProperties.h` header incorporates settings like the network SSID and password. Below are the elements of the code for this Wi-Fi® configuration:

```arduino
//code generated by Arduino IoT Cloud, DO NOT EDIT.

#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

const char SSID[] = SECRET_SSID; // Network SSID (name)
const char PASS[] = SECRET_OPTIONAL_PASS; // Network password (use for WPA, or use as key for WEP)

...

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
```

Should Opta™ need to be set up with an Ethernet connection, the `thingProperties.h` header would contain different parameters, such as _IP_, _DNS_, _Gateway_, and _Netmask_. The corresponding code highlight for an Ethernet setup would be updated to:

```arduino
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

const char IP[] = SECRET_OPTIONAL_IP;
const char DNS[] = SECRET_OPTIONAL_DNS;
const char GATEWAY[] = SECRET_OPTIONAL_GATEWAY;
const char NETMASK[] = SECRET_OPTIONAL_NETMASK;

...

EthernetConnectionHandler ArduinoIoTPreferredConnection(IP, DNS, GATEWAY, NETMASK);
```

## Conclusion

Expand Down
Loading