progetto201 API
|
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... | |
DATA: manages sensors data.
Client perspective:
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:
Which calls all the other functions
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:
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:
array | $t_conn_res | array with the DB connection object |
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.
array | $t_conn_res | array with the DB connection object |
int | $nodeid | integer that identifies the node |
int | $min_timestamp | timestamp set as the start date for data plotting |
int | $max_timestamp | timestamp set as the end date for data plotting |
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.
array | $t_conn_res | array with the DB connection object |
int | $nodeid | integer that identifies the node |
getOptions | ( | $t_conn_res | ) |
Returns user's options from the t_options table.
It executes the SELECT query to get this data:
array | $t_conn_res | array with the DB connection object |
$response = array("errors" => array()) |
Prepare default response array with no errors.