LuaScripts/getTime.lua
2021-01-08 17:22:47 +03:00

28 lines
724 B
Lua

local internet = require("internet")
local component = require("component")
local modem = component.modem
local address = "" --адрес беспроводной платы
modem.open(69)
while true do
local handle = internet.request("http://worldclockapi.com/api/json/utc/now")
local result = ""
for chunk in handle do
result = result..chunk
end
local f = io.open("time.txt", "w")
f:write(result)
f:close()
f = io.open("time.txt", "r")
f:seek("set", 30)
local date = f:read(10)
f:seek("set", 41)
local hour = tonumber(f:read(2)) + 3
f:seek("set", 44)
local min = f:read(2)
f:close()
local datetime = date.." "..hour..":"..min
print(datetime)
modem.send(address, 69, datetime)
end