def main(arguments): """ Accept the command to either read or actuate the Wemo Switch. Args as Data: 'r': Read the energy data from the Switch and update the metadata on the Building Depot. 'w': Actuate the Wemo Switch to switch on and off. Returns: If the args is to read energy data from Wemo { "success": "True" "HTTP Error 400": "Bad Request" } If the args is to Actuate the Wemo Switch, then {on/off : success} else {"Device Not Found/Error in fetching data"} """ global status, data cmd = arguments[1] if 'r' == cmd: switch = WemoSensor() try: switch = WemoSensor() switch.get_device_data() except Exception as e: print "Device Not Found/Error in fetching data" print e exit(0) """Posts json object information to BD_Connect in this format data={"sensor_data":{<all sensor data>}, "client_data":{<all client data>}}""" try: print get_json(json.dumps(data)) print "Response from bd_connnect.py" except Exception as e: print e elif 'w' == cmd: switch = WemoActuator() try: # Uncomment any of these to actuate Wemo Switch switch.output(switch.on()) # output(switch.off()) # output(switch.toggle()) # output(switch.status()) except Exception as e: print "Device Not Found" print str(e)
def read_sensor_value(self, node_id, value_id): """ Read one sensor value from a specified node, after which the data will be posted to BuildingDepot using RESTful api. Note: The sensor points will be skipped once the value is not specified in zwave.json (listen item) or the node is not connected property. Args: node_id: the id of sepcified node value_id: the id of value (sensor point) on the specified node Return: status string indicates the sensing and posting process """ global listen node = self.network.nodes[node_id] value = node.values[value_id] if node_id in listen and \ value.label in listen[node_id] and\ ZwaveNetwork.check_node_connection(self.network, node_id) and \ value_id in node.get_sensors(): sdata = {} sdata["mac_id"] = ZwaveSensor.get_mac_id(node, value) # get sensor data sdata[ZwaveSensor.get_source_name(self.network, node, value)] = \ node.get_sensor_value(value_id) # assemble data data = {"sensor_data":{}} data["sensor_data"].update(sdata) # post data print(data) return str(get_json(json.dumps(data))) # return a string return ""
def post_to_bd(self, station_data): """ Format of the JSON Object to be sent to bd_connect.py. sensor_data contains all information from sensor to be Read and sensor_points to be created in accordance with that. client_data contains all information about client_id,client_keyetc for authentication data={"sensor_data":{}} Args : {<Lifx bulb data>,<brightness>, <hue> etc.} Returns: { "success": "True" "HTTP Error 400": "Bad Request" } """ global mac_id print station_data data = {'sensor_data': {}} data['sensor_data'].update(station_data) data['sensor_data'].update({"mac_id": mac_id}) try: resp = get_json(json.dumps(data)) except Exception as e: print e return resp
def thread_post_bd(data): """ a thread routine to post the passed in data to building depot Args: snesed data: sensor_data: { mac_id: <node id (48bits)>, <All other sensor data> } """ global thread_counter print(data) print(get_json(json.dumps(data))) # has some issues here! thread_counter -= 1
def alarm_thread_post_bd(data): """ a thread routine to post the passed in data to building depot Args: snesed data: sensor_data: { <attribute/meta data> <sensor data> } Return: None """ print(data) print(get_json(json.dumps(data))) # has some issues here! # remove from pool after finishing if threading.current_thread() in threads: threads.remove(threading.current_thread())
def post_to_bd(self, deviceData): """ Post json object information to BD_Connect in this format data={"sensor_data":{<all sensor data>}} Args as data: {<netatmo station data>} Returns: { "success": "True" "HTTP Error 400": "Bad Request" } """ data = {'sensor_data': {}} data['sensor_data'].update(deviceData) response = get_json(json.dumps(data)) return response
def post_to_bd(self, mother_data): """ Format of the JSON Object to be sent to bd_connect.py. sensor_data contains all information from sensor to be Read and sensor_points to be created in accordance with that. client_data contains all information about client_id,client_key etc for authentication data={"sensor_data":{}} Args: {<Sen.se mothers data>} Returns: { "success": "True" "HTTP Error 400": "Bad Request" } """ data = {'sensor_data': {}} data['sensor_data'].update(mother_data) data['sensor_data'].update({"mac_id": self.mac_id}) response = get_json(json.dumps(data)) return response
def main(): d = DummySensor() get_json(json.dumps(d.data))