After playing with my Raspberry Pi 2 for a while, I figured that it may be good to take it to the next level by looking into the Internet of Things (IoT). The concept IoT is pretty simple which is basically to upload data from sensors (Telemetry data) to the cloud for monitoring and analytics purposes. So, I just need to be looking at how I can upload some JSON data to a cloud storage.
Since I have some basic working knowledge with Azure and since Microsoft has started supporting other platforms on Azure, I was thinking to maybe to skip Windows 10 IoT and try to get Azure working on my Pi2 with Python and Raspbian instead.
Fortunately, I found out that there is an Azure SDK for Python from Microsoft. Although it is still in RC, it is already quite usable. Installing the Azure SDK for Python is straight forward on the Pi2. Simply enter the following in a Terminal:
sudo pip3 install --pre azure
Note: I used pip3 because I am using Python 3.5.1.
I believe with the Azure SDK installed, we should somewhat be able to fulfill the basic requirements of uploading data to Azure storage. I have yet to test it because during the course of my research, I had found something even more awesome. Microsoft has actually released something called Azure IoT Suite and Azure IoT Hub. Not only does it allow you to upload telemetry data to the cloud but it also allows you to manage/control your devices from the cloud. To my delight, there is also an Azure IoT Device SDK for Python.
Going through all the hands on tutorials on the Azure IoT Hub site, I was convinced that I could use this on my Pi2. I tried to install the Azure IoT Device SDK on my Pi2 and this time it was not really that straight-forward anymore because most of the instructions were either for Windows or Ubuntu but fortunately, I got it working and here's how you can do it...
Step #1 Clone the Repository
Create a folder in your home directory on your Pi. I called mine Sources. Open a Terminal and navigate to the folder i.e. ~/Sources, then type:
sudo git clone --recursive git://github.com/Azure/azure-iot-sdks.git
After it is done, you will see an azure-iot-sdks directory inside your Sources.
Step #2 Increase Swap File size
This is an important step. You need to do this or the compilation will fail.
The swap file configuration is located in /etc/dphys-swapfile. You can edit it using any text editor. I will be using nano to do it.
sudo nano /etc/dphys-swapfile
locate the line:
CONF_SWAPSIZE=100
and change it to:
CONF_SWAPSIZE=1024
Save the file.
Note: As I am a noob in Linux, I do not know what other side-effects the above settings will cause. If you are worried about it, you can always change it back after everything is done.
After you have messed with the settings, you need to restart the swap:
/etc/dphys-swapfile stop
/etc/dphys-swapfile start
Note: It will take some time and it will look like everything is hanging and not responding but please don't panic.
Step #3 Build the Azure IoT Device SDK for C
Yes, you read it correctly. You need to build the sdk for C first. Make sure you have cmake version 3.x or higher and gcc version 4.9 or higher. If you are working on a new Raspberry Pi and have just installed Raspbian, you should be good to go.
Change to the ~/Sources/azure-iot-sdks/c/build_all/linux directory
Run:
./setup.sh
and after that, run:
./build.sh
You can get these instructions from here.
Step #4 Fix the make file.
If you proceed to follow the instructions given on the github site to compile the python iothub_client, you will get the following error:
To solve the problem, edit the CMakeLists.txt file by loading it in a text editor:
sudo nano ~/Sources/azure-iot-sdks/python/device/iothub_client_python/CMakeLists.txt
The line you are looking for is (Line 41 at time of writing):
find_package(Boost COMPONENTS "python-py${boost_python}" REQUIRED)
Change it to:
find_package(Boost COMPONENTS "python" REQUIRED)
Save the file.
Step #5 Build the Python IoTHub Client
Change to the ~/Sources/azure-iot-sdks/python/build_all/linux directory:
Run:
./setup.sh --python-version 3.5
Then:
./build.sh --build-python 3.5
You can find the detail instructions here.
Get Started!
Now you can go to the ~/Sources/azure-iot-sdks/python/device/samples and start your journey into IoT.
If you find all the electronics stuff in Raspberry Pi too intimidating and just want to jump straight to IoT, I will advice that you get a Raspberry Pi Sense HAT. It comes with all the basic sensors which is sufficient enough for you to explore Azure IoT and make your audience go wild in IoT presentations.
You can get it from element14.
Good luck and have fun!
Since I have some basic working knowledge with Azure and since Microsoft has started supporting other platforms on Azure, I was thinking to maybe to skip Windows 10 IoT and try to get Azure working on my Pi2 with Python and Raspbian instead.
Fortunately, I found out that there is an Azure SDK for Python from Microsoft. Although it is still in RC, it is already quite usable. Installing the Azure SDK for Python is straight forward on the Pi2. Simply enter the following in a Terminal:
sudo pip3 install --pre azure
Note: I used pip3 because I am using Python 3.5.1.
I believe with the Azure SDK installed, we should somewhat be able to fulfill the basic requirements of uploading data to Azure storage. I have yet to test it because during the course of my research, I had found something even more awesome. Microsoft has actually released something called Azure IoT Suite and Azure IoT Hub. Not only does it allow you to upload telemetry data to the cloud but it also allows you to manage/control your devices from the cloud. To my delight, there is also an Azure IoT Device SDK for Python.
Going through all the hands on tutorials on the Azure IoT Hub site, I was convinced that I could use this on my Pi2. I tried to install the Azure IoT Device SDK on my Pi2 and this time it was not really that straight-forward anymore because most of the instructions were either for Windows or Ubuntu but fortunately, I got it working and here's how you can do it...
Step #1 Clone the Repository
Create a folder in your home directory on your Pi. I called mine Sources. Open a Terminal and navigate to the folder i.e. ~/Sources, then type:
sudo git clone --recursive git://github.com/Azure/azure-iot-sdks.git
After it is done, you will see an azure-iot-sdks directory inside your Sources.
Step #2 Increase Swap File size
This is an important step. You need to do this or the compilation will fail.
The swap file configuration is located in /etc/dphys-swapfile. You can edit it using any text editor. I will be using nano to do it.
sudo nano /etc/dphys-swapfile
locate the line:
CONF_SWAPSIZE=100
and change it to:
CONF_SWAPSIZE=1024
Save the file.
Note: As I am a noob in Linux, I do not know what other side-effects the above settings will cause. If you are worried about it, you can always change it back after everything is done.
After you have messed with the settings, you need to restart the swap:
/etc/dphys-swapfile stop
/etc/dphys-swapfile start
Note: It will take some time and it will look like everything is hanging and not responding but please don't panic.
Step #3 Build the Azure IoT Device SDK for C
Yes, you read it correctly. You need to build the sdk for C first. Make sure you have cmake version 3.x or higher and gcc version 4.9 or higher. If you are working on a new Raspberry Pi and have just installed Raspbian, you should be good to go.
Change to the ~/Sources/azure-iot-sdks/c/build_all/linux directory
Run:
./setup.sh
and after that, run:
./build.sh
You can get these instructions from here.
Step #4 Fix the make file.
If you proceed to follow the instructions given on the github site to compile the python iothub_client, you will get the following error:
CMake Error at /usr/share/cmake-3.0/Modules/FindBoost.cmake:1198 (message):
Unable to find the requested Boost libraries.
Unable to find the requested Boost libraries.
Boost version: 1.55.0
Boost include path: /usr/include
Could not fine the following Boost libraries
boost_python-py35
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the locations of Boost.
I have filed it as an issue. I'm not sure if you will get the error if you are using python 2.7. I didn't bother to try. The error will mislead you into thinking you have a bad libboost installation but trust me, it is not.To solve the problem, edit the CMakeLists.txt file by loading it in a text editor:
sudo nano ~/Sources/azure-iot-sdks/python/device/iothub_client_python/CMakeLists.txt
The line you are looking for is (Line 41 at time of writing):
find_package(Boost COMPONENTS "python-py${boost_python}" REQUIRED)
Change it to:
find_package(Boost COMPONENTS "python" REQUIRED)
Save the file.
Step #5 Build the Python IoTHub Client
Change to the ~/Sources/azure-iot-sdks/python/build_all/linux directory:
Run:
./setup.sh --python-version 3.5
Then:
./build.sh --build-python 3.5
You can find the detail instructions here.
Get Started!
Now you can go to the ~/Sources/azure-iot-sdks/python/device/samples and start your journey into IoT.
If you find all the electronics stuff in Raspberry Pi too intimidating and just want to jump straight to IoT, I will advice that you get a Raspberry Pi Sense HAT. It comes with all the basic sensors which is sufficient enough for you to explore Azure IoT and make your audience go wild in IoT presentations.
You can get it from element14.
Good luck and have fun!