Getting Started with Raspberry Pi and Yonomi's ThinCloud
By following the procedure below, anyone can get started with Raspberry Pi and ThinCloud. There are two parts to this tutorial: the installation procedure and setting up a ThinCloud test device. Make sure you are using the supported hardware kits and have all the prerequisites before getting started. Please note: before you continue with Part II in the tutorial, you will need to create a new instance with the Yonomi team. You can contact us here to do so.
Part I: Installation Procedure
Supported Hardware Kits:
Raspberry Pi 'A+' 'B', '3 B+', 2, 3, Zero W, Zero WH
Raspberry Pi 'A+' 'B', '3 B+', 2, 3, Zero W, Zero WH installed with Raspbian
In order to have your PI communicate with the cloud you would need to follow this installation procedure to successfully integrate with your Thincloud instance.
The preferred linux OS is Raspbian.
Installation instructions can be referenced from here: https://www.raspberrypi.org/downloads/raspbian/
The OS needs to be updated with the latest modules available. Run the following commands to update your Raspbian OS to latest.
The preferred way to install Node on the pi is by downloading the binary from nodesource based on your processor architecture i.e. armv7 and then installing it. Follow the steps blow to install NodeJS on your device.
**Note: at the time of this doc, Node 10.15 was the latest stable version of NodeJS. Check https://nodejs.org/en/ to see the latest and adjust the curl command to whatever version you are installing. For example, for an older version it was setup_8.x for the latest version of Node 8.
You can check your system info using the following command:
Certain node modules require git in order to be installed.
--*-- Don't install via git-all source
Setting up PM2
PM2 provides a way to manage your node processes. We prefer users to run node process via PM2 and let it do the heavy lifting to keep the process up and running. It provides a lot of out of the box functionality like starting process on boot and restarting when there is a system fault. It also provides performance metrics and insights into your processes.
Running Thincloud test-device
Yonomi provides a virtualized nodejs testing-device to do quick prototyping which uses the Thincloud-Device-SDK. The test-device can be used as a reference to build prototypes that implements Thincloud-Device-SDK
Thincloud-test-device can be cloned from our git repo.
Part II: Setting up Thincloud-test-device
Please note: Before you continue the tutorial, you will need to create a new instance with the Yonomi team. You can contact us here.
The test-device needs to be configured to be able to talk to your Thincloud instance. There are couple things you would need as prerequisite to configure your test-device to be able to successfully connect to your cloud.
AWS-IoT Certificate for your device *(Note: the certificate has 2 files <xxxx-certificate.pem.crt>, <xxxx-private.pem.key>)
AWS-Iot broker details. This can be retrieved from the AWS-IoT console form the settings tab i.e <xxxxxxxxxxxxx.iot.us-west-2.amazonaws.com>
Thincloud deviceType i.e. 'Bulb/Hub/Gateway'
Test-device has a configuration file that requires to be modifed based on your Thincloud-instance. The configuration file is located in your project root under config i.e <thincloud-test-device/config/device.config.json>
The config file requires the certificates path and the host information to be able to connect to your Thincloud instance. The other properties functionality can be referenced from the Thincloud-Device-SDK docs.
The certificates can be placed on int your project root directory and can be referenced as shown above if its the root of your project. The host information is the AWS-IoT broker info that needs the SDK needs to point to the specific aws-iot instance. The region also needs to be the same as the host region.
The directory structure looks something like this for the files you would need to modify:
You can start your test-device by simply running it through npm. you can use the npm start script that we have provided with out client.
Running the test-device using this command is good for debugging/quick prototyping but not great for running a process that needs its lifecycle to be managed.
Running Test-device using PM2
The preferred way to run the test-device is by having PM2 manage your process. This can be done by executing following command
you can also setup pm2 to automatically boot/restart your process by executing the following commands
this command will generate a command as such:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi
this needs to be executed for PM2 to be added to systemd which basically starts PM2 when the devices is powered on
You need to save the running process in order for PM2 to know which of your process to boot
Performance and Monitoring Tools
There are several tools available for performance and monitoring. We recommend using the following tools due to their easy to configure and remote monitoring features. *(Note: These services are third party and are paid services. They do have a limited free version.)
Setting up Keymetrics (PM2) Remote Monitoring:
This is very useful to monitor your node process. Its very easy to integrate with your test-device
Setting up DataDog OS monitoring:
DataDog agent can be installed on your linux client and can be monitored remotely. Follow the reference below to integrate DataDog with your device.
About the Author
Hassan Khokhar is a Senior Software Engineer at Yonomi. During his time here, he has been responsible for developing and architecting our next level enterprise IoT cloud management platform and loves every minute of it. He previously worked for Deloitte digital as a Senior Consultant and holds a degree from Metropolitan State University in Electrical Engineering.
Are You Building a Connected Device?
Learn more about what it takes to get your device connected with our free Guide to Building a Connected Device.