Basic ALH access¶
The following classes provide basic access to the resources on sensor nodes available through the ALH protocol.
ALH protocol implementations¶
-
class
vesna.alh.
ALHTerminal
(f)¶ ALH protocol implementation through a serial terminal.
This implementation is used for testing and debugging when a sensor node is connected directly to a computer over a serial line.
Parameters: f – path to the character device of the terminal (usually an instance of the serial.Serial
class)-
get
(*args, **kwargs)¶ Issue a GET request to the service.
Raises an ALHException in case of an error.
Parameters: - resource – resource to issue request to
- args – arbitrary string arguments for the request
Returns: vesna.alh.ALHResponse
object
-
post
(*args, **kwargs)¶ Issue a POST request to the service
Raises an ALHException in case of an error.
Parameters: - resource – resource to issue request to
- data – POST data to attach to the request
- args – arbitrary string arguments for the request
Returns: vesna.alh.ALHResponse
object
-
-
class
vesna.alh.
ALHWeb
(base_url, cluster_id)¶ ALH protocol implementation through the HTTP infrastructure server.
ALHWeb is typically used to access the coordinator of a ZigBee mesh network.
If the API end-point is using basic authentication, you will be prompted for credentials on the command line.
You can also save credentials into either a file named .alhrc in your home directory or alhrc in the current directory. Format of the file is as in the following example:
Host example.com User <username> Password <password> # more Host, User, Password lines can follow
Parameters: - base_url – base URL of the HTTP API (e.g. https://crn.log-a-tec.eu/communicator)
- cluster_id – numerical cluster id
-
get
(*args, **kwargs)¶ Issue a GET request to the service.
Raises an ALHException in case of an error.
Parameters: - resource – resource to issue request to
- args – arbitrary string arguments for the request
Returns: vesna.alh.ALHResponse
object
-
post
(*args, **kwargs)¶ Issue a POST request to the service
Raises an ALHException in case of an error.
Parameters: - resource – resource to issue request to
- data – POST data to attach to the request
- args – arbitrary string arguments for the request
Returns: vesna.alh.ALHResponse
object
-
class
vesna.alh.
ALHProxy
(alhproxy, addr)¶ ALH protocol implementation through an ALH proxy.
This implementation forwards arbitrary ALH requests through the “nodes” resource on an ALH service used as a proxy.
ALHProxy is typically used to access nodes on the ZigBee mesh network behind the coordinator.
Parameters: - alhproxy – ALH implementation used as a proxy
- addr – ZigBee address of the node to forward requests to
-
get
(*args, **kwargs)¶ Issue a GET request to the service.
Raises an ALHException in case of an error.
Parameters: - resource – resource to issue request to
- args – arbitrary string arguments for the request
Returns: vesna.alh.ALHResponse
object
-
post
(*args, **kwargs)¶ Issue a POST request to the service
Raises an ALHException in case of an error.
Parameters: - resource – resource to issue request to
- data – POST data to attach to the request
- args – arbitrary string arguments for the request
Returns: vesna.alh.ALHResponse
object
Response class¶
-
class
vesna.alh.
ALHResponse
(content)¶ This class represents the response of a resource handler.
The ALH protocol does not define the encoding of strings passed thorugh it. It can be used for binary data as well. In practice however, most strings are 7-bit ASCII. Hence this class provides ASCII-decoded form of the response for convenience, as well as the undecoded binary.
-
text
¶ Text form of the response (ASCII).
-
content
¶ Binary form of the response (
bytes
object on Python 3).
-