Oracle by Example brandingQuick Start Tutorial Using a C POSIX Application on a Raspberry Pi

section 0Before You Begin

This tutorial shows you how to build the C POSIX Client Software Library sample on a Raspberry Pi, a credit-card sized computer. Then you will build and run a C POSIX application that simulates a device sending a message to Oracle Internet of Things (IoT) Cloud Service. This tutorial takes approximately 20 minutes to complete.

Background

This tutorial assumes that you have already performed the tasks in Setting up a Raspberry Pi Device to Run Oracle IoT Cloud Service Software.

This tutorial also assumes that you have attached a keyboard and monitor to the Raspberry Pi . The command windows shown are those provided by the Raspberry Pi graphical user interface. You can also use telnet or another shell client such as PuTTY for Windows to access the Raspberry Pi from your host system.

What Do You Need?

  • Access to an Oracle IoT Cloud Service instance
  • A computer running Windows 7, Mac OS 10.9 or Ubuntu 14.04.3 LTS, or later.
    Note: This tutorial assumes that you are using a Windows 7 OS. If you have a system that is running native Linux, then the steps will be similar to those on the Raspberry Pi device.
  • Raspberry Pi Model B Revision 2, Model B+ or later, power supply, Ethernet cable.
  • A USB keyboard and mouse and an HDMI cable and monitor
  • Firefox or Chrome web browser. You may use the Epiphany web browser on the Raspberry Pi.
  • This C code file: hello_world_sample.c
  • The latest version of the C POSIX Client Software Library from Oracle Technologies Network
  • Complete the following tutorial: Configuring an Application in Oracle Internet of Things Cloud Service.

section 1Configuring Your Simulated Device

  1. Open a terminal window on the Raspberry Pi and ensure that the date and time are correct by using the date command:
    date
    If the date or time is not correct, ensure that your Raspberry Pi has access to the Internet, as explained in Configuring the Raspberry Pi for Internet Access section, in the Setting up a Raspberry Pi Device to Run Oracle IoT Cloud Service Software tutorial.
  2. Enter the following command:
    sudo apt-get install libssl-dev
    Raspberry pi console
    Description of the illustration dwninst_02.png
  3. Enter the following commands:
    export IOTCS_OS_NAME="Raspbian GNU/Linux"
    export IOTCS_OS_VERSION="8"

    The variable os_name and os_version are used to get the activation policy.

  4. Click the earth icon to open the Epiphany web browser. If you are not in graphical mode, then enter startx to start the GUI.
    Raspberry Pi web browser icon
    Description of the illustration dwninst_03.png
  5. Open the Oracle IoT Cloud Service Client Software Library downloads page.
  6. Locate the binary file for C POSIX Client Software Library and download the zip file to your home directory (/home/pi).
  7. To extract the content of the iotcs-csl-posix-bin-release.zip file, use the unzip command.
    Raspberry pi console
    Description of the illustration dwninst_06.png

    The files are extracted into the subdirectory iotcs.


section 2Sending Your First Message

  1. In the bin directory, copy this C POSIX program hello_world_sample.c to create a basic simulator application.
  2. Compile the c program you downloaded in the previous step.
    gcc -g -I../include -I../lib/arm -o ./hello_world_sample.out ./hello_world_sample.c -Wl,-Bstatic -L../lib/arm -liotdeviceclient -Wl,-Bdynamic -lssl -lcrypto -lm -lrt -lpthread -ldl -lz
  3. Move libdeviceclient.a located at lib/arm/ into iotcs/csl/posix folder.
  4. Verify that your program was successfully compiled by checking that the directory where your C program resides also contains the file hello_world_sample.out
  5. Copy the Provisioning file obtained from the tutorial in the pre-requisites (Configuring an Application in Oracle Internet of Things Cloud Service) into that directory.
  6. Open a command prompt and run the following command in the same directory, replacing <file protection password> with the password you used to create the provisioning file.
    ./hello_world_sample.out <provisioning.file> <file protection password>

section 3Verify Your Message

  1. Sign in to the Oracle IoT Cloud Service instance.
  2. On the Oracle IoT Cloud Service home page, go to the Oracle IoT Asset Monitoring application.
  3. Select Data, and then in Filter By, select Device.
  4. Find your message and verify that Message Content contains the update to the attribute to the value "Hello World!".
    Messages board
    Description of the illustration runsampl_03.png

more informationWant to Learn More?