Page 4 - Always-code/Analytical-dashboard GitHub Wiki

Functions and Classes

This section describes the functions and classes used in this demo.

on_connect

on_connect (client,userdata,flags,rc)

This function is associated with on_connect callback using the command client.on_connect = on_connect

In this demo, this function prints a message when client connection on the subscriber side is established with MQTT broker.

Parameters:

  • client : str,client instance for this callback.
  • userdata : as defined by the user, contains user-defined data.
  • flags : dict, response flags set by the broker.
  • rc : int, contains the connection result.

NOTE: For more information on this callback function, visit https://www.eclipse.org/paho/index.php?page=clients/python/docs/index.php

on_log

on_log (client, userdata, level, buffer)

This function is associated with on_log callback using the command client.on_log = on_log

After subscriber side client connection is established with MQTT broker, a log is generated. This log contains information related to MQTT communication protocol. In this demo, the on_log function prints this information.

Parameters:

  • client : str,client instance for this callback.
  • userdata : as defined by the user, contains user defined data.
  • level : str, provides the severity of the message.
  • buffer : str, contains the message.

NOTE: For more information on this callback function, visit https://www.eclipse.org/paho/index.php?page=clients/python/docs/index.php

on_message

on_message (client, userdata, message)

This function is associated with on_message callback using the command client.on_message = on_message

In this demo, this function takes json data from MQTT broker, converts it into python object and inserts the data into data table in PostgreSQL database.

Parameters:

  • client : str,client instance for this callback.
  • userdata : as defined by the user, contains user defined data.
  • message : class with members topic, payload, qos, retain. This is an instance of MQTT message.

NOTE: For more information on this callback function, visit https://www.eclipse.org/paho/index.php?page=clients/python/docs/index.php

AllResourceEndpoints

This is a class inherited from parent class 'Resource'.

The get method in this class returns a list of all resource endpoints used in this demo.

MachineData

This is a class inherited from parent class 'Resource'.

Contains get method with start and stop parameters. Both the parameters are user inputs and must be integers.

The get method in this class retrieves data from PostgreSQL data table within start and stop range and returns it in json format.

MachineDataLast

This is a class inherited from parent class 'Resource'.

The get method in this class retrieves last 200 values from PostgreSQL data table and returns it in json format. (You can retrieve any number of values. This demo retrieves last 200.)

SensorData

SensorData (start, end)

This function sends a GET request to the specified URL and retrieves data values from PostgreSQL data table depending on the value of response status code.

The start and stop parameters define a range of time frames. Values within this range are selected. This function returns a data frame.

Parameters:

  • start : int, contains start of the time frame.
  • end : int, contains end of the time frame.

SensorData200

SensorData200 ()

This function sends a GET request to the specified URL and retrieves last 200 data values from PostgreSQL data table. (You can retrieve any number of values. This demo retrieves last 200.) This function returns a data frame.

sensor__temperature__container

sensor__temperature__container (interval,value,secondvalue)

This function plots the temperature values from PostgreSQL data table against time. This function defines the layout for the temperature versus time graph, shows control limits on the graph and marks data violators. (Data violators are data points that fall outside either the upper control limit value or the lower control limit value.)

Parameters:

  • interval : int, contains the graph update interval.
  • value : float, contains value of lower control limit selected by the user.
  • secondvalue : float, contains value of upper control limit selected by the user.

sensor__pressure__container

sensor__pressure__container (interval,value,secondvalue)

This function plots the pressure values from PostgreSQL data table against time. This function defines the layout for the pressure versus time graph, shows control limits on the graph and marks data violators. (Data violators are data points that fall outside either the upper control limit value or the lower control limit value.)

Parameters:

  • interval : int, contains the graph update interval.
  • value : float, contains value of lower control limit selected by the user.
  • secondvalue : float, contains value of upper control limit selected by the user.

sensor__humidity__container

sensor__humidity__container (interval,value,secondvalue)

This function plots the humidity values from PostgreSQL data table against time. This function defines the layout for the humidity versus time graph, shows control limits on the graph and marks data violators. (Data violators are data points that fall outside either the upper control limit value or the lower control limit value.)

Parameters:

  • interval : int, contains the graph update interval.
  • value : float, contains value of lower control limit selected by the user.
  • secondvalue : float, contains value of upper control limit selected by the user.

sensor__pitch__container

sensor__pitch__container (interval,value,secondvalue)

This function plots the pitch values from PostgreSQL data table against time. This function defines the layout for the pitch versus time graph, shows control limits on the graph and marks data violators. (Data violators are data points that fall outside either the upper control limit value or the lower control limit value.)

Parameters:

  • interval : int, contains the graph update interval.
  • value : float, contains value of lower control limit selected by the user.
  • secondvalue : float, contains value of upper control limit selected by the user.

sensor__roll__container

sensor__roll__container (interval,value,secondvalue)

This function plots the roll values from PostgreSQL data table against time. This function defines the layout for the roll versus time graph, shows control limits on the graph and marks data violators. (Data violators are data points that fall outside either the upper control limit value or the lower control limit value.)

Parameters:

  • interval : int, contains the graph update interval.
  • value : float, contains value of lower control limit selected by the user.
  • secondvalue : float, contains value of upper control limit selected by the user.

sensor__yaw__container

sensor__yaw__container (interval,value,secondvalue)

This function plots the yaw values from PostgreSQL data table against time. This function defines the layout for the yaw versus time graph, shows control limits on the graph and marks data violators. (Data violators are data points that fall outside either the upper control limit value or the lower control limit value.)

Parameters:

  • interval : int, contains the graph update interval.
  • value : float, contains value of lower control limit selected by the user.
  • secondvalue : float, contains value of upper control limit selected by the user.