Skip to content
Snippets Groups Projects
Commit 1b41935c authored by Nizar Bouchedakh's avatar Nizar Bouchedakh
Browse files

new-version with new method and route names

parent 7318157f
Branches master
No related tags found
No related merge requests found
##### TO DO ######
- Change some methods to POST
- Classes for different devices
...@@ -43,7 +43,6 @@ class Backend(): ...@@ -43,7 +43,6 @@ class Backend():
###### These dispatchers associate a method to a signal. the signals are generated by the library python-openzwave. ###### These dispatchers associate a method to a signal. the signals are generated by the library python-openzwave.
###### Once the signal is reveived. It's associated method is executed (see "_node_added" example below in "_network_started" method) ###### Once the signal is reveived. It's associated method is executed (see "_node_added" example below in "_network_started" method)
dispatcher.connect(self._network_started, ZWaveNetwork.SIGNAL_NETWORK_STARTED) dispatcher.connect(self._network_started, ZWaveNetwork.SIGNAL_NETWORK_STARTED)
dispatcher.connect(self._network_failed, ZWaveNetwork.SIGNAL_NETWORK_FAILED)
dispatcher.connect(self._network_ready, ZWaveNetwork.SIGNAL_NETWORK_READY) dispatcher.connect(self._network_ready, ZWaveNetwork.SIGNAL_NETWORK_READY)
###### backend object attributes ###### backend object attributes
...@@ -91,15 +90,7 @@ class Backend(): ...@@ -91,15 +90,7 @@ class Backend():
dispatcher.connect(self._node_added, ZWaveNetwork.SIGNAL_NODE_ADDED) dispatcher.connect(self._node_added, ZWaveNetwork.SIGNAL_NODE_ADDED)
dispatcher.connect(self._node_removed, ZWaveNetwork.SIGNAL_NODE_REMOVED) dispatcher.connect(self._node_removed, ZWaveNetwork.SIGNAL_NODE_REMOVED)
dispatcher.connect(self._debug_node_naming, ZWaveNetwork.SIGNAL_NODE_NAMING)
dispatcher.connect(self._debug_node_new, ZWaveNetwork.SIGNAL_NODE_NEW)
dispatcher.connect(self._debug_node_protocol_info, ZWaveNetwork.SIGNAL_NODE_PROTOCOL_INFO)
def _network_failed(self, network):
# executed once the software representation has failed
print("network failed :(")
def _network_ready(self, network): def _network_ready(self, network):
...@@ -107,8 +98,6 @@ class Backend(): ...@@ -107,8 +98,6 @@ class Backend():
print("network : ready : %d nodes were found." % network.nodes_count) print("network : ready : %d nodes were found." % network.nodes_count)
print("network : controller is : %s" % network.controller) print("network : controller is : %s" % network.controller)
# dispatcher.connect(self._node_update, ZWaveNetwork.SIGNAL_NODE)
dispatcher.connect(self._node_event, ZWaveNetwork.SIGNAL_NODE_EVENT)
dispatcher.connect(self._value_update, ZWaveNetwork.SIGNAL_VALUE) dispatcher.connect(self._value_update, ZWaveNetwork.SIGNAL_VALUE)
def _node_added(self, network, node): def _node_added(self, network, node):
...@@ -126,41 +115,6 @@ class Backend(): ...@@ -126,41 +115,6 @@ class Backend():
print('node removed: %s.' % node.name) print('node removed: %s.' % node.name)
self.node_removed = True self.node_removed = True
def _debug_node_naming(self, network, node):
# executed when node is named
print('node %s named: %s.' % (node.node_id, node.name))
def _debug_node_new(self, network, node_id):
# executed when a new node is detected in the network
print('New node is node: %s.' % node_id)
def _debug_node_protocol_info(self, network, node):
# executed when discovering the features of a new node
print('node Protocol Info: %s.' % node.node_id)
def _node_update(self, network, node):
# executed when the nodes features are received : product_name, manufacturer_id, ...
print('node update: %s.' % node)
def _node_event(self, network, node, signal, sender):
# executed when the motion sensor's state is changed
print('node event %s from node %s.' % (signal, node.node_id))
if node.isReady and node.product_name == "MultiSensor 6":
values = node.get_values("All","User","All",True,"All")
for value in values.itervalues():
if value.label == "Sensor":
motion_value = value.data
print('motion sensor value is now %s' %motion_value)
def _value_update(self, network, node, value): def _value_update(self, network, node, value):
...@@ -172,7 +126,7 @@ class Backend(): ...@@ -172,7 +126,7 @@ class Backend():
def ordered_nodes_dict(self): def ordered_nodes_dict(self):
#this method returns an ordered list of the network's nodes #this method returns an ordered list of the network's nodes sorted by node's id
return OrderedDict(sorted(self.network.nodes.items())) return OrderedDict(sorted(self.network.nodes.items()))
...@@ -232,14 +186,9 @@ class Backend(): ...@@ -232,14 +186,9 @@ class Backend():
######################################################################################################################### #########################################################################################################################
def network_preview(self): def network_info(self):
#### COMPLETE THIS METHOD ############## #### COMPLETE THIS METHOD ##############
...@@ -252,27 +201,27 @@ class Backend(): ...@@ -252,27 +201,27 @@ class Backend():
########## Configuration of multisensors ################################################################################## ########## Configuration of multisensors ##################################################################################
########################################################################################################################### ###########################################################################################################################
def set_sensor(self, Grp_interval, Grp_reports, Wakeup_interval): def set_basic_nodes_configuration(self, Grp_interval, Grp_reports, Wakeup_interval):
#### COMPLETE THIS METHOD ############## #### COMPLETE THIS METHOD ##############
return "this method configures the nodes whit a specific configuration set by us" return "this method configures the nodes whit a specific configuration"
def network_nodesConfiguration(self): def get_nodes_Configuration(self):
#### COMPLETE THIS METHOD ############## #### COMPLETE THIS METHOD ##############
return "this method returns a html containing the configuration of the network's nodes" return "this method returns a JSON that gives an overview of the network and it's nodes' configuration parameters (like the ID, Wake-up Interval, Group 1 Reports, Group 1 Interval ...)"
def set_node_config_param(self, n, param, value): def set_node_config_parameter(self, n, param, value, size):
#### COMPLETE THIS METHOD ############## #### COMPLETE THIS METHOD ##############
return "this method sets a configuration parameter to a precise value" return "this method sets a configuration parameter to a given value"
def get_node_config_param(self, n, param): def get_node_config_parameter(self, n, param):
#### COMPLETE THIS METHOD ############## #### COMPLETE THIS METHOD ##############
...@@ -285,7 +234,7 @@ class Backend(): ...@@ -285,7 +234,7 @@ class Backend():
############# SENSORS ################################################################################################# ############# SENSORS #################################################################################################
####################################################################################################################### #######################################################################################################################
def get_sensors(self): def get_sensors_list(self):
#### COMPLETE THIS METHOD ############## #### COMPLETE THIS METHOD ##############
...@@ -309,14 +258,14 @@ class Backend(): ...@@ -309,14 +258,14 @@ class Backend():
def allMeasures(self, n): def get_all_Measures(self, n):
#### COMPLETE THIS METHOD ############## #### COMPLETE THIS METHOD ##############
return "this method gets all the measures of a specific sensor node" return "this method gets all the measures of a specific sensor node"
def temperature(self, n): def get_temperature(self, n):
#### HERE'S AN EXAMPLE OF A METHOD THAT GETS THE TEMPERATURE OF A SPECIFIC SENSOR NODE ############## #### HERE'S AN EXAMPLE OF A METHOD THAT GETS THE TEMPERATURE OF A SPECIFIC SENSOR NODE ##############
...@@ -329,7 +278,7 @@ class Backend(): ...@@ -329,7 +278,7 @@ class Backend():
return jsonify(controller = name, sensor = node.node_id, location = node.location, type = value.label.lower(), updateTime = self.timestamps["timestamp"+str(node.node_id)], value = val) return jsonify(controller = name, sensor = node.node_id, location = node.location, type = value.label.lower(), updateTime = self.timestamps["timestamp"+str(node.node_id)], value = val)
return "Node not ready or wrong sensor node !" return "Node not ready or wrong sensor node !"
def humidity(self, n): def get_humidity(self, n):
#### HERE'S AN EXAMPLE OF A METHOD THAT GETS THE HUMIDITY OF A SPECIFIC SENSOR NODE ############## #### HERE'S AN EXAMPLE OF A METHOD THAT GETS THE HUMIDITY OF A SPECIFIC SENSOR NODE ##############
...@@ -342,28 +291,28 @@ class Backend(): ...@@ -342,28 +291,28 @@ class Backend():
return jsonify(controller = name, sensor = node.node_id, location = node.location, type = value.label.lower(), updateTime = self.timestamps["timestamp"+str(node.node_id)], value = val) return jsonify(controller = name, sensor = node.node_id, location = node.location, type = value.label.lower(), updateTime = self.timestamps["timestamp"+str(node.node_id)], value = val)
return "Node not ready or wrong sensor node !" return "Node not ready or wrong sensor node !"
def luminance(self, n): def get_luminance(self, n):
#### COMPLETE THIS METHOD ############## #### COMPLETE THIS METHOD ##############
return "this method gets the luminance measure of a specific sensor node" return "this method gets the luminance measure of a specific sensor node"
def motion(self, n): def get_motion(self, n):
#### COMPLETE THIS METHOD ############## #### COMPLETE THIS METHOD ##############
return "this method this method gets the motion measure of a specific sensor node" return "this method this method gets the motion measure of a specific sensor node"
def battery(self, n): def get_battery(self, n):
#### COMPLETE THIS METHOD ############## #### COMPLETE THIS METHOD ##############
return "this method this method gets the battery measure of a specific sensor node" return "this method this method gets the battery measure of a specific sensor node"
def get_nodes(self): def get_nodes_list(self):
#### COMPLETE THIS METHOD ############## #### COMPLETE THIS METHOD ##############
...@@ -398,7 +347,7 @@ class Backend(): ...@@ -398,7 +347,7 @@ class Backend():
return "this method gets the name of a specific sensor node" return "this method gets the name of a specific sensor node"
def get_neighbors(self, n): def get_neighbours_list(self, n):
#### COMPLETE THIS METHOD ############## #### COMPLETE THIS METHOD ##############
......
This diff is collapsed.
flask-main.py 100755 → 100644
...@@ -27,16 +27,41 @@ def index(): ...@@ -27,16 +27,41 @@ def index():
####################################################################################################################### #######################################################################################################################
""" """
@api {get} /network/preview get_network_config @api {get} /network/info get_network_info
@apiName get_network_config @apiName get_network_info
@apiGroup User @apiGroup User
@apiSuccess {JSON} Table Network's Information.
@apiSuccessExample {json} Example data on success:
@apiSuccess {String} Network_Home_ID Network's ID
@apiSuccess {JSON} Node_<Number> A JSON containing node's information (for each node). See below
@apiSuccess {boolean} Is_Ready Node status
@apiSuccess {String[]} Neighbours Node's neighbours
@apiSuccess {Number} Node_ID Node's ID
@apiSuccess {String} Node_location Node's location
@apiSuccess {String} Node_name Node's name
@apiSuccess {String} Product_name Node's product name
@apiSuccess {String} Query_stage Query Stage
@apiSuccess {Number} Query_stage_(%) Query Stage (percentage)
@apiSuccessExample {json} Example of result in case of success:
{ {
"Network Home ID": "0xe221b13f", "Network Home ID": "0xe221b13f",
"Node 1": { "Node 1": {
"Is Ready": true, "Is Ready": true,
"Neighbours": "2", "Neighbours": "2",
"Node ID": "1", "Node ID": "1",
...@@ -46,7 +71,7 @@ def index(): ...@@ -46,7 +71,7 @@ def index():
"Query Stage": "Complete", "Query Stage": "Complete",
"Query Stage (%)": "100 %" "Query Stage (%)": "100 %"
}, },
"Node 2": { "Node 2": {
"Is Ready": true, "Is Ready": true,
"Neighbours": "1", "Neighbours": "1",
"Node ID": "2", "Node ID": "2",
...@@ -58,45 +83,73 @@ def index(): ...@@ -58,45 +83,73 @@ def index():
} }
} }
@apiDescription Gets the configuration of the Z-Wave network in a JSON format
@apiDescription Gets information about the Z-Wave network in a JSON format
""" """
@app.route('/network/preview', strict_slashes=False) @app.route('/network/info', strict_slashes=False)
def network_preview(): def network_info():
return backend.network_preview() return backend.network_info()
""" """
@api {get} /network/configureNodes/<int:Group_interval>/<int:Group_reports>/<int:Wake-up_interval> set_nodes_configuration @api {get} /network/configureNodes/<int:Group_interval>/<int:Group_reports>/<int:Wake-up_interval> set_sensor
@apiName set_nodes_configuration @apiName set_sensor
@apiGroup Admin @apiGroup Admin
@apiParam {Number} Group_Interval Number of seconds between measurements transmissions @apiParam {Number} Group_Interval Number of seconds between two successive transfers of measures
@apiParam {Number} Group_Reports a Number identifying measurements sent @apiParam {Number} Group_Reports Number identifying measures sent by the sensor
@apiParam {Number} Wake-up_Interval Number of seconds between two node's wake-ups @apiParam {Number} Wake-up_Interval Number of seconds between two node's wake-ups
@apiSuccess {String} Message Description of the new nodes' configuration. @apiSuccess {String} Message Description of the new nodes' configuration.
@apiDescription Configure all nodes of the network with a predefined configuration @apiDescription Configure all nodes of the network with a predefined configuration. This methods configures only Group 1. All measurements (temperature, luminosity, motion and humidity) must be retrieved from the sensors after a given period of time (Group_Interval Number).
""" """
@app.route('/network/configureNodes/<int:Grp_interval>/<int:Grp_reports>/<int:Wakeup_interval>', strict_slashes=False) @app.route('/network/configureNodes/<int:Grp_interval>/<int:Grp_reports>/<int:Wakeup_interval>', strict_slashes=False)
def network_configureNodes(Grp_interval,Grp_reports,Wakeup_interval): def network_configureNodes(Grp_interval,Grp_reports,Wakeup_interval):
# configure all the nodes of the network with a specific configuration # configure all the nodes of the network with a specific configuration
return backend.set_sensor(Grp_interval,Grp_reports,Wakeup_interval) return backend.set_basic_nodes_configuration(Grp_interval,Grp_reports,Wakeup_interval)
""" """
@api {get} /network/nodesConfiguration Nodes configuration @api {get} /network/get_nodes_Configuration get_nodes_Configuration
@apiName Networks' Nodes configuration @apiName get_nodes_Configuration
@apiGroup Admin @apiGroup Admin
@apiSuccess {JSON} Table Describing of the nodes' configuration.
@apiSuccessExample {json} Example data on success:
@apiSuccess {String} Network_Home_ID Network's ID
@apiSuccess {JSON} Node_<Number> A JSON containing node's informations that are detailed above (for each node except the controller)
@apiSuccess {String} Enable_Motion_Sensor Motion sensor level
@apiSuccess {Number} Group1_Interval Number of seconds between two Group1 measurements transmissions
@apiSuccess {Number} Group1_Reports A number specifying measurements sent in this group (set to 241 to send all measurements on this group)
@apiSuccess {Number} Group2_Interval Number of seconds between two Group2 measurements transmissions
@apiSuccess {Number} Group2_Reports A number specifying measurements sent in this group (set to 0 because no measurements will be sent on this group)
@apiSuccess {Number} Group3_Interval Number of seconds between two Group3 measurements transmissions
@apiSuccess {Number} Group3_Reports A number specifying measurements sent in this group (set to 0 because no measurements will be sent on this group)
@apiSuccess {Number} Node_ID Node's ID
@apiSuccess {Number} Wake_up_Interval Number of seconds between two wake-ups
@apiSuccessExample {json} Example of result in case of success:
{ {
"Network Home ID": "0xe221b13f", "Network Home ID": "0xe221b13f",
"Node 2": { "Node 2": {
"Enable Motion Sensor": "Enabled level 5 (maximum sensitivity", "Enable Motion Sensor": "Enabled level 5 (maximum sensitivity",
"Group 1 Interval": "3600", "Group 1 Interval": "3600",
"Group 1 Reports": "241", "Group 1 Reports": "241",
...@@ -105,18 +158,17 @@ def network_configureNodes(Grp_interval,Grp_reports,Wakeup_interval): ...@@ -105,18 +158,17 @@ def network_configureNodes(Grp_interval,Grp_reports,Wakeup_interval):
"Group 3 Interval": "3600", "Group 3 Interval": "3600",
"Group 3 Reports": "0", "Group 3 Reports": "0",
"Node ID": "2", "Node ID": "2",
"Wake-up Interval": "240" "Wake-up Interval": "3600"
} }
} }
@apiDescription Gets the list of nodes and their configuration parameters in a JSON format. For each node, the system should provide the following information: Node ID, Motion sensor level, Wake_up_Interval and the report and interval of each group (there are three groups). See details in the documentation of the sensor: Aeon Labs MultiSensor 6 (Z-wave MultiSensor).
@apiDescription Gets a html with the list of nodes and their configuration parameters
""" """
@app.route('/network/nodesConfiguration', strict_slashes=False) @app.route('/network/get_nodes_Configuration', strict_slashes=False)
def network_nodesConfiguration(): def get_nodes_Configuration():
# gets a html with the list of nodes with their config parameters # gets a html with the list of nodes with their config parameters
return backend.network_nodesConfiguration() ######## a revoir return backend.get_nodes_Configuration() ######## a revoir
...@@ -164,13 +216,13 @@ def stop(): ...@@ -164,13 +216,13 @@ def stop():
""" """
@api {get} /network/reset Reset Network @api {get} /network/reset reset
@apiName Reset Network @apiName Reset Network
@apiGroup Admin @apiGroup Admin
@apiSuccess {String} Message Confirmation that the Z-Wave Network has been reset @apiSuccess {String} Message Confirmation that the Z-Wave Network has been reset
@apiDescription Resets the network's controller @apiDescription Resets the network's controller. Do not call this method before excluding (removing) the sensors connected to the controller.
""" """
...@@ -186,31 +238,27 @@ def reset(): ...@@ -186,31 +238,27 @@ def reset():
### THESE METHODS WERE SPECIALLY MADE FOR SENSOR NODES ################################################################# ### THESE METHODS WERE SPECIALLY MADE FOR SENSOR NODES #################################################################
####################################################################################################################### #######################################################################################################################
""" """
@api {get} /sensors get_sensors @api {get} /get_sensors_list get_sensors_list
@apiName get_sensors @apiName get_sensors_list
@apiGroup User @apiGroup User
@apiSuccess {String[]} List List of all sensor nodes in the network @apiSuccess {String[]} JSON List of all sensor nodes in the network i a JSON format
@apiDescription Lists all sensors nodes in the network. The controller is excluded. @apiDescription Lists all sensors nodes in the network. The controller is excluded.
""" """
@app.route('/sensors', strict_slashes=False) @app.route('/get_sensors_list', strict_slashes=False)
def sensors(): def get_sensors_list():
# returns a list of all sensors in the network (only sensors) # returns a list of all sensors in the network in a JSON format(only sensors)
sensors = backend.get_sensors() return backend.get_sensors_list()
if type(sensors) is str:
return sensors
sensors_list = ""
for key, val in sensors.items():
sensors_list += str(key) + "=" + str(val) + "\n"
return Response(sensors_list, mimetype="text/plain")
""" """
@api {get} /sensors/<node_id>/all_measures get_all_measures_sensor @api {get} /sensors/<node_id>/get_all_measures get_all_measures_sensor
@apiName get_all_measures_sensor @apiName get_all_measures_sensor
@apiGroup User @apiGroup User
...@@ -226,7 +274,7 @@ def sensors(): ...@@ -226,7 +274,7 @@ def sensors():
@apiSuccess {String} motion motion state (true or false) @apiSuccess {String} motion motion state (true or false)
@apiSuccess {Number} updateTime Timestamp at the measures' reception @apiSuccess {Number} updateTime Timestamp at the measures' reception
@apiSuccessExample {json} Example data on success: @apiSuccessExample {json} Example of result in case of success:
{ {
"battery": 100, "battery": 100,
"controller": "Pi lab1", "controller": "Pi lab1",
...@@ -238,18 +286,18 @@ def sensors(): ...@@ -238,18 +286,18 @@ def sensors():
"temperature": 30.0, "temperature": 30.0,
"updateTime": 1454682568 "updateTime": 1454682568
} }
@apiDescription Gets all reasures of a given sensor in a JSON format @apiDescription Gets all measures of a given sensor, in a JSON format
""" """
@app.route('/sensors/<int:node>/all_measures', strict_slashes=False) @app.route('/sensors/<int:node>/get_all_measures', strict_slashes=False)
def get_all_measures(node): def get_all_measures(node):
return backend.allMeasures(node) return backend.get_all_Measures(node)
""" """
@api {get} /sensors/<node_id>/temperature get_temperature @api {get} /sensors/<node_id>/get_temperature get_temperature
@apiName get_temperature @apiName get_temperature
@apiGroup User @apiGroup User
...@@ -262,7 +310,7 @@ def get_all_measures(node): ...@@ -262,7 +310,7 @@ def get_all_measures(node):
@apiSuccess {Number} value Temperature level (C) @apiSuccess {Number} value Temperature level (C)
@apiSuccess {Number} updateTime Timestamp of the measure @apiSuccess {Number} updateTime Timestamp of the measure
@apiSuccessExample {json} Example data on success: @apiSuccessExample {json} Example of result in case of success:
{ {
"controller": "Pi lab1", "controller": "Pi lab1",
"location": "Room A401", "location": "Room A401",
...@@ -275,14 +323,14 @@ def get_all_measures(node): ...@@ -275,14 +323,14 @@ def get_all_measures(node):
""" """
@app.route('/sensors/<int:node>/temperature', strict_slashes=False) @app.route('/sensors/<int:node>/get_temperature', strict_slashes=False)
def get_temperature(node): def get_temperature(node):
return backend.temperature(node) return backend.get_temperature(node)
""" """
@api {get} /sensors/<node_id>/humidity get_humidity @api {get} /sensors/<node_id>/get_humidity get_humidity
@apiName get_humidity @apiName get_humidity
@apiGroup User @apiGroup User
...@@ -295,7 +343,7 @@ def get_temperature(node): ...@@ -295,7 +343,7 @@ def get_temperature(node):
@apiSuccess {Number} value humidity level (%) @apiSuccess {Number} value humidity level (%)
@apiSuccess {Number} updateTime Timestamp at the measures' reception @apiSuccess {Number} updateTime Timestamp at the measures' reception
@apiSuccessExample {json} Example data on success: @apiSuccessExample {json} Example of result in case of success:
{ {
"controller": "Pi lab1", "controller": "Pi lab1",
"location": "Room A401", "location": "Room A401",
...@@ -308,14 +356,14 @@ def get_temperature(node): ...@@ -308,14 +356,14 @@ def get_temperature(node):
""" """
@app.route('/sensors/<int:node>/humidity', strict_slashes=False) @app.route('/sensors/<int:node>/get_humidity', strict_slashes=False)
def get_humidity(node): def get_humidity(node):
return backend.humidity(node) return backend.get_humidity(node)
""" """
@api {get} /sensors/<node_id>/luminance get_luminance @api {get} /sensors/<node_id>/get_luminance get_luminance
@apiName get_luminance @apiName get_luminance
@apiGroup User @apiGroup User
...@@ -328,7 +376,7 @@ def get_humidity(node): ...@@ -328,7 +376,7 @@ def get_humidity(node):
@apiSuccess {Number} value luminance level (lux) @apiSuccess {Number} value luminance level (lux)
@apiSuccess {Number} updateTime Timestamp at the measures' reception @apiSuccess {Number} updateTime Timestamp at the measures' reception
@apiSuccessExample {json} Example data on success: @apiSuccessExample {json} Example of result in case of success:
{ {
"controller": "Pi lab1", "controller": "Pi lab1",
"location": "Room A401", "location": "Room A401",
...@@ -341,14 +389,14 @@ def get_humidity(node): ...@@ -341,14 +389,14 @@ def get_humidity(node):
""" """
@app.route('/sensors/<int:node>/luminance', strict_slashes=False) @app.route('/sensors/<int:node>/get_luminance', strict_slashes=False)
def get_luminance(node): def get_luminance(node):
return backend.luminance(node) return backend.get_luminance(node)
""" """
@api {get} /sensors/<node_id>/motion get_motion @api {get} /sensors/<node_id>/get_motion get_motion
@apiName get_motion @apiName get_motion
@apiGroup User @apiGroup User
...@@ -361,7 +409,7 @@ def get_luminance(node): ...@@ -361,7 +409,7 @@ def get_luminance(node):
@apiSuccess {Number} value motion state (boolean) @apiSuccess {Number} value motion state (boolean)
@apiSuccess {Number} updateTime Timestamp at the measures' reception @apiSuccess {Number} updateTime Timestamp at the measures' reception
@apiSuccessExample {json} Example data on success: @apiSuccessExample {json} Example of result in case of success:
{ {
"controller": "Pi lab1", "controller": "Pi lab1",
"location": "Room A401", "location": "Room A401",
...@@ -374,22 +422,23 @@ def get_luminance(node): ...@@ -374,22 +422,23 @@ def get_luminance(node):
""" """
@app.route('/sensors/<int:node>/motion', strict_slashes=False) @app.route('/sensors/<int:node>/get_motion', strict_slashes=False)
def get_motion(node): def get_motion(node):
return backend.motion(node) return backend.get_motion(node)
""" """
@api {get} /sensors/<node_id>/set/<parameter>/to/<value> set_parameter @api {get} /sensors/<node_id>/set_parameter/<parameter>/to/<value> set_parameter
@apiName set_parameter @apiName set_parameter
@apiGroup Admin @apiGroup Admin
@apiParam {Number} node_id Sensor's unique ID @apiParam {Number} node_id Sensor's unique ID
@apiParam {Number} parameter Parameter's unique index @apiParam {Number} parameter Parameter's unique index (See sensor manual)
@apiParam {Number} value new value of the parameter @apiParam {Number} value new value of the parameter
@apiParam {Number} size size of value of the parameter (See sensor manual)
@apiSuccess {String} parameter parameter's new value @apiSuccess {String} parameter parameter's new value
...@@ -397,15 +446,15 @@ def get_motion(node): ...@@ -397,15 +446,15 @@ def get_motion(node):
""" """
@app.route('/sensors/<int:node>/set/<int:param>/to/<int:value>', strict_slashes=False) @app.route('/sensors/<int:node>/set_parameter/<int:param>/to/<int:value>/<int:size>', strict_slashes=False)
def set_config_param(node, param, value): def set_config_param(node, param, value, size):
# sets a config parameter of a sensor node # sets a config parameter of a sensor node
return backend.set_node_config_param(node, param, value) return backend.set_node_config_parameter(node, param, value, size)
""" """
@api {get} /sensors/<node_id>/get/<parameter> get_parameter @api {get} /sensors/<node_id>/get_parameter/<parameter> get_parameter
@apiName get_parameter @apiName get_parameter
@apiGroup Admin @apiGroup Admin
...@@ -418,10 +467,10 @@ def set_config_param(node, param, value): ...@@ -418,10 +467,10 @@ def set_config_param(node, param, value):
""" """
@app.route('/sensors/<int:node>/get/<int:param>', strict_slashes=False) @app.route('/sensors/<int:node>/get_parameter/<int:param>', strict_slashes=False)
def get_config_param(node, param): def get_config_param(node, param):
# gets a config parameter of a sensor node # gets a config parameter of a sensor node
return backend.get_node_config_param(node, param) return backend.get_node_config_parameter(node, param)
...@@ -432,26 +481,21 @@ def get_config_param(node, param): ...@@ -432,26 +481,21 @@ def get_config_param(node, param):
######################################################################################################################## ########################################################################################################################
### THESE METHODS ARE SPECIALLY MADE FOR ALL TYPES OF NODES ############################################################ ### THESE METHODS ARE SPECIALLY MADE FOR ALL TYPES OF NODES ############################################################
""" """
@api {get} /nodes get_nodes @api {get} /get_nodes_list get_nodes_list
@apiName get_nodes @apiName get_nodes_list
@apiGroup User @apiGroup User
@apiSuccess {String[]} List List of all nodes in the network @apiSuccess {String[]} JSON List of all nodes in the network in a JSON format
@apiDescription Lists all nodes in the network @apiDescription Lists all nodes in the network
""" """
@app.route('/nodes', strict_slashes=False) @app.route('/get_nodes_list', strict_slashes=False)
def nodes(): def nodes():
# gets a list of all nodes in the network ans not only sensors # gets a list of all nodes in the network in a JSON format
nodes = backend.get_nodes() return backend.get_nodes_list()
if type(nodes) is str:
return nodes
nodes_list = ""
for key, val in nodes.items():
nodes_list += str(key) + "=" + str(val) + "\n"
return Response(nodes_list, mimetype="text/plain")
...@@ -462,7 +506,7 @@ def nodes(): ...@@ -462,7 +506,7 @@ def nodes():
@apiSuccess {String} Message Node added successfully @apiSuccess {String} Message Node added successfully
@apiDescription Adds Node to the network @apiDescription Adds Node to the network. The node can not be a controller.
""" """
...@@ -493,7 +537,7 @@ def remove_node(): ...@@ -493,7 +537,7 @@ def remove_node():
############# TO DO #################################################################################################### ############# TO DO ####################################################################################################
""" """
@api {get} /nodes/<node_id>/battery get_battery_level @api {get} /nodes/<node_id>/get_battery get_battery_level
@apiName get_battery_level @apiName get_battery_level
@apiGroup User @apiGroup User
...@@ -506,7 +550,7 @@ def remove_node(): ...@@ -506,7 +550,7 @@ def remove_node():
@apiSuccess {Number} value battery level (%) @apiSuccess {Number} value battery level (%)
@apiSuccess {Number} updateTime Timestamp at the measures' reception @apiSuccess {Number} updateTime Timestamp at the measures' reception
@apiSuccessExample {json} Example data on success: @apiSuccessExample {json} Example of result in case of success:
{ {
"controller": "Pi lab1", "controller": "Pi lab1",
"location": "Room A401", "location": "Room A401",
...@@ -515,18 +559,18 @@ def remove_node(): ...@@ -515,18 +559,18 @@ def remove_node():
"updateTime": 1454684168, "updateTime": 1454684168,
"value": 100 "value": 100
} }
@apiDescription Gets the battery level of a sensor in a JSON format @apiDescription Gets the battery level of a given sensor, in a JSON format
""" """
@app.route('/nodes/<int:node>/battery', strict_slashes=False) @app.route('/nodes/<int:node>/get_battery', strict_slashes=False)
def get_battery(node): def get_battery(node):
return backend.battery(node) return backend.get_battery(node)
""" """
@api {get} /nodes/<node_id>/setLocationTo/<value> set_location @api {get} /nodes/<node_id>/set_location/<value> set_location
@apiName set_location @apiName set_location
@apiGroup Admin @apiGroup Admin
...@@ -539,14 +583,14 @@ def get_battery(node): ...@@ -539,14 +583,14 @@ def get_battery(node):
""" """
@app.route('/nodes/<int:node>/setLocationTo/<value>', strict_slashes=False) @app.route('/nodes/<int:node>/set_location/<value>', strict_slashes=False)
def set_node_location(node, value): def set_node_location(node, value):
return backend.set_node_location(node, value) return backend.set_node_location(node, value)
""" """
@api {get} /nodes/<node_id>/setNameTo/<value> set_name @api {get} /nodes/<node_id>/set_name/<value> set_name
@apiName set_name @apiName set_name
@apiGroup User @apiGroup User
...@@ -559,14 +603,14 @@ def set_node_location(node, value): ...@@ -559,14 +603,14 @@ def set_node_location(node, value):
""" """
@app.route('/nodes/<int:node>/setNameTo/<value>', strict_slashes=False) @app.route('/nodes/<int:node>/set_name/<value>', strict_slashes=False)
def set_node_name(node, value): def set_node_name(node, value):
return backend.set_node_name(node, value) return backend.set_node_name(node, value)
""" """
@api {get} /nodes/<node_id>/getLocation get_location @api {get} /nodes/<node_id>/get_location get_location
@apiName get_location @apiName get_location
@apiGroup User @apiGroup User
...@@ -578,14 +622,14 @@ def set_node_name(node, value): ...@@ -578,14 +622,14 @@ def set_node_name(node, value):
""" """
@app.route('/nodes/<int:node>/getLocation', strict_slashes=False) @app.route('/nodes/<int:node>/get_location', strict_slashes=False)
def get_node_location(node): def get_node_location(node):
return backend.get_node_location(node) return backend.get_node_location(node)
""" """
@api {get} /nodes/<node_id>/getName get_name @api {get} /nodes/<node_id>/get_name get_name
@apiName get_name @apiName get_name
@apiGroup User @apiGroup User
...@@ -597,14 +641,14 @@ def get_node_location(node): ...@@ -597,14 +641,14 @@ def get_node_location(node):
""" """
@app.route('/nodes/<int:node>/getName', strict_slashes=False) @app.route('/nodes/<int:node>/get_name', strict_slashes=False)
def get_node_name(node): def get_node_name(node):
return backend.get_node_name(node) return backend.get_node_name(node)
""" """
@api {get} /nodes/<node_id>/neighbors get_neighbours @api {get} /nodes/<node_id>/get_neighbours get_neighbours
@apiName get_neighbours @apiName get_neighbours
@apiGroup User @apiGroup User
...@@ -616,9 +660,9 @@ def get_node_name(node): ...@@ -616,9 +660,9 @@ def get_node_name(node):
""" """
@app.route('/nodes/<int:node>/neighbors', strict_slashes=False) @app.route('/nodes/<int:node>/get_neighbours', strict_slashes=False)
def get_neighbors(node): def get_neighbours_list(node):
return backend.get_neighbors(node) return backend.get_neighbours_list(node)
...@@ -636,7 +680,7 @@ if __name__ == '__main__': ...@@ -636,7 +680,7 @@ if __name__ == '__main__':
file_handler.setFormatter(Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) file_handler.setFormatter(Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
app.logger.addHandler(file_handler) app.logger.addHandler(file_handler)
app.run(host='::', debug=False, use_reloader=False, port=5000) app.run(host='::', debug=False, use_reloader=False)
except KeyboardInterrupt: except KeyboardInterrupt:
backend.stop() backend.stop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment