iT邦幫忙

2023 iThome 鐵人賽

0
SideProject30

人機控制介面之開發應用系列 第 33

Webhooks & Line 連動 by Pico-w 01/15

  • 分享至 

  • xImage
  •  

設計make:

  • Webhooks & LINE 連動
#make
https://hook.us1.make.com/xxxxxxxxxxxxx?date=2024-01-15-15:30:00&temperature=28.448&from=地點

from tools import connect, reconnect
from machine import ADC, Pin, Timer, RTC
import time
import urequests

connect()
adc = ADC(4)
conversion_factor = 3.3/65535

start_time = 0
duration = 60

def alert(temp):
    global start_time
    if(time.ticks_diff(time.ticks_ms(), start_time) >= duration * 1000):
        print("傳送訊息給maker")
        rtc = RTC()
        date_tuple = rtc.datetime()
        date_str = f'{date_tuple[0]}-{date_tuple[1]}-{date_tuple[2]} {date_tuple[4]}:{date_tuple[5]}:{date_tuple[6]}'
        url_str = f'https://hook.us1.make.com/xxxxxxxxxxxx?date={date_str}&temperature={temp}&from=某個位置'
        try:
            response = urequests.get(url_str)
        except :
            print("AP出問題")
            reconnect()
        else:
            if response.status_code == 200:
                print("傳送成功")
            else:
                print("傳送失敗(make服務出問題)")
        start_time = time.ticks_ms()

def second1(t):
    reading_v = adc.read_u16() * conversion_factor
        
    celsius = 27 - (reading_v-0.706) / 0.001721
    print(celsius)
    if (celsius >= 25):
        alert(celsius)
        
tim1 = Timer()
tim1.init(period=1000, callback=second1)

上一篇
Python_OpenAPI_VScode_Thonny_0112
下一篇
儲存資料至redis,並取出全部資料
系列文
人機控制介面之開發應用37
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言