flespi.io panel is great. It not only shows all flespi platform elements with their properties and counters, but also features elaborate tools for debugging the communication with devices: logs and messages nicely show in Toolbox, devices location is available in the adjacent TrackIt tab, and configuration commands will depart to your devices after a few mouse clicks.
How flexible can it be?
However, flespi is a platform for developers. And developers love to customize. So if you want to create your own panel (excluding unnecessary information from flespi and including your own stuff) — it’s up to you. And providing you with a tool to build your own flespi panel more efficiently — it’s up to us.
What info does a developer need to build a panel? Obviously, the object’s data to show.
What is the easiest way to get object’s data? Most likely, perform REST API GET object call.
What problem must one solve to keep data consistent between flespi panel and custom solution? Apparently, object’s data is dynamic, so developer needs to track changes and update the data accordingly.
At this point, most developers would agree that hanging REST API calls in the pulling mode is not the most effective solution. The alternative is faster and more usable. Let me introduce to you a special MQTT topic — flespi/state/#.
How does it work?
Any complex object consists of simple components. Let’s consider a simple parameter from a single flespi object to show the idea of flespi/state topic. E.g. we want to monitor the number of active connections to your flespi channel. What you need to do is create a channel on your flespi account and then do the following:
Subscribe to the topic
flespi/state/gw/channels/your_channel_id/connections_count
Receive the current number of active connections as a retained message for this topic.
Open TCP connection to the channel’s URI — you will receive a new MQTT message with a new counter value.
What data can I get?
Following is the table describing the fields that can be retrieved for objects from gateway and storage modules. There are two levels of topics for flespi/state:
flespi/state/<module>/<instance_type>/<instance-id>
— you will receive a JSON with the required properties of the instance specified.flespi/state/<module>/<instance_type>/<instance-id>/<property-name>
— you will receive only the value of the property specified.
module-name/ | instance-type/instance-id/ | property-name/ | |
required | optional | ||
gw | channels | id name commands_ttl configuration enabled messages_ttl protocol_id URI | blocked commands_size connections_count messages_size |
devices | id name device_type_id ident messages_ttl phone telemetry | messages_size connected | |
streams | id name configuration enabled queue_ttl | queue_size connected | |
modems | id name configuration enabled priority | ||
storage | containers | id, flags, name | blocked, size |
abques | id, name | blocked, size | |
CDNs | id, name | blocked, size |
Examples:
Subscribe | Receive |
flespi/state/storage/containers/654321 | {"flags":1,"id":654321,"name":"flespi_state_test"} — required object parameters, no optional fields |
flespi/state/+/+/+/id | Receive all ids of your objects. Identify each object type by topic in the received message |
flespi/state/storage/+/+/size | Size of all objects in the storage module |
Who will find this useful?
You are working on a huge project where multiple people can edit the flespi elements. You won’t need to refresh the page to see the most up-to-date information.
Showing the live numbers of objects/connections/messages can be a good marketing initiative building credibility for your business. E.g. the number of units connected to Wialon or the number of units online — https://gurtam.com/en/gps-hardware — just sum the values from the topics flespi/state/gw/channels/+/connections_count.
You have a high-load project and use flespi close to the usage limits. To track blocked objects in real-time use topic flespi/state/+/+/+/blocked.
***
As you can see, flespi MQTT API gives plenty of flexibility in getting the exact data you need. Be it for customer-facing tasks or internal operations, you can show the numbers that make meaning to the respective audience and not overload them with unnecessary “noise”.
Also, check our comprehensive flespi MQTT API guide!