This documentation shows how to download and use different IoT device SDKs.
Installing and Using County IoT Raspberry Pi SDK
Countly Raspberry Pi SDK is one of the Countly iOT SDK families which sends data to a Countly server. After this SDK sends data to Countly, you can visualize it on dashboard. Server takes care of both storing data and visualizing it for you so you can get more insights from your devices.
If device doesn’t have internet connection, and cannot send data, SDK stores this data and then sends to queue. Items in this queue is then sent one by one after internet connection is established.
You can add your Raspberry Pi Python SDK to your project in two different ways.
1st method: Getting the code from Github
Command below copies SDK from Github directly to your computer. It needs git command to be available on your operating system.
git clone https://github.com/Countly/countly-sdk-iot.git .
Now you can copy Countly.py command to your project folder:
cp raspberry_pi/Raspberry_SDK/Countly.py your_project_folder
In order to import Countly in Python, use this line in your example py file:
from yourpackage.Countly import Countly
2nd method: Download using pip, easy Python installer
If you have pip command installed on your system, you may run the following command. This easily installs Countly SDK into your system, so you can directly call it inside your app.
pip install Raspberry_SDK
In order to use Countly SDK in your Python app, you can add it like:
from Raspberry_SDK.Countly import Countly
Using County IoT Raspberry Pi SDK
To initiate SDK without timer,
countly = Countly("SERVER_URL", "APP_KEY", 0)
where server_URL is the IP or name of the server, and APP_KEY is the application key that you retrieved from dashboard once you create the application.
To initiate timer with a frequency, use the following:
countly = Countly("SERVER_URL", "APP_KEY", TIMER_SECOND)
In order to send a specific event, use a command as follows:
The best method to retrieve data from Raspberry Pi GPIO is to use Grove interface. Grove is basically a ready to use toolset to ease use of SPI, I2C, UART in analog and digital circuits. Prepared by Seeed Studio, it includes several sensors, I/O units, switches, lights and joysticks.
Grove works not only with Raspberry Pi, but also several industrial, well-known development boards like Arduino, Intel Edison, Beagle Bone Green. For more information about Grove, click the link here. To use Grove in Raspberry Pi, a shield-like card called Grove Pi is used.
In order to use Grove sensors and Grove Pi shield, create an account on Countly. An App Key is automatically created for you. We’ll use this key inside the SDK in relevant place.
Raspberry Pi configuration
You can find necessary configuration about how to use Python and Grove with Raspberry Pi. We need this configuration, so start reading and implementing what is written here.
After installing Grove, you can install Countly SDK:
pip install Raspberry_SDK
In our example scenario, we have a light sensor. This sensor is connected to Grove input Analog 0. After configuring Grove Pi and Grove light sensors, the following code can be used to send light sensor data to Countly servers:
import threading import grovepi from raspberry_pi.Raspberry_SDK.Countly import Countly light_sensor = 0 countly = Countly("SERVER_URL", "APP_KEY", 0) def grove(): threading.Timer(30,grove).start() countly.event("Light", int(grovepi.analogRead(light_sensor)/10.24)) grove()
Now you have completed with sending data from Raspberry Pi to your server.