You can have a look at Telemetry
and its associated desktop implementation in python Pytelemetry
Main features
It is a PubSub-based protocol, but unlike MQTT it is a point-to-point protocol, no broker.
As any pubsub protocol, you can publish from one end on a topic
and be notified on the other end on that topic.
On the embedded side, publishing to a topic is as simple as :
publish("someTopic","someMessage")
For numbers:
publish_f32("foo",1.23e-4)
publish_u32("bar",56789)
This way of sending variables may seem limited, but the next milestone intends to add extra meaning to the topic's parsing by doing things like this :
// Add an indexing meaning to the topic
publish("foo:1",45) // foo with index = 1
publish("foo:2",56) // foo with index = 2
// Add a grouping meaning to the topic
publish("bar/foo",67) // foo is under group 'bar'
// Combine
publish("bar/foo:45",54)
This is good if you need to send arrays, complex data structures, etc.
Also, the PubSub pattern is great because of its flexibility. You can build master/slave applications, device to device, etc.
C library
The C library is very simple to add on any new device as long as you have a decent UART library on it.
You just have to instanciate a data structure called TM_transport
(defined by Telemetry
), and assign the 4 function pointers read
readable
write
writeable
.
// your device's uart library function signatures (usually you already have them)
int32_t read(void * buf, uint32_t sizeToRead);
int32_t readable();
int32_t write(void * buf, uint32_t sizeToWrite);
int32_t writeable();
To use Telemetry, you just have to add the following code
// At the beginning of main function, this is the ONLY code you have to add to support a new device with telemetry
TM_transport transport;
transport.read = read;
transport.write = write;
transport.readable = readable;
transport.writeable = writeable;
// Init telemetry with the transport structure
init_telemetry(&transport);
// and you're good to start publishing
publish_i32("foobar",...
Python library
On the desktop side, there is the pytelemetry
module that implements the protocol.
If you know python, the following code connects to a serial port, publishes once on topic foo
, prints all received topics during 3 seconds then terminates.
import runner
import pytelemetry.pytelemetry as tm
import pytelemetry.transports.serialtransport as transports
import time
transport = transports.SerialTransport()
telemetry = tm.pytelemetry(transport)
app = runner.Runner(transport,telemetry)
def printer(topic, data):
print(topic," : ", data)
options = dict()
options['port'] = "COM20"
options['baudrate'] = 9600
app.connect(options)
telemetry.subscribe(None, printer)
telemetry.publish('bar',1354,'int32')
time.sleep(3)
app.terminate()
If you don't know python, you can use the command line interface
Pytelemetry CLI
The command line can be started with
pytlm
Then you can connect
, ls
(list) received topics, print
data received on a topic, pub
(publish) on a topic, or open a plot
on a topic to display received data in real-time