本文整理汇总了Python中sensor.Sensor方法的典型用法代码示例。如果您正苦于以下问题:Python sensor.Sensor方法的具体用法?Python sensor.Sensor怎么用?Python sensor.Sensor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sensor
的用法示例。
在下文中一共展示了sensor.Sensor方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_read_sensor
# 需要导入模块: import sensor [as 别名]
# 或者: from sensor import Sensor [as 别名]
def add_read_sensor(self, sensor_kind, sensor_id, sensor_name):
if sensor_id in self.__sensors__:
raise ValueError("{0} have been added".format(sensor_id))
return
new_sensor = Sensor(sensor_kind, sensor_id, sensor_name)
value_property = SProperty("value", 0, None, 0)
new_sensor.add_property(value_property)
self.__sensors__[sensor_id] = new_sensor
示例2: add_action_sensor
# 需要导入模块: import sensor [as 别名]
# 或者: from sensor import Sensor [as 别名]
def add_action_sensor(self, sensor_kind, sensor_id, sensor_name, action_function=None):
if sensor_id in self.__sensors__:
raise ValueError("{0} have been added".format(sensor_id))
return
new_sensor = Sensor(sensor_kind, sensor_id, sensor_name)
action_on = SAction("on")
action_off = SAction("off")
new_sensor.add_action(action_on)
new_sensor.add_action(action_off)
self.__sensors__[sensor_id] = new_sensor
if action_function is not None:
self.__actions__[sensor_id] = action_function
示例3: add_custom_sensor_with_action
# 需要导入模块: import sensor [as 别名]
# 或者: from sensor import Sensor [as 别名]
def add_custom_sensor_with_action(self, sensor, action):
if sensor.id in self.__sensors__:
raise ValueError("{0} have been added".format(sensor.id))
return
if isinstance(sensor, Sensor):
self.__sensors__[sensor.id] = sensor
if action is not None:
self.__actions__[sensor.id] = action
else:
raise ValueError("argument should be the instance of Sensor")
示例4: pushSensorData
# 需要导入模块: import sensor [as 别名]
# 或者: from sensor import Sensor [as 别名]
def pushSensorData(self, enCoSensor, debug = False, forceCreateChannel = False):
if not enCoSensor or not isinstance(enCoSensor , Sensor):
raise OSError('\'Sensor\' parameter undefined or wrong type!')
if self.OVERCC:
if self.CC_HTTP:
self.pushSensorDataCloudChannels(enCoSensor, debug, forceCreateChannel)
else:
self.pushSensorDataMQTT(enCoSensor, debug)
else:
self.pushSensorDataSEaaS(enCoSensor, debug)
示例5: pushSensorDataMQTT
# 需要导入模块: import sensor [as 别名]
# 或者: from sensor import Sensor [as 别名]
def pushSensorDataMQTT(self, attSensor, debug = False):
if not attSensor or not isinstance(attSensor , Sensor):
raise OSError('\'Sensor\' parameter undefined or wrong type!')
if self.mqtt == None:
print ("Instantiationg MQTT client")
self.mqtt = mqttC(attSensor.getDeviceId(),"mqtt.enco.io", user="ogmog3qcdve6lk9g", password="ogmog3qcdve6lk9g")
print ("Connecting & publishing .....")
self.mqtt.connect()
self.mqtt.publish(attSensor.getStreamId(),dumps(attSensor.getAsJson()))
self.mqtt.disconnect()
print("MQTT disco")
示例6: pushSensorDataSEaaS
# 需要导入模块: import sensor [as 别名]
# 或者: from sensor import Sensor [as 别名]
def pushSensorDataSEaaS(self, attSensor, debug = False):
if not attSensor or not isinstance(attSensor , Sensor):
raise OSError('\'Sensor\' parameter undefined or wrong type!')
self._getToken(debug)
if isinstance(attSensor , M2M_Sensor):
data = attSensor.getData()
data["containerId"] = attSensor.getContainerId()
deviceId = attSensor.getContainerId()
else:
data = {}
data["containerId"] = attSensor.getStreamId()
data["typedMessage"] = {"json_payload": dumps(attSensor.getAsJson())}
deviceId = attSensor.getStreamId()
data["macAddress"] = attSensor.getDeviceId()
data["timestamp"] = attSensor.timestamp
putUrl = "{}/device/{}/stream/{}/add".format(self.connectToURLforSEaaS, attSensor.getDeviceId(), deviceId)
if debug:
print('Sending endpoint : ', putUrl)
print('Payload : ', data)
auth_header = {'Authorization':'Bearer {}\r\n'.format(self.tokenBearer), 'Accept':'application/json'}
resp = http_client.put(putUrl, headers=auth_header, json=data, debug = debug)
if debug: print (resp.getStatus())
resp.raise_for_status()
resp.close()
示例7: pushSensorDataCloudChannels
# 需要导入模块: import sensor [as 别名]
# 或者: from sensor import Sensor [as 别名]
def pushSensorDataCloudChannels(self, enCoSensor, debug = False, forceCreateChannel = False):
data = enCoSensor.getAsJson()
self._getToken(debug)
if not self.sensorHasCCDefinition(enCoSensor, debug):
if debug: print("-- Sensor has NO CC-IN stream definition.")
self._createCCInStreamDefinition(enCoSensor, debug)
else:
if forceCreateChannel:
self._createCCInStreamDefinition(enCoSensor, debug)
if debug: print("-- Sensor HAD CC-IN stream definition! BUT RECREATED !!")
else:
if debug: print("-- Sensor HAS CC-IN stream definition!")
postUrl = "{}/cc/u/{}".format(self.connectToURLforCC_In, enCoSensor.getCloudChannelCustomHTTP())
if debug:
print('Sending endpoint : ', postUrl)
print('Payload : ', data)
auth_header = {'Authorization':'Bearer {}\r\n'.format(self.tokenBearer), 'Accept':'application/json'}
#TODO : investigate why binary path causes 500 error, send as JSON seems to work ....
resp = http_client.post(postUrl, headers=auth_header, json=data, debug = debug)
# if enCoSensor.sendAsBinary() != True:
# resp = http_client.post(postUrl, headers=auth_header, json=data, debug = debug)
# else:
# resp = http_client.post(postUrl, headers=auth_header, binary=data, debug = debug)
if debug: print (resp.getStatus())
resp.raise_for_status()
resp.close()
示例8: sensorHasMessageDefinition
# 需要导入模块: import sensor [as 别名]
# 或者: from sensor import Sensor [as 别名]
def sensorHasMessageDefinition(self, sensor, debug = False):
if not sensor or not isinstance(sensor , Sensor):
raise OSError('\'sensor\' parameter undefined or wrong type!')
if sensor.hasCCINdefinition == False:
if debug:
print("performg STREAM check")
sensor.hasCCINdefinition = self.checkIfMessageDefinitionExists(sensor.getStreamId(), debug)
else:
if debug:
print("stream was checked before !!")
return sensor.hasCCINdefinition
示例9: createCCInDefinition
# 需要导入模块: import sensor [as 别名]
# 或者: from sensor import Sensor [as 别名]
def createCCInDefinition(self, enCoSensor, debug=False):
if not isinstance(enCoSensor , Sensor):
raise OSError('Invalid \'Sensor\' parameter!')
self.connection._createCCInStreamDefinition(enCoSensor, debug)