-
Notifications
You must be signed in to change notification settings - Fork 27
Publish arrays and complex structures
It is possible to use a specific syntax for topics that enables publishing arrays and sparse arrays.
Let's see it in practice. To publish a 16 items array of floating point values to topic qux
, all you need to do is to make the following calls in your Telemetry-enabled embedded code.
publish_f32("qux:0", 7.5);
publish_f32("qux:1", 6.1);
publish_f32("qux:2", 9.6);
publish_f32("qux:3", 4.5);
//..
publish_f32("qux:15", 8.3);
See what happened there ? Using the two-points character :
as a delimiter, you can provide under the same topic multiple indexes.
The Python implementation natively understands this syntax, and also the plots opened by the command line interface. You have nothing special to do.
For instance, in the command line interface, if you open a plot by typing plot qux
, the plot will not display the evolution of qux in time, but instead it will plot the y value 7.5
received with qux:0
at x = 0
.
- At
x = 1
,y = 6.1
- At
x = 2
,y = 9.6
- At
x = 3
,y = 8.3
- etc.
It is possible to compact the publishing code by using a loop
float values[16] = {7.5, 6.1, 9.6, 4.5, ...,8.3};
// A buffer for storing our topic in a loop.
// Don't forget to add enough numbers to reserve enough space.
// Here we go up to 2 digits (16 entries) so we use '00'
char [] topic = "qux:00";
for(uint32_t i = 0 ; i < 15 ; i++)
{
// Create the topic
sprintf(topic,"qux:%u",i);
// Publish
publish_f32(topic, values[i]);
}
Notes:
- topics indexes don't have to follow one another. You can publish in this order
cos:3
,cos:1
,cos:2
- topics indexes can be sparse.
cos:12
,cos:45
,cos:18
To be done
Group variables using foo\bar
.
Back Wiki home
- Fast data visualization with the command line interface (todo)
- Fast prototyping remote program control with python (todo)
- Overview of the library
- Protocol description
- All the good stuff inside Telemetry
- List of supported platforms
- Good practices (Must-read !) in writing
- Frequently Asked Questions todo
- List of official examples
- List of projects using telemetry