progetto201 API
Functions | Variables
data.php File Reference

DATA: manages sensors data. More...

Functions

 getOptions ($t_conn_res)
 Returns user's options from the t_options table. More...
 
 getNodetype ($t_conn_res, $nodeid)
 Returns the node type of a node with id $nodeid. More...
 
 getDataType0 ($t_conn_res, $nodeid, $min_timestamp, $max_timestamp)
 Returns data of the node type 0, with id $nodeid. More...
 
 getData ($t_conn_res)
 Returns the data of the node id requested by calling the correct getDataTypeX() function. More...
 

Variables

 $response = array("errors" => array())
 Prepare default response array with no errors. More...
 

Detailed Description

DATA: manages sensors data.

Client perspective:

Description

This script sets the returned content type to JSON, includes the db_connection.php script

It is used to connect to MySQL and execute basic SELECT queries

and then defines the response array.

Many functions are defined:

 getOptions()

Returns user's options from the t_options table.

 getNodetype()

Returns the node type of a node with id $nodeid.

 getData()

Returns the data of the node id requested by calling the correct getDataTypeX() function.

 getDataType0()

Returns data of the node type 0, with id $nodeid.

If the script isn't included it tries to connect to the database, and checks the request method:

When the called function ends the connection to the DB gets terminated, and data (or errors) is collected inside the response array. The response array gets echoed to the client in JSON format

Errors list:

Since
01_01
Author
Stefano Zenaro (https://github.com/mario33881)

Function Documentation

◆ getData()

getData (   $t_conn_res)

Returns the data of the node id requested by calling the correct getDataTypeX() function.

First checks if a node id was specified in the request, then gets the timestamps from the options table by calling the getOptions() function.

Next it gets the node type of the node by calling the getNodetype() function. Based on the node type, the correct function is called to collect the data of that node.

Example:

  • if the node type is "0", the table is "t_type0_data" and the function that collects the data is called getDataType0()
Since
01_01
Parameters
array$t_conn_resarray with the DB connection object
Returns
array $action_res array with errors or data

◆ getDataType0()

getDataType0 (   $t_conn_res,
  $nodeid,
  $min_timestamp,
  $max_timestamp 
)

Returns data of the node type 0, with id $nodeid.

If the request has a "latest" parameter, return the last data from that node, else check if the client wants all the data ($min_timestamp e $max_timestamp are zero) or part of the data ( $min_timestamp <= timestamp <= $max_timestamp).

The data is then returned by the function.

Since
01_01
Parameters
array$t_conn_resarray with the DB connection object
int$nodeidinteger that identifies the node
int$min_timestamptimestamp set as the start date for data plotting
int$max_timestamptimestamp set as the end date for data plotting
Returns
array $action_res array with errors or data

◆ getNodetype()

getNodetype (   $t_conn_res,
  $nodeid 
)

Returns the node type of a node with id $nodeid.

The function selects the type id using the node id.

Since
01_01
Parameters
array$t_conn_resarray with the DB connection object
int$nodeidinteger that identifies the node
Returns
array $action_res array with errors or data

◆ getOptions()

getOptions (   $t_conn_res)

Returns user's options from the t_options table.

It executes the SELECT query to get this data:

  • color_scheme: color name selected by the user
  • min_timestamp: timestamp set as the start date for data plotting
  • max_timestamp: timestamp set as the end date for data plotting
Since
01_01
Parameters
array$t_conn_resarray with the DB connection object
Returns
array $query_arr array with errors or data

Variable Documentation

◆ $response

$response = array("errors" => array())

Prepare default response array with no errors.