Monitor Method¶
@bp.method('device.monitor')
This method will provide the layout and the data monitored from the device to the user interface. At the moment there is only the Plotly library supported. You will have to implement the layout as well as the data representation according to the Plotly documentation.
In order to make the dashboard work you will need to enable it in device.json. Plus you need to enable it when registering or editing the device in the user interface.
Parameters¶
There is one parameter passed to this function which contains the information of the requested option:
def record(option :str) -> str:
layout¶
The layout is the first thing to be requested when accessing the dashboard on the user interface.
Return it in the correct if case in a valid json format, e.g.:
if option == 'layout':
return json.dumps(<PLOTLY_JSON_LAYOUT>)
data¶
The data for the dashboard will be requested periodically, depending of the status of the device. It consists of two json entries which must be present.
Return the data in a valid json format in the correct if case:
if option == 'data':
return json.dumps(<PLOTLY_JSON_DATA>)
Data Entries¶
These two entries must be present in the response of the data request:
monitoring¶
A Boolean which tells the user interface if the device is monitoring the activity or not. When a device is not monitoring currently, the data will be requested less frequently.
graph¶
The real data to represent in the dashboard. It must also be in a valid Plotly format.
Example¶
A simple example of layout and data can look like this:
@bp.method('device.monitor')
def graph(option: str) -> str:
layout = {
'showLegend': False,
'xaxis': {
'title': 'Time',
'showgrid': False,
'zeroline': False,
'autotick': True,
'tick': '',
'showticklabels': False
},
'yaxis': {
'title': 'Voltage [mV]'
}
}
data = {
'monitoring': True,
'graph': [{
'x': [10, 20, 30, 40],
'y': [1, 2, 3, 4]
}]
}
if option == 'data':
return json.dumps(data)
if option == 'layout':
return json.dumps(layout)
Note that the data normally comes from a hardware module and is not static.
It is also supported to plot multiple graphs by using subplots, as described in the Plotly documentation.