The external program does not return the correct value in subprocess.

Asked 1 years ago, Updated 1 years ago, 61 views

I am trying to notify the temperature using the Line messaging API.I added the following code to the sample program here, and when I ran "temperature" from LINE, an error was thrown out.What should I do to notify you of the temperature?

app.py

elif text=='Temperature':
        cmd = ["python 3", "dth11.py" ]
        proc=subprocess.Popen(cmd, stdout=subprocess.PIPE,
               stderr=subprocess.STDOUT)
        temp=proc.stdout.read().decode("utf-8")
        line_bot_api.reply_message(event.reply_token, TextSendMessage(text=temp))

dth11.py

importAdafruit_DHT as DHT

SENSOR_TYPE = DHT.DHT11
DHT_GPIO=22
h,t = DHT.read_retry (SENSOR_TYPE, DHT_GPIO)
print("Current room temperature is {0:0.1f} degrees, humidity {1:0.1f}%.US>".format(t,h))

Error Contents

 python3:can't open file'dth11.py':[Errno2] No such file or directory

app.py and dth11.py are in the same directory.Thank you for your cooperation.

python python3 line

2022-09-30 21:38

1 Answers

The file name was simply incorrect.I changed dth11.py to dht11.py and it's fixed.


2022-09-30 21:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.