The Azure IoT Field Gateway SDK is a set of libraries that allow you to build a device that acts as a proxy between an individual IoT device and Azure IoT Hub.
Individual IoT devices will connect to the Gateway via some transport layer (BLE, NFC, etc) and the Gateway will forward the device data to IoT Hub. The Gateway will usually aggregate many messages into a single message or convert it to a data protocol (MQTT, AMQP, etc) that IoT Hub understands.
Here’s how to get it the Field Gateway running on a Raspberry Pi 3.
Download Raspbian
I’m using Raspbian Jessie full desktop image.
Get a MicroSD Card and MicroSD USB Card Reader
I have a Kingston 32GB Class 10 MicroSD card and a Transcend USB 3.0 Card Reader
Install Win32DiskImager
This will be used to write Raspbian to the MicroSD card
https://sourceforge.net/projects/win32diskimager/
Copy Raspbian to MicroSD card
Open Win32DiskImager. Find the yyyy-mm-dd-raspbian-jessie.img file. Select your USB drive. Click Write. This took about 5 minutes on my machine.
Get Raspberry Pi Ready
Plug in HDMI monitor, keyboard, mouse and Ethernet cable (you can also use Wifi instead)
Configure Remote Access to Pi
TightVNC allows you to remote desktop into the Raspberry Pi from your Windows desktop. This step is optional. You could also just use the monitor, mouse and keyboard that is connected to the Pi, but that gets old quick. There are other options here, but I’ve found TightVNC to be the most reliable when you just need to connect to the Pi from the same wireless network. If the Pi is on a difference network, then use Weaved.
All your remote options are located here: https://www.raspberrypi.org/documentation/remote-access/. Feel free to use one that best suits your needs. SSH with Putty is a good option if you don’t need to access the desktop.
Go to Azure IoT Field Gateway SDK GitHub Page
If you are using TightVNC, on the Pi, open the web browser and go to http://bit.ly/azuregatewaypi – that will redirect you to this page on your Pi, so you can easily copy and paste the following commands.
If you are using SSH, then just execute the commands below in your SSH window.
Install Packages
sudo apt-get update
sudo apt-get install curl build-essential libcurl4-openssl-dev git cmake libssl-dev uuid-dev valgrind libglib2.0-dev`
Clone the Azure IoT Field Gateway Repo
You can clone into any directly you want. I usually put everything in a /code folder.
git clone --recursive https://github.com/Azure/azure-iot-gateway-sdk.git
Checkout the Develop Branch
This is the branch that contains a fix that allows the Gateway to be built on the Pi
git checkout develop
Init Submodules
I like to execute this command after I checkout a branch to be sure I have the latest submodule bits that correspond to my current branch.
git submodule update --init --recursive
Run Build.sh
Change to the /tools directory and excute build.sh
cd tools
./build.sh
This will take a while. Come back in 30 mins or so.
Test Failures
You will likely see these test failures, which are known issues reported on GitHub. The e2e tests fail because we didn’t setup the IoT Hub connection. That’ll be the topic of a different blog post.
The following tests FAILED:
27 - constbuffer_unittests (Failed)
34 - httpapiex_unittests (Failed)
41 - sastoken_unittests (Failed)
63 - mqtt_client_unittests (Failed)
77 - iothubclient_http_e2etests (Failed)
79 - iothubclient_mqtt_e2etests (Failed)
81 - iothubclient_amqp_e2etests (Failed)
109 - gw_e2etests (Failed)
Errors while running CTest
Copy JSON Settings File to Build Folder
From the root of the repo run this command to copy the sample JSON settings file to the build output folder.
cp ./samples/hello_world/src/hello_world_lin.json ./build/samples/hello_world/hello_world_lin.json`
Run Hello_World_Sample
Change to the /build folder
Run the following command to start the sample.
./samples/hello_world/hello_world_sample ./samples/hello_world/hello_world_lin.json
You should now see this output.
This sample writes an entry to the /build/log.txt file. If you open that file you will see the entries. From the /build folder just enter “vi log.txt” to view the file.
You now have the Azure IoT Gateway Running on a Raspberry Pi 3!
Error When Stopped
You might see this error when you stop the gateway – it appears that you can ignore it because it is still writing data to the log file.
Error: Time:Fri Aug 5 19:41:42 2016 File:/home/pi/code/azure-iot-gateway-sdk/deps/azure-c-shared-utility/src/consolelogger.c Func:consolelogger_log Line:31 byte array is not a gateway message serialization
Jon