Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用IFTTT从Pi向手机发送温度和湿度信息时出现故障_Python_Raspberry Pi_Pi - Fatal编程技术网

Python 使用IFTTT从Pi向手机发送温度和湿度信息时出现故障

Python 使用IFTTT从Pi向手机发送温度和湿度信息时出现故障,python,raspberry-pi,pi,Python,Raspberry Pi,Pi,我正在尝试为爬行动物水箱制作一个远程温度和湿度监测系统,作为我的Pi模型3B+和SenseHat的概念证明。我能够很好地检索和显示信息,但是在将信息发送到手机时遇到了问题。我正在使用IFTTT和Pushbullet来实现这一点,但我尝试过的方法都不起作用。以下是我迄今为止的代码: from sense_hat import SenseHat import time import requests sense = SenseHat() sense.clear() number = [ 0,1,

我正在尝试为爬行动物水箱制作一个远程温度和湿度监测系统,作为我的Pi模型3B+和SenseHat的概念证明。我能够很好地检索和显示信息,但是在将信息发送到手机时遇到了问题。我正在使用IFTTT和Pushbullet来实现这一点,但我尝试过的方法都不起作用。以下是我迄今为止的代码:

from sense_hat import SenseHat
import time
import requests

sense = SenseHat()
sense.clear()

number = [
0,1,1,1, # Zero
0,1,0,1,
0,1,0,1,
0,1,1,1,
0,0,1,0, # One
0,1,1,0,
0,0,1,0,
0,1,1,1,
0,1,1,1, # Two
0,0,1,1,
0,1,1,0,
0,1,1,1,
0,1,1,1, # Three
0,0,1,1,
0,0,1,1,
0,1,1,1,
0,1,0,1, # Four
0,1,1,1,
0,0,0,1,
0,0,0,1,
0,1,1,1, # Five
0,1,1,0,
0,0,1,1,
0,1,1,1,
0,1,0,0, # Six
0,1,1,1,
0,1,0,1,
0,1,1,1,
0,1,1,1, # Seven
0,0,0,1,
0,0,1,0,
0,1,0,0,
0,1,1,1, # Eight
0,1,1,1,
0,1,1,1,
0,1,1,1,
0,1,1,1, # Nine
0,1,0,1,
0,1,1,1,
0,0,0,1
]


#celcius_color = [255,0,0] # Red
fahrenheit_color = [0,255,0] # Green
#negative_celcius_color = [0,255,255] # Cyan
negative_fahrenheit_color = [0,0,255] # Blue
empty = [0,0,0] # Black
humidity_color = [0,255,255] # Cyan
negative_humidity_color = [255,0,0] # Red

display = [
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0
]

while True:
    celcius = int(round(sense.get_temperature()))
    fahrenheit = int(round(1.8 * celcius + 32))
    humidity = int(round(sense.get_humidity()))

    if humidity < 0:
        humidity = abs(humidity)
        humidity_color = negative_humidity_color
    if fahrenheit < 0:
        fahrenheit = abs(fahrenheit)
        fahrenheit_color = negative_fahrenheit_color

    # Map digits to the display array
    pixel_offset = 0
    index = 0
    for index_loop in range(0, 4):
        for counter_loop in range(0, 4):
            display[index] = 
number[int(humidity/10)*16+pixel_offset]
                display[index+4] = 
number[int(humidity%10)*16+pixel_offset]
                display[index+32] = 
number[int(fahrenheit/10)*16+pixel_offset]
                display[index+36] = 
number[int(fahrenheit%10)*16+pixel_offset]
            pixel_offset = pixel_offset + 1
            index = index + 1
        index = index + 4

    # Color the temperatures
    for index in range(0, 64):
        if display[index]:
            if index < 32:
                display[index] = humidity_color
            else:
                display[index] = fahrenheit_color
        else:
            display[index] = empty

    
    
    # Display the temperatures
    sense.low_light = True # Optional
    sense.set_pixels(display)
    time.sleep(1)
c_val = 0
h_val = 0
celcius = int(round(sense.get_temperature()))
fahrenheit = int(round(1.8 * celcius + 32))
humidity = int(round(sense.get_humidity()))
while ((celcius['']>c_val) or (humidity['']>h_val)):
    celcius = int(round(sense.get_temperature()))
    fahrenheit = int(round(1.8 * celcius + 32))
    humidity = int(round(sense.get_humidity())) 
    
while True:
    celcius = int(round(sense.get_temperature()))
    fahrenheit = int(round(1.8 * celcius + 32))
    humidity = int(round(sense.get_humidity())) 
    if ((celcius['1']>c_val) or (humidity['1']>h_val)):
        print('monitoring...')
        r = requests.post('https://maker.ifttt.com/trigger/climate_monitor/with/key/MY_KEY', params={"value1":"str(fahrenheit)","value2":"str(humidity)","value3":"none"})
        time.sleep(5)
        celcius = int(round(sense.get_temperature()))
        fahrenheit = int(round(1.8 * celcius + 32))
        humidity = int(round(sense.get_humidity()))
从sense\u hat导入SenseHat
导入时间
导入请求
sense=SenseHat()
明白
数字=[
0,1,1,1,0
0,1,0,1,
0,1,0,1,
0,1,1,1,
0,0,1,0,1
0,1,1,0,
0,0,1,0,
0,1,1,1,
0,1,1,1,2
0,0,1,1,
0,1,1,0,
0,1,1,1,
0,1,1,1,3
0,0,1,1,
0,0,1,1,
0,1,1,1,
0,1,0,1,4
0,1,1,1,
0,0,0,1,
0,0,0,1,
0,1,1,1,5
0,1,1,0,
0,0,1,1,
0,1,1,1,
0,1,0,0,6
0,1,1,1,
0,1,0,1,
0,1,1,1,
0,1,1,1,7
0,0,0,1,
0,0,1,0,
0,1,0,0,
0,1,1,1,8
0,1,1,1,
0,1,1,1,
0,1,1,1,
0,1,1,1,9
0,1,0,1,
0,1,1,1,
0,0,0,1
]
#celcius#u颜色=[255,0,0]#红色
华氏温度颜色=[0255,0]#绿色
#负片颜色=[0255255]#青色
负华氏度颜色=[0,0255]#蓝色
空=[0,0,0]#黑色
湿度颜色=[0255255]#青色
负湿度颜色=[255,0,0]#红色
显示=[
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0
]
尽管如此:
celcius=int(圆形(sense.get_temperature())
华氏温度=整数(圆形(1.8*celcius+32))
湿度=int(圆形(sense.get\u湿度())
如果湿度<0:
湿度=abs(湿度)
湿度颜色=负湿度颜色
如果华氏温度<0:
华氏度=绝对值(华氏度)
华氏温度颜色=负华氏温度颜色
#将数字映射到显示阵列
像素偏移=0
索引=0
对于范围(0,4)中的索引_循环:
对于范围(0,4)内的计数器_循环:
显示[索引]=
数字[int(湿度/10)*16+像素偏移]
显示[索引+4]=
数字[int(湿度%10)*16+像素\u偏移]
显示[索引+32]=
数字[int(华氏/10)*16+像素偏移]
显示[索引+36]=
数字[int(华氏%10)*16+像素偏移]
像素偏移=像素偏移+1
索引=索引+1
索引=索引+4
#给温度上色
对于范围(0,64)中的索引:
如果显示[索引]:
如果索引<32:
显示[索引]=湿度\u颜色
其他:
显示[索引]=华氏度颜色
其他:
显示[索引]=空
#显示温度
sense.low_light=True#可选
感测。设置像素(显示)
时间。睡眠(1)
c_val=0
h_val=0
celcius=int(圆形(sense.get_temperature())
华氏温度=整数(圆形(1.8*celcius+32))
湿度=int(圆形(sense.get\u湿度())
而((塞尔修斯[''']>c_val)或(湿度[''']>h_val)):
celcius=int(圆形(sense.get_temperature())
华氏温度=整数(圆形(1.8*celcius+32))
湿度=int(圆形(sense.get\u湿度())
尽管如此:
celcius=int(圆形(sense.get_temperature())
华氏温度=整数(圆形(1.8*celcius+32))
湿度=int(圆形(sense.get\u湿度())
如果((celcius['1']>c_val)或(湿度['1']>h_val)):
打印('监视…')
r=请求。post('https://maker.ifttt.com/trigger/climate_monitor/with/key/MY_KEY,参数={“value1”:“str(华氏)”,“value2”:“str(湿度)”,“value3”:“none”})
时间。睡眠(5)
celcius=int(圆形(sense.get_temperature())
华氏温度=整数(圆形(1.8*celcius+32))
湿度=int(圆形(sense.get\u湿度())
当然,当我在IFTTT链接中有“我的密钥”时,“我的密钥”只是一个占位符,用于发布此信息时的安全目的。我在Pi上的文件中有正确的密钥


非常感谢您提供的任何帮助

您发送的不是温度和湿度,而是一段代码,因为您已将字符串(已经是字符串)括在双引号中

改为这样运行:

import requests

fahrenheit = 73
humidity   = 95

r = requests.post('https://maker.ifttt.com/trigger/climate_monitor/with/key/MY_KEY', params={"value1":str(fahrenheit),"value2":str(humidity),"value3":"none"})

如果获取和显示温度和湿度的所有代码都运行良好,您可以将其删除,并制作一个简单的循环,每5秒向IFTTT发送一个递增的数字…“我尝试过的一切都没有起作用”并没有描述代码中您遇到的问题。另请参阅您应该如何尝试呈现,虽然我们了解,可复制部分可能需要Pi。爬行动物坦克当然可以被嘲笑:)我遇到的问题是代码的IFTTT部分。该代码读取和显示的温度和湿度非常好,但不会将该信息传输给IFTTT。我认为我对代码的最后一行“While”和“While true”有问题。我相信我的变量和参数存在问题,但我不知道如何将温度和湿度变量分配给IFTTT