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.
$ 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
Add the contents from the InfluxDB C++ API to your project:
influxdb-cxxinside 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.
WeatherSample project selected on
Solution Explorer, click Project > Properties to edit the project level properties:
Additional Include Directoriesto include the include and the influxdb-cxx\include folders.
C++ Language Standardto
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++.
Click on Apply --> Ok to close the
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
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):
devpackagesrow and click on Edit....
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:
extrapackagesrow and click on Edit....
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:
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.
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.
version: '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.
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:
You can also modify the geographic coordinates you want to receive the data by modifying the functions:
Follow the instructions provided on Using Multiple Containers with TorizonCore - How to Use the Example - Configure Grafana. As you follow the steps:
Weather, which is the database name used in the current example.
Weather-<timestamp>.jsonfile from the weather sample directory.
Weatherin the Name field and click import. The Dashboard is now ready.