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

nodesconfiguration in a json

parent 14467bc1
No related branches found
No related tags found
No related merge requests found
......@@ -50,8 +50,8 @@ class Backend():
# self.devices = OrderedDict() ### will contain the list of nodes in the network
# self.sensors = OrderedDict() ### will contain the list of sensors (only) in the network
self.node_added = False
self.node_removed = False
self.timestamps = {} ### will contain the time of the last values' update for each sensor
self.node_removed = False
self.timestamps = {} ### will contain the time of the last values' update for each sensor
self.queryStages = { ### the diffrent stages that a node object gets through before being ready
"None" : 1, # Query process hasn't started for this node
"ProtocolInfo" : 2, # Retrieve protocol information
......@@ -211,7 +211,7 @@ class Backend():
values = node.get_values("All","All","All",False,"All")
for value in values.itervalues():
#print("%s %s %s" % (value.label, value.data, value.units))
if value.label == "Group 1 Interval":
if value.label == "Group 1 Interval":
value.data = Grp_interval # Group 1 Reports sent every 240 seconds
if value.label == "Group 1 Reports":
value.data = Grp_reports # Group 1 Reports : Temperature, Luminance, Humidity and battery
......@@ -230,61 +230,33 @@ class Backend():
def network_nodesConfiguration(self):
# this method returns a html containing the configuration of the network's nodes
result = "<h1>Network Configuration</h1>"
result += "<p>Home ID = " + self.network.home_id_str + "</p></br>"
result += """<table style="text-align: center; width: 100%; margin: auto; border-collapse: collapse; border: 1px solid black;">
<tr>
<th>ID</th>
<th>Powered by</th>
<th>Wake-up Interval</th>
<th>Wake up 10 minutes when</br>batteries are inserted</th>
<th>On Time</th>
<th>Enable Motion Sensor</th>
<th>Command Options</th>
<th colspan="2">Group 1</th>
<th colspan="2">Group 2</th>
<th colspan="2">Group 3</th>
</tr>
<tr>
<th colspan="7"></th>
<th>Reports</th>
<th>Interval</th>
<th>Reports</th>
<th>Interval</th>
<th>Reports</th>
<th>Interval</th>
</tr>
"""
result = {}
result ['Network Home ID'] = self.network.home_id_str
for node in self.ordered_nodes_dict().itervalues():
if node.isReady and node.node_id is not 1:
node.request_all_config_params()
values = node.get_values("All","All","All",False,"All") #Config + System pour Wake-up interval
result += "<tr style='border: 1px solid black;'>"
nodeValues = {}
for value in values.itervalues():
#nodeValues[cle] = {}...
#nodeValues[value.value_id]...
#nodeValues[valeur.label]...
nodeValues[int(value.index)] = value.data
result += "<td>"+str(node.node_id)+"</td>"
result += "<td>"
result += "USB" if node.is_listening_device else "Batteries"
result += "</td>"
result += "<td>"+str(nodeValues[0])+"</td>"
result += "<td>"+str(nodeValues[2])+"</td>"
result += "<td>"+str(nodeValues[3])+"</td>"
result += "<td>"+str(nodeValues[4])+"</td>"
result += "<td>"+str(nodeValues[5])+"</td>"
result += "<td>"+str(nodeValues[101])+"</td>"
result += "<td>"+str(nodeValues[111])+"</td>"
result += "<td>"+str(nodeValues[102])+"</td>"
result += "<td>"+str(nodeValues[112])+"</td>"
result += "<td>"+str(nodeValues[103])+"</td>"
result += "<td>"+str(nodeValues[113])+"</td>"
result += "</tr>"
result += "</table>"
return result
print str(value.index)+" "+str(value.label)+" "+str(value.data)+" id:"+str(node.node_id)
info = {}
info ['Node ID'] = str(node.node_id)
info ['Wake-up Interval'] = str(nodeValues[0])
info ['Enable Motion Sensor'] = str(nodeValues[4])
info ['Group 1 Reports'] = str(nodeValues[101])
info ['Group 1 Interval'] = str(nodeValues[111])
info ['Group 2 Reports'] = str(nodeValues[102])
info ['Group 2 Interval'] = str(nodeValues[112])
info ['Group 3 Reports'] = str(nodeValues[103])
info ['Group 3 Interval'] = str(nodeValues[113])
result ['Node '+str(node.node_id)] = info
return jsonify(result)
################################################################################################################
......@@ -293,18 +265,18 @@ class Backend():
def start(self):
# this method starts the software representation
# this method starts the software representation
global started
if started:
print "Already started "
print "Already started"
return
started = True
self.network.start()
print "Z-Wave Network Starting..."
for i in range(0, 300):
if self.network.is_ready:
if self.network.state == self.network.STATE_READY:
break
else:
time.sleep(1.0)
......@@ -319,7 +291,7 @@ class Backend():
# this method stops the software representation
global started
started = False
started = False
print "Stopping Z-Wave Network... "
self.network.stop()
......@@ -400,7 +372,7 @@ class Backend():
def allMeasures(self, n):
for node in self.network.nodes.itervalues():
if node.node_id == n and node.isReady and n != 1 :
if node.node_id == n and node.isReady and n != 1 and "timestamp"+str(node.node_id) in self.timestamps:
values = node.get_values("All", "User", "All", True, False)
if len(node.location) < 3:
node.location = configpi.sensors[str(node.node_id)][:4]
......@@ -425,7 +397,7 @@ class Backend():
def temperature(self, n):
for node in self.network.nodes.itervalues():
if node.node_id == n and node.isReady and n != 1 :
if node.node_id == n and node.isReady and n != 1 and "timestamp"+str(node.node_id) in self.timestamps:
values = node.get_values(0x31, "User", "All", True, False)
for value in values.itervalues():
if value.label == "Temperature":
......@@ -437,7 +409,7 @@ class Backend():
def humidity(self, n):
for node in self.network.nodes.itervalues():
if node.node_id == n and node.isReady and n != 1 :
if node.node_id == n and node.isReady and n != 1 and "timestamp"+str(node.node_id) in self.timestamps:
values = node.get_values(0x31, "User", "All", True, False)
for value in values.itervalues():
if value.label == "Relative Humidity":
......@@ -449,7 +421,7 @@ class Backend():
def luminance(self, n):
for node in self.network.nodes.itervalues():
if node.node_id == n and node.isReady and n != 1 :
if node.node_id == n and node.isReady and n != 1 and "timestamp"+str(node.node_id) in self.timestamps:
values = node.get_values(0x31, "User", "All", True, False)
for value in values.itervalues():
if value.label == "Luminance":
......@@ -461,7 +433,7 @@ class Backend():
def motion(self, n):
for node in self.network.nodes.itervalues():
if node.node_id == n and node.isReady and n != 1 :
if node.node_id == n and node.isReady and n != 1 and "timestamp"+str(node.node_id) in self.timestamps:
values = node.get_values(0x30, "User", "All", True, False)
for value in values.itervalues():
if value.label == "Sensor":
......@@ -473,7 +445,7 @@ class Backend():
def battery(self, n):
for node in self.network.nodes.itervalues():
if node.node_id == n and node.isReady and n != 1 :
if node.node_id == n and node.isReady and n != 1 and "timestamp"+str(node.node_id) in self.timestamps:
val = node.get_battery_level()
return jsonify(controller = name, sensor = node.node_id, location = node.location, type = "battery", updateTime = self.timestamps["timestamp"+str(node.node_id)], value = val)
return "Node not ready or wrong sensor node !"
......
......@@ -33,6 +33,31 @@ def index():
@apiSuccess {JSON} Table Network's Information.
@apiSuccessExample {json} Example data on success:
{
"Network Home ID": "0xe221b13f",
"Node 1": {
"Is Ready": true,
"Neighbours": "2",
"Node ID": "1",
"Node location": "",
"Node name": "",
"Product name": "Z-Stick Gen5",
"Query Stage": "Complete",
"Query Stage (%)": "100 %"
},
"Node 2": {
"Is Ready": true,
"Neighbours": "1",
"Node ID": "2",
"Node location": "",
"Node name": "",
"Product name": "MultiSensor 6",
"Query Stage": "Complete",
"Query Stage (%)": "100 %"
}
}
@apiDescription Gets the configuration of the Z-Wave network in a JSON format
"""
......@@ -66,7 +91,23 @@ def network_configureNodes(Grp_interval,Grp_reports,Wakeup_interval):
@apiName Networks' Nodes configuration
@apiGroup Admin
@apiSuccess {html} Table Describing of the nodes' configuration.
@apiSuccess {JSON} Table Describing of the nodes' configuration.
@apiSuccessExample {json} Example data on success:
{
"Network Home ID": "0xe221b13f",
"Node 2": {
"Enable Motion Sensor": "Enabled level 5 (maximum sensitivity",
"Group 1 Interval": "3600",
"Group 1 Reports": "241",
"Group 2 Interval": "3600",
"Group 2 Reports": "0",
"Group 3 Interval": "3600",
"Group 3 Reports": "0",
"Node ID": "2",
"Wake-up Interval": "240"
}
}
@apiDescription Gets a html with the list of nodes and their configuration parameters
......@@ -595,7 +636,7 @@ if __name__ == '__main__':
file_handler.setFormatter(Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
app.logger.addHandler(file_handler)
app.run(host='::', debug=False, use_reloader=False)
app.run(host='::', debug=False, use_reloader=False, port=5000)
except KeyboardInterrupt:
backend.stop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment