294 Star 1.6K Fork 391

GVP合宙Luat / LuatOS

 / 详情

[🐛Bug]: 基于开发板core_air780e的4G mqtt应用代码从一个地区换到另外一个地区使用失败, E/DNS no ipv6, no ipv4

已完成
创建于  
2024-04-21 16:13

描述一下这个bug / Describe the bug

在山东省内时使用时没有报错,能够正常访问broker。换到湖南省时,虽然网络正常,却无法访问mqtt broker

复现步骤 / To Reproduce

-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "mqtt"
VERSION = "1.0.1"

log.info("main", PROJECT, VERSION)

-- sys库是标配
_G.sys = require("sys")

-- local netLed = require("netLed")
local netConnect = false

--根据自己的服务器修改以下参数
local mqtt_host = "lbsmqtt.airm2m.com"
local mqtt_port = 1884
local mqtt_isssl = false
local client_id = "abc"
local user_name = "user"
local password = "password"

local pub_topic = "/pub/"
local sub_topic = "/sub/"

local mqttc = nil
local device_id = 0

local adc_pin_bat_lead_acid_v = 0
--ADC读取
local PIN_TOTAL_SWITCH_STATUS = 1 -- 读入端口,外部环境下的acc_on状态
local PIN_ACC_ON_EXT = 9 -- 读入端口,外部环境下的acc_on状态
local PIN_POWER_STATUS = 11 -- 读入端口,power_status
local PIN_NET_LED_ACC_INT = 27 -- 输出端口,内部输出的ACC电平输出
local cnt_life = 0
local PUB_MSG_PERIOD = 100 -- 发布消息的周期,单位s
local setDevicePowerOn = 1
local setDevicePowerOff = 0
function hw_init()
if rtos_bsp == "EC618" then --Air780E开发板ADC
-- 默认不开启分压,范围是0-1.2v精度高
-- adc.setRange(adc.ADC_RANGE_1_2) -- 关闭分压 执行这一句实测发现最高只能测到1.2V左右
-- adc.setRange(adc.ADC_RANGE_3_8) -- 启用分压 执行这一句实测发现最高只能测到3.2V左右
-- 什么都不设置实测发现最高能测到3.8V左右
elseif rtos_bsp == "EC718P" then --Air780EP开发板ADC
-- 默认不开启分压,范围是0-1.2v精度高
adc.setRange(adc.ADC_RANGE_3_8)
else
log.info("main", "define ADC pin in main.lua")
end
adc.open(adc_pin_bat_lead_acid_v)
gpio.setup(PIN_TOTAL_SWITCH_STATUS, 1, gpio.PULLUP) -- 输入读端口
gpio.setup(PIN_ACC_ON_EXT, 1, gpio.PULLUP) -- 输入读端口
gpio.setup(PIN_POWER_STATUS, 1, gpio.PULLUP) -- 输出端口
gpio.setup(PIN_NET_LED_ACC_INT, 0, gpio.PULLUP) -- 输出端口
log.info("", "硬件初始化完毕")
-- while true do
-- sys.wait(1000)
-- -- log.debug("adc", "铅酸电池电压=", adc.get(adc_pin_bat_lead_acid_v)/1000,"v")
-- end
end

function publish_topic()
local qos = 0 -- QOS0不带puback, QOS1是带puback的
mqttc:publish(pub_topic, '123', qos)
end

sys.taskInit(function()
hw_init()
mobile.ipv6(true)
-- 等待联网
sys.waitUntil("IP_READY")
socket.setDNS(nil, 0, "223.5.5.5")
socket.setDNS(nil, 1, "119.29.29.29")
socket.setDNS(nil, 2, "114.114.114.114")
device_id = mobile.imei()
-- 下面的是mqtt的参数均可自行修改
client_id = device_id
pub_topic = "/test/haha/pub"
sub_topic = "/test/haha/sub/".. tostring(device_id)

-- 打印一下上报(pub)和下发(sub)的topic名称
-- 上报: 设备 ---> 服务器
-- 下发: 设备 <--- 服务器
-- 可使用mqtt.x等客户端进行调试
log.info("mqtt", "pub", pub_topic)
log.info("mqtt", "sub", sub_topic)

-- 打印一下支持的加密套件, 通常来说, 固件已包含常见的99%的加密套件
-- if crypto.cipher_suites then
--     log.info("cipher", "suites", json.encode(crypto.cipher_suites()))
-- end
if mqtt == nil then
    while 1 do
        sys.wait(1000)
        log.info("bsp", "本bsp未适配mqtt库, 请查证")
    end
end


mqttc = mqtt.create(nil, mqtt_host, mqtt_port, mqtt_isssl, ca_file)
mqttc:auth(client_id,user_name,password) -- client_id必填,其余选填
mqttc:keepalive(100) -- 默认值240s
mqttc:autoreconn(true, 3000) -- 自动重连机制

mqttc:on(function(mqtt_client, event, data, payload)
    -- 用户自定义代码
    if event == "conack" then
        -- 连上了
        log.info("mqtt", "event", event, "连接成功")
        sys.publish("mqtt_conack")
        mqtt_client:subscribe(sub_topic)--单主题订阅
        -- mqtt_client:subscribe({[topic1]=1,[topic2]=1,[topic3]=1})--多主题订阅
    elseif event == "recv" then
        log.info("mqtt", "downlink", "topic", data, "payload", payload)
        sys.publish("mqtt_payload", data, payload)
    elseif event == "sent" then
        -- log.info("mqtt", "sent", "pkgid", data)
    elseif event == "disconnect" then
        log.info("mqtt", "event", event, "连接断开")
        -- 非自动重连时,按需重启mqttc
        -- mqtt_client:connect()
    end
end)

-- mqttc自动处理重连, 除非自行关闭
mqttc:connect()
sys.waitUntil("mqtt_conack")

publish_topic()
while true do
    cnt_life = cnt_life + 1
    if netConnect == true and cnt_life == PUB_MSG_PERIOD then  
        log.info("mqtt", "发送心跳包")
        cnt_life = 0
        publish_topic()
    end
    sys.wait(1000)  -- 固定周期上报
    
end
mqttc:close()
mqttc = nil

end)

sys.subscribe("mqtt_payload", function(topic, payload)
log.info("", "订阅到的数据长度", #payload,"内容:",payload)

end)
-- 联网后会发一次这个消息
sys.subscribe("IP_READY", function(ip, adapter)
log.info("", "IP_READY+++++++++++++++++网络正常", ip, (adapter or -1) == socket.LWIP_GP)
netConnect = true
end)
-- 断网后会发一次这个消息
sys.subscribe("IP_LOSE", function(adapter)
log.info("", "IP_LOSE------------------没有网络", (adapter or -1) == socket.LWIP_GP)
netConnect = false
end)
-- 用户代码已结束---------------------------------------------
-- 结尾总是这一句
sys.run()
-- sys.run()之后后面不要加任何语句!!!!!

如果正常,应该是什么样 / Expected behavior

正常应该不会打印这些字符
[2024-04-21 15:23:58.991][000000025.987] E/DNS no ipv6, no ipv4
[2024-04-21 15:23:58.995][000000025.988] E/mqtt mqtt_callback param1 -1, closing socket
[2024-04-21 15:23:59.000][000000025.988] I/mqtt mqtt closing socket netc:0041C1E0 mqtt_state:1
[2024-04-21 15:23:59.004][000000025.990] I/user.mqtt event disconnect 连接断开
[2024-04-21 15:23:59.990][000000026.987] I/DNS dns all done ,now stop

截图 / Screenshots

输入图片说明输入图片说明

日志 / Logs

[2024-04-21 16:08:01.093] 工具提示: soc log port COM11打开成功
[2024-04-21 16:08:01.138] 工具提示: ap log port COM10打开成功
[2024-04-21 16:08:01.147] 工具提示: 用户虚拟串口 COM20
[2024-04-21 16:08:01.210][000000000.013] Uart_BaseInitEx 1042:uart 0 rx cache 256 dma 256
[2024-04-21 16:08:01.210][000000000.215] D/pm PowerKey-Debounce is enabled
[2024-04-21 16:08:01.218][000000000.215] I/pm poweron: Power/Reset
[2024-04-21 16:08:01.219][000000000.215] I/main LuatOS@EC618 base 23.11 bsp V1109 32bit
[2024-04-21 16:08:01.226][000000000.215] I/main ROM Build: Mar 6 2024 13:22:33
[2024-04-21 16:08:01.226][000000000.223] D/main loadlibs luavm 262136 14432 14464
[2024-04-21 16:08:01.226][000000000.223] D/main loadlibs sys 280480 53888 83872
[2024-04-21 16:08:01.226][000000000.236] I/user.main mqtt 1.0.1
[2024-04-21 16:08:01.226][000000000.257] I/user.main define ADC pin in main.lua
[2024-04-21 16:08:01.226][000000000.258] I/user. 硬件初始化完毕
[2024-04-21 16:08:01.226][000000000.431] self_info 127:model Air780E_A16 imei 869329069187451
[2024-04-21 16:08:02.927][000000002.259] D/mobile cid1, state0
[2024-04-21 16:08:02.927][000000002.266] D/mobile bearer act 0, result 0
[2024-04-21 16:08:02.927][000000002.281] D/mobile TIME_SYNC 0
[2024-04-21 16:08:03.359][000000002.709] D/mobile NETIF_LINK_ON -> IP_READY
[2024-04-21 16:08:03.365][000000002.711] I/user.mqtt pub /test/haha/pub
[2024-04-21 16:08:03.369][000000002.712] I/user.mqtt sub /test/haha/sub/869329069187451
[2024-04-21 16:08:03.369][000000002.714] D/DNS lbsmqtt.airm2m.com state 0 id 1 ipv6 0 use dns server0, try 0
[2024-04-21 16:08:03.369][000000002.717] I/user. IP_READY+++++++++++++++++网络正常 10.55.52.71 true
[2024-04-21 16:08:04.354][000000003.714] D/DNS lbsmqtt.airm2m.com state 0 id 1 ipv6 0 use dns server0, try 1
[2024-04-21 16:08:06.363][000000005.714] D/DNS lbsmqtt.airm2m.com state 0 id 1 ipv6 0 use dns server0, try 2
[2024-04-21 16:08:09.363][000000008.714] D/DNS lbsmqtt.airm2m.com state 0 id 1 ipv6 0 use dns server1, try 0
[2024-04-21 16:08:10.356][000000009.714] D/DNS lbsmqtt.airm2m.com state 0 id 1 ipv6 0 use dns server1, try 1
[2024-04-21 16:08:12.357][000000011.714] D/DNS lbsmqtt.airm2m.com state 0 id 1 ipv6 0 use dns server1, try 2
[2024-04-21 16:08:15.364][000000014.714] D/DNS lbsmqtt.airm2m.com state 0 id 1 ipv6 0 use dns server2, try 0
[2024-04-21 16:08:16.357][000000015.714] D/DNS lbsmqtt.airm2m.com state 0 id 1 ipv6 0 use dns server2, try 1
[2024-04-21 16:08:18.357][000000017.714] D/DNS lbsmqtt.airm2m.com state 0 id 1 ipv6 0 use dns server2, try 2
[2024-04-21 16:08:21.357][000000020.714] D/DNS lbsmqtt.airm2m.com state 0 id 1 ipv6 0 use dns server3, try 0
[2024-04-21 16:08:22.368][000000021.714] D/DNS lbsmqtt.airm2m.com state 0 id 1 ipv6 0 use dns server3, try 1
[2024-04-21 16:08:24.354][000000023.714] D/DNS lbsmqtt.airm2m.com state 0 id 1 ipv6 0 use dns server3, try 2
[2024-04-21 16:08:27.355][000000026.714] E/DNS no ipv6, no ipv4
[2024-04-21 16:08:27.360][000000026.715] E/mqtt mqtt_callback param1 -1, closing socket
[2024-04-21 16:08:27.363][000000026.715] I/mqtt mqtt closing socket netc:0041C1E0 mqtt_state:1
[2024-04-21 16:08:27.369][000000026.717] I/user.mqtt event disconnect 连接断开
[2024-04-21 16:08:28.365][000000027.714] I/DNS dns all done ,now stop
[2024-04-21 16:08:30.367][000000029.716] D/DNS lbsmqtt.airm2m.com state 0 id 2 ipv6 0 use dns server0, try 0
[2024-04-21 16:08:31.360][000000030.715] D/DNS lbsmqtt.airm2m.com state 0 id 2 ipv6 0 use dns server0, try 1
[2024-04-21 16:08:33.359][000000032.715] D/DNS lbsmqtt.airm2m.com state 0 id 2 ipv6 0 use dns server0, try 2

PACK包版本 / Version

V1109

验证

  • 检查过该问题,之前没有人提过 / Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • 提供了最小可复现工程或详细的复现步骤,确保开发者可以复现 / The provided reproduction is a minimal reproducible example of the bug.
  • 已经提供了完整的报错信息、日志、截图,没有经过删减。

评论 (4)

FreedomSnail 创建了任务

换当地的卡

这个不太好,设计的目标是允许设备在全国范围内移动

这是你现在用的卡的限制,哪有什么好不好,要么换一张全国能用的卡

咨询过卡的代理商,确实是卡的限制导致的

alien2017 计划截止日期设置为2024-04-26
alien2017 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(2)
Lua
1
https://gitee.com/openLuat/LuatOS.git
git@gitee.com:openLuat/LuatOS.git
openLuat
LuatOS
LuatOS

搜索帮助

344bd9b3 5694891 D2dac590 5694891