1. Home
  2. Docs
  3. Zerynth Device Manager
  4. Demo projects
  5. Connect a Raspberry Pi or PC application to the Zerynth Device Manager

Connect a Raspberry Pi or PC application to the Zerynth Device Manager

How to connect Raspberry Pi and PC applications to the ZDM

Date: 03/2020  |. Version: 1.0

ZDM Client Python Library

What is it?

Zerynth Device Manager can be used for orchestrating both MCU (microcontroller) and CPU (microprocessor) based devices. If you want to connect an MCU device like a Raspberry PI, an SBC (Single Board Computer) a PC, or any Python application in general, the ZDM Client Python Library is what you need.

Installation

The latest stable version of the ZDM-Client Python Library is available on PyPI (https://pypi.org/project/zdm-client-py/)

The installation assumes that you have installed the latest Python version with pip.

In order to install the ZDM-Client Python Library, type the following command or add the zdm-client-py into the requirements.txt file.

Copy to Clipboard

If you want, you can also download the repository publicly available on GitHub.

Copy to Clipboard

navigate to the download repo directory and create a virtual env using the command

Copy to Clipboard

And install the python package locally.

Copy to Clipboard

Usage

Once you have installed the ZDM-client Python lib you can use it for connecting your CPU based device to the ZDM and stream your data.

Login to the ZDM in order to obtain the device id and the password of a device (see the ZDM getting started guide for more info) 

Create a new file zdm_basic.py and copy the following script and replace the obtained device id and password in the placeholders.

Copy to Clipboard

Type the command

Copy to Clipboard

Your first ZDM device will start sending random temperatures to three different tags (“tag1″, “tag2”, “tag3”) to the ZDM.

Jobs

In addition, the  ZDM-client Python lib permits also to define a set of jobs on the client that can be invoked by the ZDM.

The jobs are passed to the ZDMClient as a dictionary, where the key is the name of the job and the value is the corresponding function to execute.

The example below illustrates a simple example of a client exposing one job named set_temp.

Upon the device receiving the Job, it executes the corresponding function and returns a result of a JSON object.

Copy the following script into a new file hello_jobs.py.

Copy to Clipboard

Type the command

Copy to Clipboard

Now, you can schedule the job in two different ways: by using the ZDM UI or the ZDM CLI.

ZDM UI 

Steps needed to execute the job “set_led” on the device by using the ZDM UI:

  • Login to the ZDM (https://zdm.zerynth.com/login)
  • Click on the workspace where the device is associated.
  • On the section “My Devices”, click the checkbox of the device
  • Click on the button “Jobs”, and on the popup select the job Name “set_temp”  in the Job Name dropdown menu.
  • Add to the  “Arguments”  section any arguments of the function in json format (if any). For this example, you can leave the field empty.
  • Click on “Launch Job” button.

ZDM CLI

Steps needed to execute the job “set_led”  on the device by using the ZDM CLI.

Make sure you have configured the ZDM CLI (https://www.zerynth.com/blog/docs/the-tools/zdm/getting-started/).

In order to schedule the job, type the following command (where the DEVICE_ID must be substituted with the actual id of the device):

Copy to Clipboard

Expected result:

If the job has been correctly scheduled to the zdm client py, the following message will appear in the console:

Copy to Clipboard

That’s all! Edit the script file and build your own ZDM powered IOT project!