您尚未登录。

楼主 # 2022-02-12 16:58:49

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,206
积分: 1142.5

请教,luat函数调用给了个没定义的参数,看不懂这里。

请教个问题,翻出来irtu的源码,这个函数又看不懂了。
    mqttTask(cid, pios, reg, convert, passon, upprot, dwprot, keepAlive, timeout, addr, port, usr, pwd, cleansession, sub, pub, qos, retain, uid, clientID, "addImei", ssl, will)


调用这个函数,给的参数里最后两个ssl和will,在这句所在函数里,并没有定义这两个变量。那么ssl和will是怎么来的?
调用这个函数的语句在倒数第二行。

local function aliyunOmok(cid, pios, reg, convert, passon, upprot, dwprot, keepAlive, timeout, RegionId, ProductKey, deviceSecret, deviceName, ver, cleansession, qos, uid, sub, pub)
    cid, keepAlive, timeout, uid = tonumber(cid) or 1, tonumber(keepAlive) or 300, tonumber(timeout), tonumber(uid)
    cleansession, qos = tonumber(cleansession) or 0, tonumber(qos) or 0
    local data = "clientId" .. sim.getIccid() .. "deviceName" .. deviceName .. "productKey" .. ProductKey
    local usr = deviceName .. "&" .. ProductKey
    local pwd = crypto.hmac_sha1(data, #data, deviceSecret, #deviceSecret)
    local clientID = sim.getIccid() .. "|securemode=3,signmethod=hmacsha1|"
    local addr = ProductKey .. ".iot-as-mqtt." .. RegionId .. ".aliyuncs.com"
    local port = 1883
    if type(sub) ~= "string" or sub == "" then
        sub = ver:lower() == "basic" and "/" .. ProductKey .. "/" .. deviceName .. "/get" or "/" .. ProductKey .. "/" .. deviceName .. "/user/get"
    else
        sub = listTopic(sub, "addImei", ProductKey, deviceName)
        local topics = {}
        for i = 1, #sub do
            topics[sub[i]] = tonumber(sub[i + 1]) or qos
        end
        sub = topics
    end
    if type(pub) ~= "string" or pub == "" then
        pub = ver:lower() == "basic" and "/" .. ProductKey .. "/" .. deviceName .. "/update" or "/" .. ProductKey .. "/" .. deviceName .. "/user/update"
    else
        pub = listTopic(pub, "addImei", ProductKey, deviceName)
    end
    local dwprotFnc = dwprot and dwprot[cid] and dwprot[cid] ~= "" and loadstring(dwprot[cid]:match("function(.+)end"))
    local upprotFnc = upprot and upprot[cid] and upprot[cid] ~= "" and loadstring(upprot[cid]:match("function(.+)end"))
    [color=#FF0000]mqttTask(cid, pios, reg, convert, passon, upprot, dwprot, keepAlive, timeout, addr, port, usr, pwd, cleansession, sub, pub, qos, retain, uid, clientID, "addImei", ssl, will)[/color]

end

最近编辑记录 Gentlepig (2022-02-12 17:01:30)

离线

楼主 #1 2022-02-14 09:28:23

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,206
积分: 1142.5

Re: 请教,luat函数调用给了个没定义的参数,看不懂这里。

感觉应该算是各空参数,但仍好奇这里为什么不直接空着。

离线

楼主 #2 2022-02-14 09:29:47

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,206
积分: 1142.5

Re: 请教,luat函数调用给了个没定义的参数,看不懂这里。

    if uconf[i][1] == uart.USB or tonumber(dtu.uartReadTime) > 0 then
        uart.on(uconf[i][1], "receive", function(uid, length)
            table.insert(recvBuff[i], uart.read(uconf[i][1], length or 8192))
            sys.timerStart(sys.publish, tonumber(dtu.uartReadTime) or 25, "UART_RECV_WAIT_" .. uconf[i][1], uconf[i][1], i)
        end)
    else

还有不明白的地方:
串口订阅receive事件的回调函数后,为什么又打开了个定时器触发publish函数?
直接调用sys.publish函数不行吗?

离线

楼主 #3 2022-02-14 13:40:35

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,206
积分: 1142.5

Re: 请教,luat函数调用给了个没定义的参数,看不懂这里。

在一个luat群里问了,有群友回答是实现串口分帧超时功能的。
但我还是不理解。我感觉是每次有recevive事件后,串口读取数据并插入到recvBuff数组里,然后开启了个定时器,25ms后发送'USART_RECV_WAIT"消息。
但我不理解这个定时器起什么作用?每次接收到数据后都会延时发送USART_RECV_WAIT消息啊,又不是间隔25ms发送一次消息。

离线

楼主 #4 2022-02-15 09:35:26

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,206
积分: 1142.5

Re: 请教,luat函数调用给了个没定义的参数,看不懂这里。

四. 定时器覆盖
定时器会被同回调函数(参数也必须相同)的定时器重置, 重置后重新计时

如下例: 因为定时器总是被重置, 永远不会执行

https://blog.csdn.net/finedayforu/article/details/114303679
-------------------------------------------

搜到了这个,应该是这个原因。

离线

楼主 #5 2022-03-17 09:27:18

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,206
积分: 1142.5

Re: 请教,luat函数调用给了个没定义的参数,看不懂这里。

在更下这个帖子,又遇到了新问题。
想实现通过ssl连接阿里云,之前没用ssl可以连上。照例程添加了证书文件,也能连上。不过阿里云上无法看出是否是通过ssl方式连接的。
于是我将证书文件的名称拼错,结果仍是能连上,郁闷了。

请教个问题,air724连接阿里云,我想用tls方式连接,所以下载了阿里云的证书,但是我如何验证我是通过ssl连接的阿里云?
我尝试把证书名字拼搓,结果仍是能连上阿里云的。
    local ssl = "tcp_ssl"
    local cert = {caCert="root1.crt"}
    while not mqttc:connect(addr, port, ssl == "tcp_ssl" and ssl or nil, cert) do sys.wait((2 ^ idx) * 1000)idx = idx > 9 and 0 or idx + 1 end

离线

楼主 #6 2022-03-17 15:23:49

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,206
积分: 1142.5

Re: 请教,luat函数调用给了个没定义的参数,看不懂这里。

一般mqtt服务器的tcp连接端口是1883,ssl连接端口是8883。猜测阿里云这里也是,因为现在port就是1883.
我将port由1883改为8883,结果连不上阿里云了,即时增加正确拼写的cert证书名称后,仍是连不上...

离线

楼主 #7 2022-03-17 16:49:34

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,206
积分: 1142.5

Re: 请教,luat函数调用给了个没定义的参数,看不懂这里。

看了阿里云的mqtt.fx连接介绍,用mqtt.fx连接阿里云时,无论tcp还是ssl连接,端口都是1883。只不过clientID里有个securemode由3变为2。
但这样我还是无法验证连到阿里云的是不是通过的是ssl方式...

在私有服务器上建了emqx服务端,用mqtt客户端可以连上,用air724板子,可以用tcp方式连上。
我看emqx介绍说有个默认的临时的证书,复制到本记。然后用mqtt客户端通过ssl方式连接,不过勾选SSL Secure这个选项后,怎么也连不上Mqtt服务器。去掉这个勾选呢,无论用哪个证书,随便找个都行,都可以连到服务器,而且在emqx页面上可以看到是ssl连接。

那么我换用air724连接服务器,设置成ssl方式,端口改为8883,设置了个证书,却怎么也连不上去。

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn