Skip to content

Commit

Permalink
add:iotcloud支持手动设置自动重连
Browse files Browse the repository at this point in the history
  • Loading branch information
Dozingfiretruck committed Sep 20, 2024
1 parent 6abdd0c commit 7dcb00f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions script/libs/iotcloud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ end
@api iotcloud.new(cloud,iot_config,connect_config)
@string 云平台 iotcloud.TENCENT:腾讯云 iotcloud.ALIYUN:阿里云 iotcloud.ONENET:中国移动云 iotcloud.HUAWEI:华为云 iotcloud.TUYA:涂鸦云
@table iot云平台配置, device_name:可选,默认为imei否则为unique_id iot_config.product_id:产品id(阿里云则为产品key) iot_config.product_secret:产品密钥,有此项则为动态注册 iot_config.device_secret:设备秘钥,有此项则为秘钥连接 instance_id:公共实例id,新版阿里云公共实例专用 userid:用户ID,onenet专用,动态注册使用 userkey:用户Accesskey,onenet专用,动态注册使用
@table mqtt配置, host:可选,默认为平台默认host ip:可选,默认为平台默认ip tls:加密,若有此项一般为产品认证 keepalive:心跳时间,单位s 可选,默认240
@table mqtt配置, host:可选,默认为平台默认host ip:可选,默认为平台默认ip tls:加密,若有此项一般为产品认证 keepalive:心跳时间,单位s 可选,默认240 autoreconn:自动重连,number:重连时间,单位ms /bool 是否重连,默认3000ms 可选,默认不自动重连
@return table 云平台对象
@usage
Expand All @@ -563,12 +563,12 @@ end
-- iotcloudc = iotcloud.new(iotcloud.TENCENT,{produt_id = "xxx",device_name = "123456789"},{tls={client_cert=io.readFile("/luadb/client_cert.crt")}})
-- 阿里云
-- 动态注册(免预注册)(一型一密)(仅企业版支持)
-- 一型一密(免预注册-仅企业版支持)
-- iotcloudc = iotcloud.new(iotcloud.ALIYUN,{instance_id = "xxx",produt_id = "xxx",product_secret = "xxx"}) -- 企业版公共实例
-- 动态注册(预注册)(一型一密)
-- 一型一密(预注册)
-- iotcloudc = iotcloud.new(iotcloud.ALIYUN,{produt_id = "xxx",device_name = "xxx",product_secret = "xxx"}) -- 旧版公共实例
-- iotcloudc = iotcloud.new(iotcloud.ALIYUN,{instance_id = "xxx",produt_id = "xxx",device_name = "xxx",product_secret = "xxx"}) -- 新版公共实例
-- 密钥校验 (预注册)(一机一密)
-- 一机一密 (预注册)
-- iotcloudc = iotcloud.new(iotcloud.ALIYUN,{produt_id = "xxx",device_name = "xxx",key = "xxx"}) -- 旧版公共实例
-- iotcloudc = iotcloud.new(iotcloud.ALIYUN,{instance_id = "xxx",produt_id = "xxx",device_name = "xxx",key = "xxx"})-- 新版公共实例
Expand Down Expand Up @@ -670,7 +670,7 @@ function iotcloud.new(cloud,iot_config,connect_config)
-- iotcloudc.mqttc:debug(true)
iotcloudc.mqttc:auth(iotcloudc.client_id,iotcloudc.user_name,iotcloudc.password)
iotcloudc.mqttc:keepalive(connect_config.keepalive or 240)
iotcloudc.mqttc:autoreconn(true, 3000) -- 自动重连机制
iotcloudc.mqttc:autoreconn(connect_config.autoreconn and true, (type(connect_config.autoreconn) == "number") or connect_config.autoreconn)-- 自动重连机制
iotcloudc.mqttc:on(iotcloud_mqtt_callback) -- mqtt回调
table.insert(cloudc_table,iotcloudc) -- 添加到表里记录
return iotcloudc,error_code -- 错误返回待处理
Expand Down

0 comments on commit 7dcb00f

Please sign in to comment.