Select the version of your OS from the tabs below. If you don't know the version you are using, run the command cat /etc/os-release
or cat /etc/issue
on the board.
Remember that you can always refer to the Torizon Documentation, there you can find a lot of relevant articles that might help you in the application development.
Using the Visual Studio Extension for Torizon and Visual Studio 2019 it is easy to set up a highly productive developer workflow for creating Torizon based apps. To demonstrate this, this article will:
Note: the example-specific information is presented at the end of the article on Example: Weatherboard with InfluxDB, Grafana and OpenWeatherMap
This article complies to the Typographic Conventions for Torizon Documentation.
To begin, see here a short video showing how easy is to debug C/C++ applications on Torizon devices using Torizon Extension with Visual Studio:
Then, let's go with our step-by-step guide with our sample application.
Create a new project using Visual Studio 2019.
Clone the Torizon samples and the InfluxDB C++ API repositories to your PC. Open a PowerShell and run:
$ git clone https://github.com/toradex/torizon-samples.git $ git clone https://github.com/offa/influxdb-cxx.git
Add the contents from Torizon samples to your project:
torizon-samples\weather\src\
to your project folder - you can use the Windows File Explorer to do it.Solution Explorer
(you can choose Delete
, not just Remove
).Add the contents from the InfluxDB C++ API to your project:
influxdb-cxx
inside your project folder - you can use the Windows File Explorer to do it.Attention: before proceeding, you may add your OpenWeatherMap API key to the example. See how to do it on How to Use the Example - Configure OpenWeatherMap.
With the WeatherSample
project selected on Solution Explorer
, click Project > Properties to edit the project level properties:
Additional Include Directories
to include the include and the influxdb-cxx\include folders.C++ Language Standard
to C++17 (-std=c++17)
. This specific C++ version is required for libraries in this example - your own project may require a different version of C/C++.Library Dependencies
:curl;pthread;boost_system;jsoncpp
Click on Apply --> Ok to close the Property Pages
.
The Torizon Visual Studio Development Tools Extension creates a new property window in any Torizon C/C++ Application
project. To open that window, click Project > WeatherSample > Properties... item and select the Torizon C/C++ Aplication
node. Be sure that All Configurations
and All Platforms
are selected at the top of the Property Pages
window:
Now drop down the value next to Configuration
in the main panel, and click <Properties...>
. This window allows you to configure the values that are ultimately passed to Docker to manage various aspects of the containers that will be built as part of the project. At the top, the Username
should be set to the default (torizon) and the Configuration should be Common
.
You can install development packages in the container that runs on the development PC to cross-build the application for the Toradex board (target device):
devpackages
row and click on Edit....devpackages
:libcurl4-openssl-dev:armhf libboost1.67-dev:armhf libboost-system1.67-dev:armhf libboost-test1.67-dev:armhf libboost-program-options1.67-dev:armhf libjsoncpp-dev:armhf
You can install extra packages
to be included in your application container that runs on the target:
extrapackages
row and click on Edit....extrapackages
:libcurl4 libboost-system1.67.0 libjsoncpp1
You can configure the container networking. To add/edit the values in the bottom section of the property window, simply click the ...
button, then click New
in the popup, and enter the value on the new row. For our example, add the following new value for the Networks:
setting in the property window:
#%application.id%#_backend
To orchestrate the containers bring-up, set up a docker-compose file. Click the "..."
button next to Docker-compose script:
and save it with the filename: docker-compose.yml.
docker-compose.yml
In the toolbar at the top of Solution Explorer
, toggle the button to Show All Files
if it is not already enabled. You will now see a folder in Solution Explorer
named appconfig_0. Expand that folder and open the docker-compose.yml file:
For our application, we'll need a total of 3 containers:
We'll also declare the networks and volumes we need, link the containers, and expose Grafana on port 3000.
docker-compose.ymlversion: '2.4' services: grafana: container_name: grafana depends_on: - influxdb networks: - backend - frontend volumes: - "grafana-storage:/var/lib/grafana" ports: - "3000:3000" links: - influxdb image: grafana/grafana:6.7.1 influxdb: container_name: influxdb networks: - backend volumes: - "influxdb-grafana:/var/lib/influxdb" image: influxdb:1.7.10 networks: backend: internal: true frontend: internal: false volumes: grafana-storage: influxdb-grafana:
Follow the steps from the article Visual Studio Extension for Torizon - Deploy and Debug
This is it, now you have a broader understanding of how to develop a C++ application for Torizon using Toradex's Visual Studio extension.
This section goes through aspects specific to the example, that are not applicable to other projects using the Visual Studio extension.
There are many weather APIs available, our sample uses the OpenWeatherMap’s current weather and 5-day forecast APIs.
Current weather is displayed in Grafana using the singlestat widget and the forecast is displayed using graphs.
The current weather is fetched twice every minute and the forecast is fetched only once on application start. The Forecast API provides datapoints at 3hr intervals. Forecast graphs are available for Temperature, Humidity, and Pressure at the moment, although the API provides access to much more data.
One of the first things our sample code does is to create the InfluxDB database. However, it's possible that this line of code runs before InfluxDB is actually up and running.
By default, the sample code performs 45 retries, 1 second apart, waiting for the DB to be available. If this is not long enough, you can change the value: int retries = 45;
The Openweather API key is referred to as appid
in the requests.
You'll need to update the API key in the demo code. This value is currently hardcoded and needs to be replaced at the following functions:
getowmforecast.setApiKey();
getowmcurrent.setApiKey();
You can also modify the geographic coordinates you want to receive the data by modifying the functions:
getowmforecast.setCity();
getowmcurrent.setCity();
Follow the instructions provided on Using Multiple Containers with TorizonCore - How to Use the Example - Configure Grafana. As you follow the steps:
collectd
to Weather
, which is the database name used in the current example.Weather-<timestamp>.json
from the sample directory:
Weather-<timestamp>.json
file from the weather sample directory.Weather
in the Name field and click import. The Dashboard is now ready.Using the Visual Studio Extension for Torizon and Visual Studio 2019 it is easy to set up a highly productive developer workflow for creating Torizon based apps. To demonstrate this, this article will:
Note: the example-specific information is presented at the end of the article on Example: Weatherboard with InfluxDB, Grafana and OpenWeatherMap
This article complies to the Typographic Conventions for Torizon Documentation.
To begin, see here a short video showing how easy is to debug C/C++ applications on Torizon devices using Torizon Extension with Visual Studio:
Then, let's go with our step-by-step guide with our sample application.
Create a new project using Visual Studio 2019.
Clone the Torizon samples and the InfluxDB C++ API repositories to your PC. Open a PowerShell and run:
$ git clone https://github.com/toradex/torizon-samples.git $ git clone https://github.com/awegrzyn/influxdb-cxx.git
Add the contents from Torizon samples to your project:
torizon-samples\weather\src\
to your project folder - you can use the Windows File Explorer to do it.Solution Explorer
(you can choose Delete
, not just Remove
).Add the contents from the InfluxDB C++ API to your project:
influxdb-cxx
inside your project folder - you can use the Windows File Explorer to do it.Attention: before proceeding, you may add your OpenWeatherMap API key to the example. See how to do it on How to Use the Example - Configure OpenWeatherMap.
With the WeatherSample
project selected on Solution Explorer
, click Project > Properties to edit the project level properties:
Additional Include Directories
to include the include and the influxdb-cxx\include folders.C++ Language Standard
to C++17 (-std=c++17)
. This specific C++ version is required for libraries in this example - your own project may require a different version of C/C++.Library Dependencies
:curl;pthread;boost_system;jsoncpp
Click on Apply --> Ok to close the Property Pages
.
The Torizon Visual Studio Development Tools Extension creates a new property window in any Torizon C/C++ Application
project. To open that window, click Project > WeatherSample > Properties... item and select the Torizon C/C++ Aplication
node. Be sure that All Configurations
and All Platforms
are selected at the top of the Property Pages
window:
Now drop down the value next to Configuration
in the main panel, and click <Properties...>
. This window allows you to configure the values that are ultimately passed to Docker to manage various aspects of the containers that will be built as part of the project. At the top, the Username
should be set to the default (torizon) and the Configuration should be Common
.
You can install development packages in the container that runs on the development PC to cross-build the application for the Toradex board (target device):
devpackages
row and click on Edit....devpackages
:libcurl4-openssl-dev:armhf libboost1.67-dev:armhf libboost-system1.67-dev:armhf libboost-test1.67-dev:armhf libboost-program-options1.67-dev:armhf libjsoncpp-dev:armhf
You can install extra packages
to be included in your application container that runs on the target:
extrapackages
row and click on Edit....extrapackages
:libcurl4 libboost-system1.67.0 libjsoncpp1
You can configure the container networking. To add/edit the values in the bottom section of the property window, simply click the ...
button, then click New
in the popup, and enter the value on the new row. For our example, add the following new value for the Networks:
setting in the property window:
#%application.id%#_backend
To orchestrate the containers bring-up, set up a docker-compose file. Click the "..."
button next to Docker-compose script:
and save it with the filename: docker-compose.yml.
docker-compose.yml
In the toolbar at the top of Solution Explorer
, toggle the button to Show All Files
if it is not already enabled. You will now see a folder in Solution Explorer
named appconfig_0. Expand that folder and open the docker-compose.yml file:
For our application, we'll need a total of 3 containers:
We'll also declare the networks and volumes we need, link the containers, and expose Grafana on port 3000.
docker-compose.ymlversion: '2.4' services: grafana: container_name: grafana depends_on: - influxdb networks: - backend - frontend volumes: - "grafana-storage:/var/lib/grafana" ports: - "3000:3000" links: - influxdb image: grafana/grafana:6.7.1 influxdb: container_name: influxdb networks: - backend volumes: - "influxdb-grafana:/var/lib/influxdb" image: influxdb:1.7.10 networks: backend: internal: true frontend: internal: false volumes: grafana-storage: influxdb-grafana:
Follow the steps from the article Visual Studio Extension for Torizon - Deploy and Debug
This is it, now you have a broader understanding of how to develop a C++ application for Torizon using Toradex's Visual Studio extension.
This section goes through aspects specific to the example, that are not applicable to other projects using the Visual Studio extension.
There are many weather APIs available, our sample uses the OpenWeatherMap’s current weather and 5-day forecast APIs.
Current weather is displayed in Grafana using the singlestat widget and the forecast is displayed using graphs.
The current weather is fetched twice every minute and the forecast is fetched only once on application start. The Forecast API provides datapoints at 3hr intervals. Forecast graphs are available for Temperature, Humidity, and Pressure at the moment, although the API provides access to much more data.
One of the first things our sample code does is to create the InfluxDB database. However, it's possible that this line of code runs before InfluxDB is actually up and running.
By default, the sample code performs 45 retries, 1 second apart, waiting for the DB to be available. If this is not long enough, you can change the value: int retries = 45;
The Openweather API key is referred to as appid
in the requests.
You'll need to update the API key in the demo code. This value is currently hardcoded and needs to be replaced at the following functions:
getowmforecast.setApiKey();
getowmcurrent.setApiKey();
You can also modify the geographic coordinates you want to receive the data by modifying the functions:
getowmforecast.setCity();
getowmcurrent.setCity();
Follow the instructions provided on Using Multiple Containers with TorizonCore - How to Use the Example - Configure Grafana. As you follow the steps:
collectd
to Weather
, which is the database name used in the current example.Weather-<timestamp>.json
from the sample directory:
Weather-<timestamp>.json
file from the weather sample directory.Weather
in the Name field and click import. The Dashboard is now ready.