iqrfpy
iqrfpy
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.
Changelog
Version: 0.2.11
Release date: 22.05.2025
Changes
- Added support for Standard Sensor Action (
Action) quantity
Version: 0.2.10
Release date: 15.09.2024
Changes
- Added support for Particulates PM40 (
ParticulatesPM40) quantity
Version: 0.2.9
Release date: 05.09.2024
Changes
Commonmethodlist_to_hex_stringseparator parameter now defaults to whitespaceCommonmethodlist_to_hex_stringuppercase parameter now defaults toTrue
Version: 0.2.8
Release date: 08.07.2024
Changes
SensorParsernow rounds converted sensor data to quantity-specified number of decimal digits
Version: 0.2.7
Release date: 23.05.2024
Changes
- Removed unused extra package metadata
Version: 0.2.6
Release date: 23.05.2024
Changes
- Added support for Activity Concentration (
ActivityConcentration) quantity
Version: 0.2.5
Release date: 18.04.2024
Changes
- Updated support for diagnostics module renamed to
iqd_diagnosticsfromdiagnostics
Version: 0.2.4
Release date: 16.04.2024
Changes
- Added support for
iqrfpy-diagnosticsauto-import
Version: 0.2.3
Release date: 15.04.2024
Changes
- Added
get_tr_series_strclass methods toTrDTypesandTrGTypes - Renamed
McuTypesclass methodget_mcu_codetoget_mcu_code_str
Version: 0.2.2
Release date: 15.04.2024
Changes
- Added missing imports for
InitPhyDataandTrMcuTypeData - Fixed
tr_seriesparsing inTrMcuTypeData
Version: 0.2.1
Release date: 14.04.2024
Changes
- Added
InitPhyDatadata class - Replaced raw
init_phyvalue ofReadTrConfResponsewithInitPhyData, the raw value is now accessible asvaluemember ofInitPhyData - Added
TrMcuTypeDatadata class - Renamed
tr_typemember ofOsReadDatatotr_mcu_type - Replaced raw
tr_mcu_typevalue ofOsReadDatawithTrMcuTypeData, the raw value is now accessible asvaluemember ofTrMcuTypeData - Added a new
OsTrConfDatastatic methodcalculate_checksumto calculate checksum from TR configuration data - Utility class
Commonmethodlist_to_hex_stringnow accepts parametersseparatoranduppercase - Added new utility class
Commonmethodsbcd_to_decimal,dpa_build_date_to_str,dpa_version_to_strandfletcher_checksum - Added new DPA utility enum classes
McuTypes,TrDTypes,TrGTypesandRfBands - Added a new
ResponseCodesclass methodis_ok_response - Fixed
ResponseCodesmethodto_stringto correctly return string representation of DPA confirmation status code - Added a metaclass for enums for use of the
inoperator, removed thehas_valuemethod - Added missing docstrings
Version: 0.2.0
Release date: 02.04.2024
Changes
- Added peripheral submodules level imports for request, response and data classes
- Added autoloading
extsubmodule for extensions and plugins - Renamed
AuthorizeBondParamstoCoordinatorAuthorizeBondParams - Renamed
DpaParamtoCoordinatorDpaParam - Renamed
PeripheralEnumerationDatatoExplorationPerEnumData - Renamed
PeripheralInformationDatatoExplorationPerInfoData - Renamed
OsIndicateControltoOsIndicateParam - Renamed
OsSecurityTypetoOsSecurityTypeParam - Moved
BinaryOutputState,CoordinatorAuthorizeBondParams,CoordinatorDpaParams,ExplorationPerEnumData,ExplorationPerInfoData,FrcParams,IoTriplet,NodeReadData,NodeValidateBondsParams,OsBatchData,OsIndicateParam,OsLoadCodeFlags,OsReadData,OsSecurityTypeParam,OsSleepParams,OsTrConfByte,OsTrConfData,SensorDataandSensorWrittenDatadata classes toobjectssubmodule - Removed
transportssubmodule,ITransportis not available from the root module - Removed
MqttTransport,MqttTransportParam,MqttTransportParamsErrorandMqttTransportConnectError, they are now available from theiqrfpy-mqtt-transportpackage, accessible underiqrfpy.ext.mqtt_transportif installed - Removed
paho-mqttandtypeguarddependencies
Version: 0.1.58
Release date: 12.03.2024
Changes
- Differentiate parsing of peripheral enumeration from OS Read response
Version: 0.1.57
Release date: 04.03.2024
Changes
- Updated paho-mqtt requirement version in setup tools
Version: 0.1.56
Release date: 02.03.2024
Changes
- Locked paho-mqtt requirement version down to
<2.0
Version: 0.1.55
Release date: 14.01.2023
Changes
- Change float NaN to None in
SensorParser
Version: 0.1.54
Release date: 12.12.2023
Changes
- Added python 3.12 to project classifiers
Version: 0.1.53
Release date: 12.12.2023
Changes
- Updated Sensor constant and dataclass names to match IQRF Sensor Standard
Version: 0.1.52
Release date: 17.11.2023
Changes
- OS
TestRfSignalResponse: Updatedget_countvalue format.
Version: 0.1.51
Release date: 8.11.2023
Changes
- OS
TestRfSignalResponse: Addedget_countmethod that returns string representation of counter value
Version: 0.1.50
Release date: 6.11.2023
Changes
- MqttTransport: Client connect errors are now raised as
MqttTransportConnectError - Renamed
MqttParamsErrortoMqttTransportParamsError
Version: 0.1.49
Release date: 3.11.2023
Changes
- Added OS FactorySettings, LoadCode and TestRfSignal messages and response factories
- Added missing tests for Sensor
ReadSensorResponse - Minor fixes of tests, added
Response_Factorytests
Version: 0.1.48
Release date: 31.10.2023
Changes
- OS TR configuration data now stores reserved data blocks
Version: 0.1.47
Release date: 31.10.2023
Changes
- Fixed OS
BatchRequestandSelectiveBatchRequestdata length validation - Fixed OS TR configuration data embedded peripherals parsing
Version: 0.1.46
Release date: 17.10.2023
Changes
- Added getter methods for
OsTrConfDatamembers - Fixed RAM
WriteRequestdata length validation
Version: 0.1.45
Release date: 13.10.2023
Changes
- Added OS Batch, SelectiveBatch, Indicate and WriteTrConfByte messages and response factories
- Added generic serialization and deserialization methods for requests and responses
- Deduplicated serialization and deserialization code of messages
- Removed unused imports
Version: 0.1.44
Release date: 29.08.2023
Changes
- Fixed
GenericResponseparsing methodfrom_dpa
Version: 0.1.43
Release date: 29.08.2023
Changes
- Allow user peripheral numbers to be used in messages
Version: 0.1.42
Release date: 28.08.2023
Changes
MqttTransportmethodsend_and_receivenow returnsNoneif request address isIQMESH_TEMP_ADDR(254) orBROADCAST_ADDR(255).
Version: 0.1.41
Release date: 25.08.2023
Changes
- Added parameter to response factory from dpa to allow use of GenericResponse in case of unknown peripheral number or peripheral command.
Version: 0.1.40
Release date: 25.08.2023
Changes
- Added docstrings across the library
- Added Binary Output standard messages and response factories
- Added a
GenericRequestandGenericResponsemessages - Added IO constants to
dpautility module - Updated return types across the library
- Changed response messages' data return types to
Optionalfor situations where request was not handled successfully - Fixed some codestyle, doc style and linter errors
- Removed some unused auxiliary methods
Version: 0.1.39
Release date: 07.08.2023
Changes
- Reworked factory methods
- Updated typeguard dependency
Version: 0.1.38
Release date: 07.08.2023
Changes
- Fixed typeguard version to 4.0.0
Version: 0.1.37
Release date: 01.08.2023
Changes
- Added
FrcCommandsenum to DPA utils - Added
FrcParserclass - Updated
SensorFrcErrorsenum to use strings and added factory method from integer values
Version: 0.1.36
Release date: 31.07.2023
Changes
- Fixed FRC commands of
TemperatureFloatandLengthquantities
Version: 0.1.35
Release date: 31.07.2023
Changes
- Changed
Powerquantity short name - Added
TemperatureFloatandLengthquantities - Fixed data block parsing data in
SensorParser - Fixed FRC data conversion errors
Version: 0.1.34
Release date: 30.07.2023
Changes
- Removed unused Sensor FRC request
- Added missing 2bit FRC command to
BinaryData7quantity
Version: 0.1.33
Release date: 20.07.2023
Changes
- Added missing quantities to
SensorParsermethodfrc_convert - Fixed data block parsing in
SensorParser - Removed trailing comma in
TimeSpanquantity definition - Fixed
short_namemember inShortLengthquantity definition
Version: 0.1.32
Release date: 19.07.2023
Changes
- Fixed a bug where
PeripheralEnumerationresponse data was parsed byPeripheralInformationresponse factory - Added
coordinator_shiftparameter tobitmap_to_nodesmethod to ignore first bit - Updated
BondedDevicesandDiscoveredDevicesresponses to parse only first 30 bytes of PDATA
Version: 0.1.31
Release date: 10.07.2023
Changes
- Fixed a bug where EEEPROM responses were handled by EEPROM response factories
Version: 0.1.30
Release date: 01.07.2023
Changes
- Updated
Temperaturequantity short name fromttoT - Added EEEPROM, RAM and IO peripherals
- Added missing submodule imports
- Fixed validation of EEPROM
WriteRequestdata length
Version: 0.1.29
Release date: 28.06.2023
Changes
- Fixed conversion of temperature measurement from 1B FRC data in
SensorParser - Removed a debug print from Thermometer
Readresponse
Version: 0.1.28
Release date: 27.06.2023
Changes
- Fixed return type hint of Sensor
ReadSensorsresponse factory methods - Added missing type hint to
ResponseCodesmethodto_string - Separated quantity data from
sensor_parsermodule intoquantity_datamodule - Sensor parsing methods now raise
UnknownSensorTypeErrorinstead ofValueError - Updated docstrings for utils submodule
Version: 0.1.27
Release date: 24.06.2023
Changes
- Added validation of
dpa_rsp_timeanddev_process_timeIRequest properties - Fixed Sensor FRC error codes handling
- Fixed trimming of
frc_datainfrc_dpamethod ofSensorParser, the method now assumesfrc_datadoes not include status byte - Fixed 2B FRC data conversion in
SensorParser - Reworked data trimming by FRC data size in
SensorParser - Added parsing of 2b FRC responses to
SensorParser
Version: 0.1.26
Release date: 22.06.2023
Changes
- Added
dev_process_timeparameter to request classes - Changed
timeoutparameter of request classes todpa_rsp_time - Added Sensor
ReadSensorsrequest (without types) - Added parsing method for
ReadSensorsresponse and FRC responses - Updated typeguard dependency version
ResponseCodesmethodto_stringnow includes flags
Version: 0.1.25
Release date: 18.06.2023
Changes
- Added FRC peripheral requests, responses, response factories and DPA constants
- Added Sensor Enumerate and Read requests, responses, response factories
- Added Sensor parser and types
- Fixed incorrect OS
WRITE_CFGresponse command value - Refactored OS
ReadTrConfResponseandWriteTrConfRequestdata into a single class, added serialization and deserialization methods - Replaced regular getter and setter methods with
@propertydecorators (response.get_rcode()->response.rcode) - Updated Exploration
PeripheralInformationResponseandMorePeripheralsInformationResponseclasses to work with basic JSON API response data instead of results for the purposes of matching DPA and JSON API responses
Version: 0.1.24
Release date: 31.05.2023
Changes
- Added Node peripheral commands
- Added OS peripheral commands reset, restore,
- Added new Node and OS peripheral imports to
messages - Added new Node and OS peripheral response factories
- Changed
UartOpenRequestto accept baud rate parameter as bothBaudRatesenum member and integer - Changed
OsReadDataparameter fromresulttodata - Removed unnecessary result fetching in
from_jsonfactory method ofClearAllBondsResponse - Fixed parameter types of
AsyncResponse - Updated error message in
response_lengthDPA validator - MqttTransport now does not wait for responses to broadcast messages
- Added more constants to
dpautils
Version: 0.1.23
Release date: 25.05.2023
Changes
- Updated
ResponseCodesmethodto_stringmessages. - Moved UART baud rate enum from UART Open request to
dpasubmodule.
Version: 0.1.22
Release date: 23.05.2023
Changes
- Fixed rcode value comparison condition in
ResponseCodesmethodto_string
Version: 0.1.21
Release date: 22.05.2023
Changes
- Added check for values out of range to
ResponseCodesmethodto_string - Fixed missing return statements
Version: 0.1.20
Release date: 20.05.2023
Changes
- Added missing DPA error constants to
ResponseCodes - Added string representation of
ResponseCodesvalues andto_stringclassmethod - Used ResponseCodes constants throughout the library where unused
Version: 0.1.19
Release date: 17.05.2023
Changes
- Added Device Exploration (unfinished due to pending changes in IQRF Gateway Daemon), UART and Thermometer peripheral request, responses and response factories
- Added
terminatemethod toMqttTransportto disconnect client and stop event loop peacefully - MQTT transport initialization now waits for subscription confirmation instead of connection confirmation
Version: 0.1.18
Release date: 10.05.2023
Changes
- Added
is_connectedmethod toMqttTransport - Fixed matching of sent requests and received responses in MQTT transport
- MQTT transport now distinguishes DPA request timeout without user-specified timeout, DPA request timeout with user-specified timeout, JSON request timeout
Version: 0.1.17
Release date: 09.05.2023
Changes
- Fixed validation of
IRequestparameternadr
Version: 0.1.16
Release date: 03.05.2023
Changes
- Added setters for EEPROM requests
- Fixed generation of random UUID message ID for requests
- Separated DPA and JSON timeout in MQTT transport
- Added optional timeout parameter to requests
Version: 0.1.15
Release date: 02.05.2023
Changes
- Fixed
peripheralsmodule submodule imports
Version: 0.1.14
Release date: 27.04.2023
Changes
- Changed module tree structure
iqrfpy.messages.requests.<peripheral>->iqrfpy.peripherals.<peripheral>.requestsiqrfpy.messages.responses.<peripheral>->iqrfpy.peripherals.<peripheral>.responses
- Moved
async_response,confirmation,irequest,iresponseandresponse_factorysubmodules toiqrfpymodule - Renamed
peripheral_messagessubmodule tomessages - Added specific peripheral submodule imports to
periphralsubmodule - Added missing submodule imports
- Added
send_and_receivemethod overloads for individual requests and responses toMqttTransport
Version: 0.1.13
Release date: 26.04.2023
Changes
- Added EEPROM peripheral requests, responses and response factories
- Added EEPROM peripheral to
Commonclass auxiliary methods - Changed
response_factoryCoordinator response imports to named namespace import - Added
iqrfpy.peripheral_messagesmodule containing imports and wildcard import for all available requests and responses - Simplified validation of request parameters, deferring much of the work to the DPA layer
Version: 0.1.12
Release date: 24.04.2023
Changes
- Added LEDG peripheral requests, responses and response factories
- Fixed undefined variable warning when selecting a response factory
- Added wildcard imports to
iqrfpy.exceptionsmodule - Added
iqrfpy.utils.validatorsmodule containing validator classes for DPA and JSON responses - Updated validation of DPA and JSON responses in factory methods
- Added optional timeout parameter to
receivemethod ofMqttTransport MqttTransportonmessage callback now checks if received JSON API response indicates DPA request timeout
Version: 0.1.11
Release date: 20.04.2023
Changes
- Added
LOCAL_DEVICE_ADDRandBROADCAST_ADDRconstants toiqrfpy.utils.dpamodule - Added
list_to_hex_stringauxiliary method toCommonclass - Changed
IRequestvalidation ofnadrto include local device, temporary iqmesh and broadcast addresses - Added
OsReadFlagsandOsReadSlotLimitsdataclasses - Added response data getters to OS
ReadResponse
Version: 0.1.10
Release date: 20.04.2023
Changes
- Added missing wildcard imports to
response_factorymodule - Removed
synchronousparameter fromMqttTransport MqttTransportnow passes received message to user-specified callback regardless of communication mode- Implemented method
send_and_receiveofMqttTransport
Version: 0.1.9
Release date: 20.04.2023
Changes
- Added OS
ReadResponseresponse factory - Added synchronous MQTT transport communication
- Added
TransportNotConnectedErrorandMessageNotReceivedErrorexceptions
Version: 0.1.8
Release date: 19.04.2023
Changes
- Unified class file name and class name cases
- Moved validation of
AuthorizeBondRequestparameters toAuthorizeBondParamsclass - Added validation of
AuthorizeBondParamscount toAuthorizeBondRequest - Added LEDR peripheral requests, responses and response factories
- Added OS peripheral Read request and response
- Added exceptions for unsupported peripherals and peripheral commands
ResponseFactorymethods now throw relevant exceptions when an unknown or unsupported peripheral or peripheral command is processed- Added method
send_and_receivetoITransport - Added abstract method decorators to
ITransportmethods - Added
MqttTransportParamsdataclass and removed individual parameters fromMqttTransportconstructor - Added asynchronous MQTT transport communication
- Added docstrings for enums
Version: 0.1.7
Release date: 17.04.2023
Changes
- Added
receiveandconfirmationmethods toITransport
Version: 0.1.6
Release date: 15.04.2023
Changes
- Added module
iqrfpy.utils.dpacontaining DPA constants - Replaced magical constants throughout the source code with named DPA constants
- Exposed request and response submodules imports
Version: 0.1.5
Release date: 07.04.2023
Changes
- Added module
iqrfpy.exceptionscontaining custom exceptions - Replaced generic Error types with custom exceptions
Version: 0.1.4
Release date: 06.04.2023
Changes
ITransportmethods now raiseNotImplementedError- Added
set_receive_callbackmethod toITransport - Removed
receiveandreceive_asyncmethods fromITransport
Version: 0.1.3
Release date: 02.04.2023
Changes
- Added
AuthorizeBondParamsdataclass forAuthorizeBondRequest - Added validation of
AuthorizeBondRequestparameters - Added response factory for
AuthorizeBondResponse
Version: 0.1.2
Release date: 27.03.2023
Changes
- Added wildcard imports for response factories
Version: 0.1.1 (unreleased)
Release date: N/A
Changes
- Unified module name cases
- Added typechecking for classes
- Added enum class
IntEnumMemberwithhas_valuemethod - Changed existing integer enums to extend
IntEnumMember - Added response factories to parse DPA and JSON responses into response objects
- Renamed
dataparameter todpain DPA response factory methods - Renamed
dataparameter tojsonin JSON response factory methods - Moved
IRequestclass torequestsmodule - Moved
AsyncResponse,ConfirmationandIResponseclass toresponsesmodule - Added more auxiliary methods to
Commonclass
Version: 0.1.0 (unreleased)
Release date: N/A
Changes
- Basic project structure
- Added peripheral enums
- Added peripheral request and response command enums
- Added message type enums
- Added class Common providing auxiliary functions
- Added abstract classes for requests, responses and transports
- Added asynchronous responses
- Added confirmation message
- Added Coordinator peripheral requests and responses
- Added MQTT transport
- Added simple tests for Coordinator peripheral, enums and Common class