PROJECT = 'TESTHTTPS'
VERSION = '0.0.1'
is_online = false
is_synced = false
counter = 0
require "sys"
LOG_LEVEL = log.LOGLEVEL_TRACE
require "net"
net.startQueryAll(60000, 60000)
sys.subscribe('NET_STATE_UNREGISTER', function()
is_online = false
end)
sys.subscribe('NET_STATE_REGISTERED', function()
is_online = true
end)
sys.subscribe('SOCKET_ACTIVE', function(status)
if status then
is_socket_available = false
else
is_socket_available = true
end
end)
--require "wdt"
--wdt.setup(pio.P0_30, pio.P0_31)
require 'netLed'
netLed.setup(true, pio.P1_1)
require 'ntp'
ntp.timeSync(12, function()
is_synced = true
end)
require 'http'
sys.timerLoopStart(function()
counter = counter + 1
if counter % 5 == 0 and is_online and is_synced and is_socket_available then
http.request('POST', 'https://www.example.com/hws/test.php?u=' .. misc.getImei(), nil, { ["Content-Type"] = "application/text" }, '1234567890', 10000, function(result, prompt, head, body)
if result then
log.trace('UPLOAD', body)
else
log.error('UPLOAD', prompt)
end
end)
end
end, 1000)
sys.init(0, 0)
sys.run()
测试了一下,如果你代码中的timer定时器改成这样,就不会有问题:
sys.taskInit(function () while true do if is_online and is_synced and is_socket_available then http.request('POST', 'https://www.example.com/hws/test.php?u=' .. misc.getImei(), nil, {["Content-Type"] = "application/text" }, '1234567890', 10000, function(result, prompt, head, body) if result then log.trace('UPLOAD', body) else log.error('UPLOAD', prompt) end sys.publish("HTTP_END") end) sys.waitUntil("HTTP_END") else sys.wait(1000) end end end)
如果觉得我的回答对您有用,请随意打赏。你的支持将鼓励我继续创作!