pytelemetry
provides high-level communication with any embedded device for
remote control and monitoring.
Specifically, pytelemetry
implements a custom communication protocol, based on
the PubSub
(Publish/Subscribe) messaging pattern.
telemetry
is the C implementation
of the protocol. It can run on any embedded system, along with official
distributions for Arduino and ARM Mbed.
pytelemetrycli
is a powerful command line interface to interact with
embedded devices using the protocol. It enables instant data visualization
of any received data, full logging of communications, health monitoring
of the serial port and much more.
Data is exchanged on named communication channels called topics
.
First, instanciate one of the available transport class (Note: so far, only serial transport is implemented) and the Pytelemetry
object.
from pytelemetry import Pytelemetry
from pytelemetry.transports.serialtransport import SerialTransport
import time
# create a transport (Here based on pyserial) to exchange data through serial port
transport = SerialTransport()
# Top level Pytelemetry api
tlm = Pytelemetry(transport)
# Connection to serial port `COM20` at `9600` bauds.
transport.connect({'port': "com20", 'baudrate': 9600})
Publish once to topic named throttle
, sending effectively the value 0.8
of type float
to the embedded device.
# publish on a topic
tlm.publish('throttle',0.8,'float32')
Subscribe a printer
function to all received topics.
Basically, this function will be called every time a new frame is received.
def printer(topic, data, options):
print(topic," : ", data)
# subscribe to a topic. Subscribing to None subscribes to all
tlm.subscribe(None, printer)
Then, run an update during 3 seconds and disconnect after.
# Update during 3 seconds
timeout = time.time() + 3
while True:
tlm.update()
if time.time() > timeout:
break
# disconnect
transport.disconnect()
print("Done.")
If the embedded device published regularly on topic foo
with an incrementing value, you should see in the console:
foo : 34
foo : 35
foo : 36
foo : 37
Done.
Python 3.3 and upward is supported. Python 2.x is not supported for now.
pip3 install pytelemetry
foo:2
. '2' is used here for the index, the value is provided inside the payload.In the next milestone, it is planned to make topics more meaningful (on the python-implementation only).
bar\foo
, will add group data. This will indicate that there is a group called bar
, with a subtopic called foo
bar\foobar\foo
,bar\foobar\foo:2
bar\12\foo
will be understood as foo
instance number 12 (useful if you want to have multiple instances under a same topic name)For both python and C implementations of the protocol, it is also planned:
replace the byte stuffing algorithm by a consistent-over byte stuffing algorithm
Both will contribute to reduce overhead and frames size.