100 air202 https, 只要发生 send head fail 错误,之后 socket 就无法正常工作了,只能重启?

test.trc

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()
请先 登录 后评论

最佳答案 2019-01-22 14:02

测试了一下,如果你代码中的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)
不要不停地新建各种请求,等请求发起完毕了再进行下一步动作
请先 登录 后评论

其它 1 个回答

李炜镪

请附上从开机到send head fail及socket无法正常工作的日志文件

请先 登录 后评论
  • 0 关注
  • 0 收藏,3297 浏览
  • 高鹏 提出于 2019-01-16 12:19

相似问题