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.
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.
If you want, you can also download the repository publicly available on GitHub.
navigate to the download repo directory and create a virtual env using the command
And install the python package locally.
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.
Type the command
Your first ZDM device will start sending random temperatures to three different tags (“tag1″, “tag2”, “tag3”) to the ZDM.
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.
Type the command
Now, you can schedule the job in two different ways: by using the ZDM UI or the ZDM CLI.
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.
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):
If the job has been correctly scheduled to the zdm client py, the following message will appear in the console:
That’s all! Edit the script file and build your own ZDM powered IOT project!