- 0. Introduction
- 1. Project Schema
- 2. Development environment
- 3. Implementing source code
- 4. Adding the program to the watchdog
- 5. Compiling
- 6. Deploying the image to the Cloudgate
- 7. Testing
- 8. From here on: Enhancing the project
- LED display with Cloudgate
This tutorial will show you how to connect a LED display panel to Carriots platform using Option’s CloudGate gateway.
We will learn how to:
- Control a serial port with Cloudgate
- Deploy your projects on a Cloudgate
- Communicate with Carriots with C language
- 1 x Option's CloudGate: Option.com
- 1 x Industrial serial expansion card: Option.com
- 1 x LED display panel with RS232 port: Displaymatic
- Serial cable RS 232 -> RJ 11: Equinox
Music to listen: Jamie Woon - Night air
This project covers a robust way to communicate LED pannels to the Internet with a Cloudgate
Here is overall diagram of the project:
User can send any message to Carriots that will be displayed on the LED panel. CloudGate performs an active polling to Carriots to pull the text to be displayed and its display mode.
We will assume that you have your account at Carriots and also an account at the CloudGate Universe and you have upgraded it to developer.
To develop apps with CloudGate you will need a computer with Linux installed and common development tools (make, getopt, gcc, ncurses, etc.). You will find the complete list at their website: http://cloudgate.option.com/en/sdk-getting-started
The SDK configuration tool will warn you if the necessary dependencies are missing. Note that in many cases the developer versions of these packages are required.
When the development machine is ready, you have to download the SDK tarball file at cloudgate.option.com -> Developer tools -> Releases -> SDK version XXXX (as for this tutorial it was CloudGate-SDK-x86_64-v1.23.0.tar). Choose the corresponding file to your development environment: 32 bits or 64 bits. Open it and then enter the recently created folder where you will find:
- 'include': buildsystem scripts related to OpenWRT/buildroot.
- 'keys': contains the developer key for signing the resulting image.
- 'config': contains all configuration files that can be bundled with the resulting image.
- 'package': this is where development will take place & you will create your own applications.
- 'scripts': OpenWRT-related scripts.
- 'target': contains various platform specific settings.
- 'staging_dir': this directory contains several things:
- Binaries of host tools: toolchain + various host-tools that are necessary to create an image.
- Binaries of compiled packages.
- Header files that are needed for some package to compile. For example, say package A depends on header files of package B: package B will compile first, put the header files in the staging dir. After that, package A can compile.
- The resulting, assembled filesystem.
What we want to spot is:
- 'packages': where we will put our source code
- 'bin/imx28': where the images are dropped after compilation
If youre registered in Carriots, you have a default device already created for you.
Check your control panel and see what it looks like.
Basically you need the device id_developer that must be something like
Now, go to your control panel “My account menu” and check your Apikey.
Its a big alphanumeric token like:
You will need this number to complete the tutorial.
We will implement a package called carriots_RS232_display. For that we will create a folder with the same name in packages folder.
Default CloudGate development environment includes C standard libraries (stdlib, string, stdio, math, etc.), so it will be quite simple to develop and port applications to the platform.
To work with JSON messages needed in Carriots communication we will use cJSON library (http://sourceforge.net/projects/cjson/). It's a light library written in ANSI-C, easily portable to different architectures. To use it, just download the files and copy cJSON.c and cJSON.h to carriots_RS232_display folder.
Communication with the LED display will be done using /dev/ttySP0 device, which corresponds to the serial port at the industrial serial expansion board. It’s written in send2display.c file using common C functions used to write on file descriptors.
This is carriots_RS232_display.c source code:
main function is located in carriots_RS232_display.c file. Device must be identified in Carriots as serial_number@user where serial_number must replaced by your CloudGate serial number.
The program presents an architecture based on two processes:
- Child process: will run constantly status_stream_forked function which purpose is to send status streams to Carriots.
- Parent process: will ask Carriots for the last stream and will display its contents in the LED display panel.
This is carriots_RS232_display.c source code:
CloudGate platform has a watchdog to monitor applications and services. As a supervisor it will watch processes to re-launch them in case they’re dead or to start them at boot time.
To include our package in the controlled set of applications we have to add the following lines to config/config/clients file:
On a new environment you might have to create this file, as it may not exist or is empty.
We made a bundle with the source code, makefiles and folders to download it: carriots_RS232_display.zip. Unzip it in the package folder.
To start the compilation process we invoke the command make menuconfig from the development environment’s main folder. It will show you the common ncurses compilation environment.
- ncurses environment
Going to the Base system option we will see our carriots_RS232_display program available. To add it to the image that we will generate we have to mark it <*>
- Base system packages
After that we can exit the environment. Compilation will be launched by invoking the make command. It will automatically create the image to upload to the Cloudgate.
After this process our image will be available in the bin/imx28 folder. It's named bundle-sdk-
This file can be uploaded using CloudGate’s web interface or using Option’s platform. Using Cloudgate's web interface you have to access the Cloudgate's local IP address with a browser.
- Cloudgate login
- Cloudgate upload
- Cloudgate restart
To test the deployment you have to send a status stream to your device at Carriots. You will find some examples in other tutorials: Send stream tutorial
This is an example of a stream. Put your text, speed and display mode:
You can create a listener that will send messages to LED display with Groovy code:
Now you know how to connect a Cloudgate with Carriots and to control LED display using a serial port. You can enhance this project in many ways:
- Try to make other devices interact automatically with the LED display by creating listeners.
- Create your own control panel to send messages to the LED display, by building an HTML page with a status request to Carriots