//Підключення бібліотек
ds18b20 = require("ds18b20")
http = require("http")
//Ініціалізація піну для DS18B20
ds18b20.setup(4)
//Функція для відправки даних на thingspeak.com
function sendToThingspeak(temperature)
local url = "https://api.thingspeak.com/update"
local apiKey = "YOUR_API_KEY"
local postParams = "api_key=" .. apiKey .. "&field1=" .. temperature
http.post(url, nil, postParams, function(code, data)
if (code < 0) then
print("Помилка під час відправлення даних на Thingspeak")
else
print("Дані успішно відправлено на Thingspeak")
end
end)
end
//Основний цикл
tmr.alarm(0, 10000, tmr.ALARM_AUTO, function()
local temperature = ds18b20.read()
if temperature then
print("Temperature is: " .. temperature .. "C")
sendToThingspeak(temperature)
else
print("Помилка при зчитуванні температури")
end
end)