Last updated: 11 ก.ย. 2565 | 2472 จำนวนผู้เข้าชม |
สำหรับตัวอย่างข้างต้น ก่อนทำการทดสอบต้องทำการสมัคร Line Notify ก่อนนะครับ แล้วจึงนำ Token ของไลน์มาใช้งาน
This example shows how to use the LINE Notify to send message into LINE group. When monitoring bit "@test" changes, it will trigger and send the message. Please replace with your own Token.
สร้าง bit ใน vbox ชื่อ "Test" สำหรับเทส
ส่วนของ Lua Scrips.
local tempBit = 0
local tempWord = 0
local LineToken = "เปลี่ยน Line Token ตรงนี้"
local https = require("https")
local json = require("json")
local ltn12 = require("ltn12")
-- Send http.get request and return response result
function getHttpsUrl(url,header,reqbody)
local body = {}
local bodyJson = json.encode(body)
local result_table, code, headers, status = https.request{
method = "POST",
url = url,
source = ltn12.source.string(reqbody),
headers = header,
sink = ltn12.sink.table(body)
}
print("code:"..code)
if code~= 200 then
return
else
return body
end
end
function getMessageUrl(lineMessage)
local url = "https://notify-api.line.me/api/notify"
local reqMess = "message="..lineMessage
local headers =
{
["Authorization"] = "Bearer "..LineToken,
["Content-Type"] = "application/x-www-form-urlencoded",
["Content-Length"] = #reqMess
}
print("Get the link:"..url)
getHttpsUrl(url, headers, reqMess)
end
function linenotify.main()
local bitValue = addr_getbit("@test");
local message = ''
print("b=="..bitValue)
if bitValue == 1 and bitValue ~= tempBit then
message = 'Alarm V-Box triggered, the output is '.. bitValue
getMessageUrl(message)
print("Notification pushed of triggering alarm,"..bitValue)
elseif bitValue == 0 and bitValue ~= tempBit then
message = 'Alarm V-Box dismissed, the output is '.. bitValue
getMessageUrl(message)
print("Notification pushed of dismissing alarm,"..bitValue)
end
tempBit = bitValue----Prevent monitoring values from continuous being sent to the platform
local wordValue = addr_getword("@t2")
print("w=="..wordValue)
--dosomething
if wordValue >= 100 and wordValue ~= tempWord and tempWord <= 100 then
message = 'Alarm V-Box triggered, the temperature is '.. wordValue
getMessageUrl(message)
print("Notification pushed of triggering alarm,"..wordValue)
elseif wordValue < 100 and wordValue ~= tempWord and tempWord >= 100 then
message = 'Alarm V-Box dismissed, the temperature is '.. wordValue
getMessageUrl(message)
print("Notification pushed of dismissing alarm,"..wordValue)
end
tempWord = wordValue----Prevent monitoring values from continuous being sent to the platform
end
1 เม.ย 2564
8 ธ.ค. 2562
15 ก.ย. 2562
15 ธ.ค. 2565