Skip to main content

A python library for communication with IQRF Network

Project description

What is iqrfpy?

iqrfpy is a library that provides a python API for interacting with the IQRF network utilizing the DPA framework (DPA) or IQRF Gateway Daemon (Daemon) JSON API. Communication between a python runtime and the IQRF network is facilitated by transports.

For communication with Daemon, only the MQTT transport is implemented at this time. However, this library provides an abstract transport class, allowing for custom communication implementations.

The library provides classes for serialization of requests and deserialization of responses to message class objects.

Quick start

Before installing the library, it is recommended to first create a virtual environment. Virtual environments help isolate python installations as well as pip packages independent of the operating system.

A virtual environment can be created and launched using the following commands:

python3 -m venv <dir>
source <dir>/bin/activate

iqrfpy can be installed using the pip utility:

python3 -m pip install -U iqrfpy

Serialize requests to DPA:

from iqrfpy.peripherals.coordinator.requests.addr_info import AddrInfoRequest

req = AddrInfoRequest()
req_packet = req.to_dpa()
print(req_packet)

Serialize requests to JSON:

from iqrfpy.peripherals.coordinator.requests.addr_info import AddrInfoRequest

req = AddrInfoRequest()
json_req = req.to_json()
print(json_req)

Parse DPA responses:

from iqrfpy.peripherals.coordinator.responses import AddrInfoResponse
from iqrfpy.response_factory import ResponseFactory

def handle_addr_info_response(response: AddrInfoResponse) -> None:
    print(f'peripheral: {response.pnum}')
    print(f'peripheral command: {response.pcmd}')
    status = response.rcode
    if status == 0:
        print(f'Addr info response dev_nr: {response.dev_nr}')
        print(f'Addr info response did: {response.did}')


dpa_rsp_packet = b'\x00\x00\x00\x80\x00\x00\x00\x40\x0a\x2a'
dpa_rsp = ResponseFactory.get_response_from_dpa(dpa=dpa_rsp_packet)
handle_addr_info_response(response=dpa_rsp)

Parse JSON responses:

from iqrfpy.peripherals.coordinator.responses import AddrInfoResponse
from iqrfpy.response_factory import ResponseFactory

def handle_addr_info_response(response: AddrInfoResponse) -> None:
    print(f'peripheral: {response.pnum}')
    print(f'peripheral command: {response.pcmd}')
    status = response.rcode
    if status == 0:
        print(f'Addr info response dev_nr: {response.dev_nr}')
        print(f'Addr info response did: {response.did}')


daemon_rsp_json = {
    "mType": "iqrfEmbedCoordinator_AddrInfo",
    "data": {
        "msgId": "testEmbedCoordinator",
        "rsp": {
            "nAdr": 0,
            "hwpId": 0,
            "rCode": 0,
            "dpaVal": 64,
            "result": {
                "devNr": 0,
                "did": 42
            }
        },
        "insId": "iqrfgd2-1",
        "status": 0
    }
}
json_rsp = ResponseFactory.get_response_from_json(json=daemon_rsp_json)
handle_addr_info_response(response=json_rsp)

Documentation

For more information, check out our API reference.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iqrfpy-0.2.1.tar.gz (110.3 kB view details)

Uploaded Source

Built Distribution

iqrfpy-0.2.1-py3-none-any.whl (275.8 kB view details)

Uploaded Python 3

File details

Details for the file iqrfpy-0.2.1.tar.gz.

File metadata

  • Download URL: iqrfpy-0.2.1.tar.gz
  • Upload date:
  • Size: 110.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for iqrfpy-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a42efa51f74468592d97d1f4c2c17200f9d4ca46ded9daa730c88c63533b5c24
MD5 08a16cc318137202af593d1052f52fbd
BLAKE2b-256 4b7bbe6c0be8530f2b6c9022d5ac6d7a68e507ab894314976f9341070ffd7a34

See more details on using hashes here.

File details

Details for the file iqrfpy-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: iqrfpy-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 275.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for iqrfpy-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d76f0c4bb216f61adbba949bf6bc344249404d65e9869af40781b9b2d5b06bae
MD5 b5158c23a4ecc5783f8e73286388bfad
BLAKE2b-256 8911707682738ffad4ea6d8ccfa2ca9e42c5be5ec5ab0e16dfa416e1e9be38df

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page