A simple, lightweigtht and ready to use Python package
Purpose - visualise time series data locally
Most IoT data is generated at the edge and collected by an industrial edge controller. This data is often visualised in the backend with solutions such as Grafana. However, in many production scenarios or proof of concepts there is an additional demand to visualise data at the point of origin with a local plot server. Due to the limited memory and CPU resources this mandates a simple and lightweight solution preferably running in memory only. This is why qbee.io created the Python package plot_server that allows anyone to have a local data visualisation running in no time.
We recently had a joint project together with Moxa where the edge device was the UC-2100 industrial gateway with 256MB of RAM. There it was no option to install Grafana locally and have an additional Influx database which stores the time series measurements. Hence, we have developed the plot_server module that is now available as an open source Python package.
Within this joint project with Moxa we were able to read Modbus input signals and send them to the plot server running locally on the edge gateway. We were using qbee-connect to access the device and the plot server running on port 8080.
How it works - introducing the Python plot server
The plot server is an http server written in Python running on a user-defined port (by default 8080). The server has a REST API through which the server can be be fed with payloads through POST requests. These payloads contain the corresponding measurement tag together with the measurement value and an optional unit and timestamp parameter. If the timestamp is left out, then the time of ingestion is used. A sample payload looks like this:
"tag": "Temperature - Room 1",
The server stores the data points of each measurement in memory and in order not to consume the entire available memory after inserting more and more data points the plot server only stores (a configurable) maximum number of points per measurement. Therefore, it is very resource efficient and doesn’t need an additional database running in the background. Also the file system is not utilized. The Python package is built on http.server which is contained in Python’s standard library. The only dependencies are on one additional Python package, namely python-dateutil, making it easy to deploy and allowing for correct timestamps in local browser time.
How to get it
Deploying the plot server on your edge device is fairly simple. All you need is a Python installation (>=3.5) together with the package manager pip. Then, you can simply run:
$ pip3 install http-plot-server
To configure the server you can either supply the following command line parameters
or simply put them in a config file called param.cfg (for example) and start the server specifying the path to this file:
$ python3 -m plot_server --cfg=param.cfg
The package is only 10,3KB large (*.whl file) and contains the following dependencies on the standard library: