本文整理汇总了Python中ATT_IOT.send方法的典型用法代码示例。如果您正苦于以下问题:Python ATT_IOT.send方法的具体用法?Python ATT_IOT.send怎么用?Python ATT_IOT.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ATT_IOT
的用法示例。
在下文中一共展示了ATT_IOT.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_message
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def on_message(id, value):
global nextVal
if id.endswith(str(Out1Id)) == True:
print("value received: " + value) # the value that we receive from the cloud is a string
IOT.send(value, Out1Id) #provide feedback to the cloud that the operation was successful, the value is still a string, so we can simply send it back to the cloud.
nextVal = int(value) # convert the received data, which is a string, into an integer
else:
print("unknown actuator: " + id)
示例2: on_message
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def on_message(id, value):
if id.endswith(str(Led)) == True:
value = value.lower() #make certain that the value is in lower case, for 'True' vs 'true'
if value == "true":
grovepi.digitalWrite(Led, 1)
IOT.send("true", Led) #provide feedback to the cloud that the operation was succesful
elif value == "false":
grovepi.digitalWrite(Led, 0)
IOT.send("false", Led) #provide feedback to the cloud that the operation was succesful
else:
print("unknown value: " + value)
示例3: setBacklight
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def setBacklight(value):
'''turn on/off the backlight
value: string ('true' or 'false')
returns: true when input was succesfully processed, otherwise false
'''
if value == "true":
GPIO.output(LISIPAROIPin, GPIO.HIGH)
elif value == "false":
GPIO.output(LISIPAROIPin, GPIO.LOW)
else:
print("unknown value: " + value)
IOT.send(value, ToggleLISIPAROIId) #provide feedback to the cloud that the operation was succesful
示例4: TurnWaterOn
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def TurnWaterOn():
global WaterRelaisState
"""Turn the water on"""
try:
GPIO.output(WaterRelaisPin, False) # pin takes reversed value.
WaterRelaisState = True
if (
IsConnected
): # no need to try and send the state if not yet connected, will be updated when connection is successfull
IOT.send("true", WaterRelaisPin)
except:
logging.exception("failed to turn water on")
示例5: SwitchLightsOff
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def SwitchLightsOff():
"""Switch the lights off"""
global LightRelaisState
try:
LightRelaisState = False
GPIO.output(LightsRelaisPin, True) # pin is reversed value
if (
IsConnected
): # no need to try and send the state if not yet connected, will be updated when connection is successfull
IOT.send("false", LightsRelaisPin)
except:
logging.exception("failed to switch lights off")
示例6: TurnWaterOff
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def TurnWaterOff():
"""Turn the water off"""
global WaterRelaisState
try:
if WaterRelaisState == True:
GPIO.output(WaterRelaisPin, True) # pin takes reversed value
WaterRelaisState = False
if (
IsConnected
): # no need to try and send the state if not yet connected, will be updated when connection is successfull
IOT.send("false", WaterRelaisPin)
except:
logging.exception("failed to turn water off")
示例7: on_message
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def on_message(id, value):
if id.endswith(Out1Id) == True:
value = value.lower() #make certain that the value is in lower case, for 'True' vs 'true'
if value == "true":
print("true on " + Out1Name)
IOT.send("true", Out1Id) #provide feedback to the cloud that the operation was succesful
elif value == "false":
print("false on " + Out1Name)
IOT.send("false", Out1Id) #provide feedback to the cloud that the operation was succesful
else:
print("unknown value: " + value)
else:
print("unknown actuator: " + id)
示例8: on_message
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def on_message(id, value):
if id.endswith(str(ActuatorPin)) == True:
value = value.lower() #make certain that the value is in lower case, for 'True' vs 'true'
if value == "true":
GPIO.output(ActuatorPin, True)
IOT.send("true", ActuatorPin) #provide feedback to the cloud that the operation was succesful
elif value == "false":
GPIO.output(ActuatorPin, False)
IOT.send("false", ActuatorPin) #provide feedback to the cloud that the operation was succesful
else:
print("unknown value: " + value)
else:
print("unknown actuator: " + id)
示例9: setRecord
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def setRecord(value):
if _isPreview:
print("preview not allowed during recording, shutting down preview.")
setPreview(False)
if value == "true":
camera.resolution = (1920, 1080) #set to max resulotion for record
camera.start_recording('video' + datetime.date.today().strftime("%d_%b_%Y_%H_%M%_S") + '.h264')
elif value == "false":
camera.stop_recording()
camera.resolution = (640, 480) #reset resulotion for preview
else:
print("unknown value: " + value)
IOT.send(value, RecordId) #provide feedback to the cloud that the operation was succesful
示例10: setPreview
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def setPreview(value):
if _isRecording:
print("recording not allowed during preview, shutting down recording.")
setRecord(False)
if value == "true":
_isPreview = True
streamer.start_preview()
elif value == "false":
_isPreview = False
streamer.stop_preview()
else:
print("unknown value: " + value)
IOT.send(value, PreviewId) #provide feedback to the cloud that the operation was succesful
示例11: tryConnect
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def tryConnect():
global IsConnected
try:
networkCheckCount = 0
while (
Network.isConnected() == False and networkCheckCount < 5
): # we check a number of times to give the network more time to start up.
networkCheckCount = networkCheckCount + 1
sleep(2)
if Network.isConnected() == False:
logging.error("failed to set up network connection")
else:
# make certain that the device & it's features are defined in the cloudapp
IOT.connect()
# IOT.addAsset(TempSensorPin, TempSensorName, "temperature", False, "number", "Secondary")
# IOT.addAsset(WaterLevelSensorPin, WaterLevelSensorName, "Water level", False, "number", "Secondary")
IOT.addAsset(LightsRelaisPin, LightsRelaisName, "Turn the lights on/off", True, "boolean", "Primary")
IOT.addAsset(WaterRelaisPin, WaterRelaisName, "Turn the water flow on/off", True, "boolean", "Primary")
IOT.addAsset(
ConfigSeasonId,
ConfigSeasonName,
"Configure the season",
True,
"{'type': 'string','enum': ['grow', 'flower']}",
"Config",
)
try:
season = IOT.getAssetState(ConfigSeasonId)
except:
logging.exception("failed to get asset state")
LoadConfig(
season
) # load the cloud settings into the appbefore closing the http connection. otherwise this call fails.
IOT.subscribe() # starts the bi-directional communication
sleep(
2
) # wait 2 seconds until the subscription has succeeded (bit of a hack, better would be to use the callback)
IsConnected = True
IOT.send(
str(LightRelaisState).lower(), LightsRelaisPin
) # provide feedback to the platform of the current state of the light (after startup), this failed while loading config, cause mqtt is not yet set up.
IOT.send(str(WaterRelaisState).lower(), WaterRelaisPin)
except:
logging.exception("failed to set up the connection with the cloud")
IsConnected = False
示例12: on_message
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def on_message(id, value):
if id.endswith(str(ToggleLISIPAROIId)) == True:
value = value.lower() #make certain that the value is in lower case, for 'True' vs 'true'
setBacklight(value)
elif id.endswith(str(PreviewId)) == True:
value = value.lower() #make certain that the value is in lower case, for 'True' vs 'true'
setPreview(value)
elif id.endswith(str(RecordId)) == True:
value = value.lower() #make certain that the value is in lower case, for 'True' vs 'true'
setRecord(value)
elif id.endswith(str(StreamServerId)) == True:
streamer.streamServerIp = value
IOT.send(value, StreamServerId) #provide feedback to the cloud that the operation was succesful
elif id.endswith(str(PictureId)) == True:
if value.lower() == "true":
takePicture()
else:
print("unknown actuator: " + id)
示例13: setConfigSeason
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def setConfigSeason(value):
try:
global scheduler
IOT.send(
value, ConfigSeasonId
) # first return value, in case something went wrong, the config is first stored, so upon restart, the correct config is retrieved.
configs = ConfigParser() # save the configuration
configs.set("general", "season", value)
with open(ConfigFile, "w") as f:
configs.write(f)
if scheduler:
scheduler.shutdown(
wait=False
) # stop any pending jobs so we can recreate them with the new config later on.
scheduler = None
SetClock(value.lower())
StartScheduler()
except:
logging.exception("failed to store new season config")
示例14: setupCloud
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
def setupCloud():
IOT.on_message = on_message
#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
if hasLISIPAROI:
IOT.addAsset(ToggleLISIPAROIId, "LISIPAROI", "Control the light on the camera", False, "boolean")
IOT.addAsset(PreviewId, "Preview", "Show/close a preview on the monitor that is connected to the RPI", True, "boolean")
IOT.addAsset(RecordId, "Record", "Start/stop recording the video stream on sd-card", True, "boolean")
IOT.addAsset(PictureId, "Picture", "take a picture (max resoution) and store on sd-card", True, "boolean")
IOT.addAsset(StreamServerId, "Stream server", "set the ip address of the server that manages the video", True, "string")
# get any previously defined settings
streamer.streamServerIp = IOT.getAssetState(StreamServerId)
if streamer.streamServerIp:
streamer.streamServerIp = streamer.streamServerIp['state']['value']
logging.info("sending stream to: " + streamer.streamServerIp)
else:
logging.info("no stream endpoint defined")
IOT.subscribe() #starts the bi-directional communication
# set current state of the device
IOT.send("false", ToggleLISIPAROIId)
IOT.send("false", PreviewId)
IOT.send("false", RecordId)
示例15: print
# 需要导入模块: import ATT_IOT [as 别名]
# 或者: from ATT_IOT import send [as 别名]
IOT.send("false", Led) #provide feedback to the cloud that the operation was succesful
else:
print("unknown value: " + value)
else:
print("unknown actuator: " + id)
IOT.on_message = on_message
#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(Pir, "PIR", "PIR SENSOR", False, "boolean")
IOT.addAsset(Led, "LED", "Light Emitting Diode", True, "boolean")
IOT.subscribe() #starts the bi-directional communication
#main loop: run as long as the device is turned on
while True:
try:
if grovepi.digitalRead(Pir) == 1:
if Pir_Prev == False:
print("PIR activated")
IOT.send("true", Pir)
Pir_Prev = True
elif Pir_Prev == True:
print("PIR deactivated")
IOT.send("false", Pir)
Pir_Prev = False
sleep(.3)
except IOError:
print ""