Using Widget JS Editor to parse raw data on Device Dashboard


#1

The Murano Products device dashboards can be handy for debugging and visualizing data before creating a full solution project.

It’s common that data is sent in a formatted blob, say JSON and of course this can’t be used in the dashboard widgets without doing a little bit of parsing.

For example, if I have a typical data packet being sent to an alias called ‘raw_data’ that looks like this:

{"ping":52,"power":98.90,"temperature":46.70,"state":"running"}

If I want to graph temperature and power and show an indicator on on/off status - I can use these examples.

Add a new widget and select ‘.JS EDITOR’ for the value.

Enter the Javascript to run for each new data value, in this case to find the temperature value. Then hit the ‘close’ button.

Then save the widget. You’ll dashboard will start to look like this.

Example for Graphing a Float Number

var _str = resources["rawdata"]
var json =JSON.parse(_str);
return parseFloat(json.temperature);

Example for finding an on/off state for Indicator Widget

var _str = resources["raw_data"];
var json =JSON.parse(_str);
if(json.state == 'running') {
    return 1;
}
return 0;