[問題] LINE bot回傳數值的問題
不好意思我是Python新手
目前在做LINE bot回傳raspberry pi溫度監測數值的作業
網路上的資源大多都教直接回傳原訊息
我的是收到user傳送來的特定字元時會偵測sensor的溫度並回傳
因為不太熟 app跟functino一直想不出來 想請各位大神指點
app.py
reply = event.message.text
if message.count('temp'):
function.temperature()
temperature = function.temperature
reply = temperature
function.py
dht = adafruit_dht.DHT(board.D17)
def temperature():
temperature = dht.temperature
print (temperature)
return temperature
======
function.py的print是為了驗證能顯示出來結果真的可以在設備上看到溫度
但是執行時有這個錯誤不知道怎麼排除
Object of type function is not JSON serializable
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.160.231.139 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1641286987.A.4B8.html
→
01/04 17:06,
3年前
, 1F
01/04 17:06, 1F
→
01/04 17:06,
3年前
, 2F
01/04 17:06, 2F
→
01/04 17:07,
3年前
, 3F
01/04 17:07, 3F
推
01/04 18:31,
3年前
, 4F
01/04 18:31, 4F
感謝你們熱心提供解答及方向
後來app.py改寫如下 已經可以正常運作
留個紀錄
if message.count('temp'):
function.temperature()
temperature = function.temperature()
line_bot_api.reply_message(event.reply_token,
TextSendMessage(text="Temperature is" + str(temperature)))
※ 編輯: TheSims4 (1.160.231.44 臺灣), 01/04/2022 23:53:00
推
01/05 00:06,
3年前
, 5F
01/05 00:06, 5F
Python 近期熱門文章
PTT數位生活區 即時熱門文章