Overdrivr / pytelemetry

High level communication protocol with embedded devices
MIT License
17 stars 6 forks source link

PyPI version Join the chat at https://gitter.im/Overdrivr/pytelemetry Stories in Ready Windows Build status Linux Build Status

pytelemetry

Overview

Usage

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.

Installation

Python 3.3 and upward is supported. Python 2.x is not supported for now.

pip3 install pytelemetry

Advanced features

Future improvements

In the next milestone, it is planned to make topics more meaningful (on the python-implementation only).

For both python and C implementations of the protocol, it is also planned: