Before 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.
Configuring Your Simulated Device
- Open a terminal window on the Raspberry Pi and ensure that the date and time are correct by using the
date
command:
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.date
- Enter the following command:
sudo apt-get install libssl-dev
Description of the illustration dwninst_02.png - Enter the following commands:
export IOTCS_OS_NAME="Raspbian GNU/Linux"
export IOTCS_OS_VERSION="8"
The variable
os_name
andos_version
are used to get the activation policy. - Click the earth icon to open the Epiphany web browser. If you are not in graphical mode, then enter
startx
to start the GUI.Description of the illustration dwninst_03.png - Open the Oracle IoT Cloud Service Client Software Library downloads page.
- Locate the binary file for C POSIX Client Software Library and download the zip file to your home directory (
/home/pi
). - To extract the content of the
iotcs-csl-posix-bin-release.zip
file, use theunzip
command.Description of the illustration dwninst_06.png The files are extracted into the subdirectory
iotcs
.
Sending Your First Message
- In the
bin
directory, copy this C POSIX programhello_world_sample.c
to create a basic simulator application. - 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
-
Move
libdeviceclient.a
located at lib/arm/ intoiotcs/csl/posix
folder. - 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
- 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.
- 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>
Verify Your Message
- Sign in to the Oracle IoT Cloud Service instance.
- On the Oracle IoT Cloud Service home page, go to the Oracle IoT Asset Monitoring application.
- Select Data, and then in Filter By, select Device.
- Find your message and verify that Message Content contains the update to the attribute to the value "Hello World!".
Description of the illustration runsampl_03.png