Messages¶
The messages payload are encoded using the postcard format and has a maximum of 64 bytes.
Low level messages¶
Altough most functionality is available as a high level API on the nodes it is still possible to send messages manually. To send a message to a node use the function Node.send_msg().
Example:
node = nm.get_node("01020304-3e00-4800-1650-4b5332393420")
# Switch endpoint 1 to 100%
msg = ActuatorOutput(endpoint_id=u8(1), value=f32(100.0))
node.send_msg(msg)
If the message is of the type request
you can send and wait for the reply using Node.send_and_wait().
Example:
node = nm.get_node("01020304-3e00-4800-1650-4b5332393420")
# Request info about the endpoint 1 in the node
endpoint_info = await node.send_and_wait(
Msg.EndpointInfoRequest(endpoint_id=u8(1))
)
API reference¶
- class ActuatorOutput(endpoint_id: pypostcard.types.u8, value: pypostcard.types.f32)¶
- MSG_ID = 7¶
- MSG_TYPE = 2¶
- endpoint_id: u8¶
- value: f32¶
- class ArbitrationId(prio: bool, dst: int, master: bool, src: int, multiframe: bool, msg_type: int, msg_id: int)¶
- static decode(id: int)¶
- dst: int¶
- encode()¶
- master: bool¶
- msg_id: int¶
- msg_type: int¶
- multiframe: bool¶
- prio: bool¶
- src: int¶
- class EndpointClass(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
- Input = 1¶
- NotSupported = 0¶
- Output = 2¶
- class EndpointConfigRequest(endpoint_id: pypostcard.types.u8, config_no: pypostcard.types.u8, config: pypostcard.types.List[pypostcard.types.u8, 32])¶
- MSG_ID = 8¶
- MSG_TYPE = 0¶
- config: List[u8, 32]¶
- config_no: u8¶
- endpoint_id: u8¶
- class EndpointInfoRequest(endpoint_id: pypostcard.types.u8)¶
- MSG_ID = 5¶
- MSG_TYPE = 0¶
- endpoint_id: u8¶
- class EndpointInfoResponse(id: pypostcard.types.u8, endpoint_class: pypostcard.types.Enum[pypostcard.types.u8, openhydroponics.msg.EndpointClass], endpoint_sub_class: pypostcard.types.u8)¶
- MSG_ID = 5¶
- MSG_TYPE = 1¶
- endpoint_class: Enum[u8, EndpointClass]¶
- endpoint_sub_class: u8¶
- id: u8¶
- class EndpointInputClass(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
- EC = 3¶
- Humidity = 2¶
- NotSupported = 0¶
- Temperature = 1¶
- class HeartbeatWithIdRequest(counter: pypostcard.types.u32, uuid: pypostcard.types.List[pypostcard.types.u8, 16])¶
- MSG_ID = 2¶
- MSG_TYPE = 0¶
- counter: u32¶
- uuid: List[u8, 16]¶
- class IdSet(uuid: pypostcard.types.List[pypostcard.types.u8, 16])¶
- MSG_ID = 3¶
- MSG_TYPE = 0¶
- uuid: List[u8, 16]¶
- class Msg(msg_id: MsgId, msg_type: MsgType)¶
- static decode(arb: ArbitrationId, data: bytes)¶
- static encode(msg: Any) bytes ¶
- messages = {(MsgId.Heartbeat, MsgType.Value): <class 'openhydroponics.msg.Heartbeat'>, (MsgId.HeartbeatWithIdRequest, MsgType.Request): <class 'openhydroponics.msg.HeartbeatWithIdRequest'>, (MsgId.IdSet, MsgType.Request): <class 'openhydroponics.msg.IdSet'>, (MsgId.NodeInfo, MsgType.Value): <class 'openhydroponics.msg.NodeInfo'>, (MsgId.EndpointInfo, MsgType.Request): <class 'openhydroponics.msg.EndpointInfoRequest'>, (MsgId.EndpointInfo, MsgType.Response): <class 'openhydroponics.msg.EndpointInfoResponse'>, (MsgId.SensorReading, MsgType.Value): <class 'openhydroponics.msg.SensorReading'>, (MsgId.ActuatorOutput, MsgType.Value): <class 'openhydroponics.msg.ActuatorOutput'>, (MsgId.EndpointConfig, MsgType.Request): <class 'openhydroponics.msg.EndpointConfigRequest'>}¶
- class MsgId(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
- ActuatorOutput = 7¶
- EndpointConfig = 8¶
- EndpointInfo = 5¶
- Heartbeat = 1¶
- HeartbeatWithIdRequest = 2¶
- IdSet = 3¶
- NodeInfo = 4¶
- SensorReading = 6¶
- class MsgType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
- Request = 0¶
- Response = 1¶
- Value = 2¶