本文整理匯總了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)