本文整理汇总了Python中arduino.Arduino.get_temperatures方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.get_temperatures方法的具体用法?Python Arduino.get_temperatures怎么用?Python Arduino.get_temperatures使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arduino.Arduino
的用法示例。
在下文中一共展示了Arduino.get_temperatures方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CloudSensor
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import get_temperatures [as 别名]
#.........这里部分代码省略.........
else:
self.mute = False
self.mutebutton.config(text='Mute')
def updatetmp(self):
''' Update the temperatures and gui.
Also check if we need to raise alarm.
'''
if self.stop:
self.frame.after(polldelay, self.updatetmp)
return
if 'Client' in self.csmode.get():
try:
if self.socket is not None:
self.socket.close()
self.socket = None
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect((socket.gethostname(), 8001))
mesg = self.socket.recv(32).strip('\0')
self.socket.close()
except Exception as msg:
log.error("client exception: " + str(msg))
if mesg is None:
log.warning("Didn't get a response from the server...")
self.frame.after(polldelay, self.updatetmp)
return
else:
[a, b, c] = mesg.split(';')
self.timearray.append(datetime.datetime.strptime(a.split('.')[0], '%Y-%m-%d %H:%M:%S'))
self.skytmphist.append(int(b))
self.ambtmphist.append(int(c))
else:
log.debug("Arduino is connected? " + str(self.uno.isconnected()))
if self.uno.isconnected() == True:
# Add workaround for 1037.55
newtmp, anewtmp = self.uno.get_temperatures()
if newtmp == '1037.55':
try:
self.skytmphist.append(self.skytmphist[-1])
except IndexError:
self.skytmphist.append('0')
else:
self.skytmphist.append(newtmp)
if anewtmp == '1037.55':
try:
self.ambtmphist.append(self.ambtmphist[-1])
except IndexError:
self.ambtmphist.append('0')
else:
self.ambtmphist.append(anewtmp)
templog.debug("sky=" + str(newtmp) + ":ambient=" + str(anewtmp))
else:
newtmp = randint(0, 100)
anewtmp = randint(0, 100)
templog.debug("sky=" + str(newtmp) + ":ambient=" + str(anewtmp))
self.skytmphist.append(newtmp)
self.ambtmphist.append(anewtmp)
tnow = datetime.datetime.now()
self.timearray.append(tnow)
self.skytemp.config(text=str(self.skytmphist[-1]))
self.ambtemp.config(text=str(self.ambtmphist[-1]))
self.__updateplot()
if (float(self.skytmphist[-1]) > float((self.threshold.get()))) and not self.mute:
log.debug("BEEEEEEEPPPPPP")
if sys.platform == 'darwin':
audio_file = "Siren_Noise.wav"
subprocess.Popen(["afplay " + audio_file], shell=True,
stdin=None, stdout=None, stderr=None,
close_fds=True)
self.frame.after(polldelay, self.updatetmp)
def network(self):
''' Either Run a tcp server that a client can connect to
or run a client to connect to a server
or do nothing.
'''
mode = self.csmode.get()
# print mode
if 'Off' in mode:
self.frame.after(offdelay, self.network)
return
elif 'Server' in mode:
if self.socket is None:
self.socket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
self.socket.bind((socket.gethostname(), 8001))
self.socket.setblocking(0)
self.socket.listen(5)
try:
cstring = str(self.timearray[-1]) + ";" + \
str(self.skytmphist[-1]) + ";" + \
str(self.ambtmphist[-1]) + "\0"
a, b, c = select.select([self.socket], [], [], 0)
for s in a:
client_socket, address = self.socket.accept()
client_socket.send(cstring)
except Exception as msg:
log.error("exception1: " + str(msg))
self.frame.after(serverdelay, self.network)