LED display with Cloudgate

  • LED display with Cloudgate

 

0. Introduction

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

Difficulty:

Ingredients

Music to listen: Jamie Woon - Night air

TOP

1. Project Schema

This project covers a robust way to communicate LED pannels to the Internet with a Cloudgate

Here is overall diagram of the project:

  • Schema

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.

TOP

2. Development environment

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

TOP

3. Implementing source code

Carriots device

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 @myusername. For example MX23D4F5KP@testcloudgate

Apikey

Now, go to your control panel “My account menu” and check your Apikey.
Its a big alphanumeric token like:
98346673a6377ef1fde2357ebdcb0da582b150b00cabcd5a0d83045425407ab4.
You will need this number to complete the tutorial.

Source code

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:

TOP

4. Adding the program to the watchdog

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.

TOP

5. Compiling

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.

TOP

6. Deploying the image to the Cloudgate

After this process our image will be available in the bin/imx28 folder. It's named bundle-sdk-.zip. If you found several files in this folder due to previous compilations, you have to use the most recent one

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

TOP

7. Testing

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:

TOP

8. From here on: Enhancing the project

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
TOP