Skip to content

Connecting a C.H.I.P. Board

Follow the instructions below to connect your device to the Cloud4RPi control panel.

Prerequisites

It is advisable to update your system before installing.

sudo apt update && sudo apt upgrade -y

Install/update the required packages.

sudo apt install git python python-pip -y

You can use alternative methods to install pip.

Note

The Cloud4RPi library is compatible with Python 2.7.9+ and Python 3.2+ versions.

Getting the Cloud4RPi Client Library

Install the library using your preferred Python version. The following command installs and integrates Cloud4RPi with your OS's default Python interpreter (usually Python 2):

sudo pip install cloud4rpi

If you are using Python 3, use the following command:

sudo python3 -m pip install cloud4rpi

Note

For information on how to work with several versions of Python installed, see Python Documentation.

If you get an error while using pip, try to update the setuptools and pip packages.

sudo pip install --upgrade setuptools pip

Hacking Together some Code

We have prepared sample code for several platforms in the cloud4rpi-chip-python repository to demonstrate sending data to the Cloud.

Get Cloud4RPi examples for your device:

git clone https://github.com/cloud4rpi/cloud4rpi-chip-python.git && cd cloud4rpi-chip-python

Before running a sample (control.py), remember to replace the __YOUR_DEVICE_TOKEN__ string with your real device token. Use a text editor (for instance, nano) to replace __YOUR_DEVICE_TOKEN__ with the token displayed at the top of the device page on cloud4rpi.io. If you have no token yet, open the Devices page, create a device using the New Device button in the top right corner, and use its token.

Note

Install the CHIP_IO Python library as described in its documentation to use the C.H.I.P.'s GPIO subsystem from Python. If you do not need GPIO, remove the import CHIP_IO.GPIO as GPIO line and all GPIO references from the control.py example.

Running

Execute the script with the Python interpreter, for example:

sudo python control.py

Note

If you have installed Cloud4RPi to a non-default Python, use the version with the Cloud4RPi library.

If the script output looks right, open the Devices page to see if the device status has changed.

Installing as a Service

You can use our service templates to facilitate service installation. Pass the path to your Cloud4RPi-enabled Python script to the service_install.sh script as a parameter.

chmod +x service_install.sh
sudo ./service_install.sh your_script.py

Note

You need to replace 'your_script.py' with the actual path to your service script.