Bläddra i källkod

fix:修改excloud扩展库以及提交aircloud的demo

mw 4 månader sedan
förälder
incheckning
d2ec3d5703

+ 5 - 5
module/Air780EHM_Air780EHV_Air780EGH/demo/aircloud/excloud_test.lua

@@ -112,8 +112,8 @@ function excloud_task_func()
         reconnect_interval = 10, -- 重连间隔(秒)
         max_reconnect = 5,       -- 最大重连次数
         mtn_log_enabled = true,  -- 启用运维日志
-        mtn_log_blocks = 2,      -- 日志文件块数
-        mtn_log_write_way = excloud.MTN_LOG_CACHE_WRITE  -- 缓存写入方式
+        mtn_log_blocks = 1,      -- 日志文件块数
+        mtn_log_write_way = excloud.MTN_LOG_ADD_WRITE  -- 缓存写入方式
     })
 
 
@@ -131,7 +131,7 @@ function excloud_task_func()
     --     mtn_log_enabled = true                         -- 启用运维日志
     -- })
 
-    -- -- 配置excloud参数,虚拟设备链接
+    -- 配置excloud参数,虚拟设备链接
     -- local ok, err_msg = excloud.setup({
     --     use_getip = true, --使用getip服务
     --     device_type = 9,
@@ -242,8 +242,8 @@ function mtnlog_test_task()
     local test_count = 0
     while true do
         test_count = test_count + 1
-
-        excloud.mtn_log("mtn_test", test_count)
+        
+        excloud.mtn_log("info", "mtn_test", test_count)
         -- 每30秒记录一次
         sys.wait(1000)
     end

+ 6 - 6
module/Air780EHM_Air780EHV_Air780EGH/demo/aircloud/readme.md

@@ -10,7 +10,7 @@
 
 ## 演示功能概述
 
-使用Air780EPM V1.3开发板测试aircloud功能
+使用Air780EHM 核心板测试aircloud功能
 
 AirCloud 概述:AirCloud 是 LuatOS 物联网设备云服务通信协议,提供设备连接、数据上报、远程控制和文件上传等核心功能。excloud 扩展库是 AirCloud 协议的实现,通过该库设备可以快速接入云服务平台,实现远程监控和管理。
 
@@ -23,24 +23,24 @@ AirCloud 概述:AirCloud 是 LuatOS 物联网设备云服务通信协议,提
 
 ## 演示硬件环境
 
-![img](https://docs.openluat.com/air780epm/luatos/app/driver/eth/image/RFSvb75NRoEWqYxfCRVcVrOKnsf.jpg)
+![](https://docs.openluat.com/air780epm/luatos/app/driver/eth/image/RFSvb75NRoEWqYxfCRVcVrOKnsf.jpg)
 
-1、Air780EPM V1.3版本开发板一块+可上网的sim卡一张+4g天线一根+网线一根:
+1、Air780EHM 核心板一块+可上网的sim卡一张+4g天线一根+网线一根:
 
 - sim卡插入开发板的sim卡槽
 - 天线装到开发板上
 - 网线一端插入开发板网口,另外一端连接可以上外网的路由器网口
 
-2、TYPE-C USB数据线一根 ,Air780EPM V1.3版本开发板和数据线的硬件接线方式为:
+2、TYPE-C USB数据线一根 ,Air780EHM 核心板和数据线的硬件接线方式为:
 
-- Air780EPM V1.3版本开发板通过TYPE-C USB口供电;(外部供电/USB供电 拨动开关 拨到 USB供电一端)
+- Air780EHM 核心板通过TYPE-C USB口供电;(外部供电/USB供电 拨动开关 拨到 USB供电一端)
 - TYPE-C USB数据线直接插到核心板的TYPE-C USB座子,另外一端连接电脑USB口;
 
 ## 演示软件环境
 
 1、Luatools下载调试工具
 
-2、[Air780EPM V2016版本固件](https://gitee.com/link?target=https%3A%2F%2Fdocs.openluat.com%2Fair780epm%2Fluatos%2Ffirmware%2Fversion%2F)
+2、[Air780EHM V2016版本固件](https://gitee.com/link?target=https%3A%2F%2Fdocs.openluat.com%2Fair780epm%2Fluatos%2Ffirmware%2Fversion%2F)
 
 ## 演示核心步骤
 

+ 5 - 5
module/Air780EPM/demo/aircloud/excloud_test.lua

@@ -112,8 +112,8 @@ function excloud_task_func()
         reconnect_interval = 10, -- 重连间隔(秒)
         max_reconnect = 5,       -- 最大重连次数
         mtn_log_enabled = true,  -- 启用运维日志
-        mtn_log_blocks = 2,      -- 日志文件块数
-        mtn_log_write_way = excloud.MTN_LOG_CACHE_WRITE  -- 缓存写入方式
+        mtn_log_blocks = 1,      -- 日志文件块数
+        mtn_log_write_way = excloud.MTN_LOG_ADD_WRITE  -- 缓存写入方式
     })
 
 
@@ -131,7 +131,7 @@ function excloud_task_func()
     --     mtn_log_enabled = true                         -- 启用运维日志
     -- })
 
-    -- -- 配置excloud参数,虚拟设备链接
+    -- 配置excloud参数,虚拟设备链接
     -- local ok, err_msg = excloud.setup({
     --     use_getip = true, --使用getip服务
     --     device_type = 9,
@@ -242,8 +242,8 @@ function mtnlog_test_task()
     local test_count = 0
     while true do
         test_count = test_count + 1
-
-        excloud.mtn_log("mtn_test", test_count)
+        
+        excloud.mtn_log("info", "mtn_test", test_count)
         -- 每30秒记录一次
         sys.wait(1000)
     end

+ 5 - 5
module/Air8000/demo/Aircloud/excloud_test.lua

@@ -112,8 +112,8 @@ function excloud_task_func()
         reconnect_interval = 10, -- 重连间隔(秒)
         max_reconnect = 5,       -- 最大重连次数
         mtn_log_enabled = true,  -- 启用运维日志
-        mtn_log_blocks = 2,      -- 日志文件块数
-        mtn_log_write_way = excloud.MTN_LOG_CACHE_WRITE  -- 缓存写入方式
+        mtn_log_blocks = 1,      -- 日志文件块数
+        mtn_log_write_way = excloud.MTN_LOG_ADD_WRITE  -- 缓存写入方式
     })
 
 
@@ -131,7 +131,7 @@ function excloud_task_func()
     --     mtn_log_enabled = true                         -- 启用运维日志
     -- })
 
-    -- -- 配置excloud参数,虚拟设备链接
+    -- 配置excloud参数,虚拟设备链接
     -- local ok, err_msg = excloud.setup({
     --     use_getip = true, --使用getip服务
     --     device_type = 9,
@@ -242,8 +242,8 @@ function mtnlog_test_task()
     local test_count = 0
     while true do
         test_count = test_count + 1
-
-        excloud.mtn_log("mtn_test", test_count)
+        
+        excloud.mtn_log("info", "mtn_test", test_count)
         -- 每30秒记录一次
         sys.wait(1000)
     end

+ 6 - 6
module/Air8000/demo/Aircloud/readme.md

@@ -10,7 +10,7 @@
 
 ## 演示功能概述
 
-使用Air780EPM V1.3开发板测试aircloud功能
+使用Air8000 核心板测试aircloud功能
 
 AirCloud 概述:AirCloud 是 LuatOS 物联网设备云服务通信协议,提供设备连接、数据上报、远程控制和文件上传等核心功能。excloud 扩展库是 AirCloud 协议的实现,通过该库设备可以快速接入云服务平台,实现远程监控和管理。
 
@@ -23,24 +23,24 @@ AirCloud 概述:AirCloud 是 LuatOS 物联网设备云服务通信协议,提
 
 ## 演示硬件环境
 
-![img](https://docs.openluat.com/air780epm/luatos/app/driver/eth/image/RFSvb75NRoEWqYxfCRVcVrOKnsf.jpg)
+![](https://docs.openluat.com/air8000/luatos/common/hwenv/image/Air8000_core_board1.jpg)
 
-1、Air780EPM V1.3版本开发板一块+可上网的sim卡一张+4g天线一根+网线一根:
+1、Air8000 核心板一块+可上网的sim卡一张+4g天线一根+网线一根:
 
 - sim卡插入开发板的sim卡槽
 - 天线装到开发板上
 - 网线一端插入开发板网口,另外一端连接可以上外网的路由器网口
 
-2、TYPE-C USB数据线一根 ,Air780EPM V1.3版本开发板和数据线的硬件接线方式为:
+2、TYPE-C USB数据线一根 ,Air8000 核心板和数据线的硬件接线方式为:
 
-- Air780EPM V1.3版本开发板通过TYPE-C USB口供电;(外部供电/USB供电 拨动开关 拨到 USB供电一端)
+- Air8000 核心板通过TYPE-C USB口供电;(外部供电/USB供电 拨动开关 拨到 USB供电一端)
 - TYPE-C USB数据线直接插到核心板的TYPE-C USB座子,另外一端连接电脑USB口;
 
 ## 演示软件环境
 
 1、Luatools下载调试工具
 
-2、[Air780EPM V2016版本固件](https://gitee.com/link?target=https%3A%2F%2Fdocs.openluat.com%2Fair780epm%2Fluatos%2Ffirmware%2Fversion%2F)
+2、[Air8000 V2018版本固件](https://docs.openluat.com/air8000/luatos/firmware/)
 
 ## 演示核心步骤
 

+ 28 - 16
script/libs/excloud.lua

@@ -554,7 +554,7 @@ end
 
 --             -- 记录认证结果到运维日志
 --             if config.aircloud_mtn_log_enabled then
---                 exmtn.log("auth", "认证结果", "success", success, "message", tlv.value)
+--                 exmtn.log("info", "aircloud","auth", "认证结果", "success", success, "message", tlv.value)
 --             end
 
 
@@ -770,7 +770,7 @@ local function upload_mtn_log_files(log_files)
 
                 -- 记录上传成功的运维日志
                 if config.aircloud_mtn_log_enabled then
-                    exmtn.log("mtn_upload", "文件上传成功", "file", log_file.name, "size", log_file.size)
+                    exmtn.log("info", "aircloud", "mtn_upload", "文件上传成功", "file", log_file.name, "size", log_file.size)
                 end
             else
                 -- 发送上传失败状态
@@ -780,7 +780,7 @@ local function upload_mtn_log_files(log_files)
 
                 -- 记录上传失败的运维日志
                 if config.aircloud_mtn_log_enabled then
-                    exmtn.log("mtn_upload_error", "文件上传失败", "file", log_file.name, "error", err_msg)
+                    exmtn.log("info", "aircloud","mtn_upload_error", "文件上传失败", "file", log_file.name, "error", err_msg)
                 end
             end
 
@@ -806,7 +806,7 @@ local function upload_mtn_log_files(log_files)
 
         -- 记录上传完成日志
         if config.aircloud_mtn_log_enabled then
-            exmtn.log("mtn_upload", "运维日志上传完成", "success", success_count, "failed", failed_count, "total", total_files)
+            exmtn.log("info", "aircloud","mtn_upload", "运维日志上传完成", "success", success_count, "failed", failed_count, "total", total_files)
         end
         -- 通知上传完成
         if callback_func then
@@ -825,7 +825,7 @@ local function handle_mtn_log_upload_request()
     local latest_index = total_files > 0 and log_files[#log_files].index or 0
 
     if config.aircloud_mtn_log_enabled then
-        exmtn.log("cloud_cmd", "收到运维日志上传请求", "file_count", total_files)
+        exmtn.log("info", "aircloud","cloud_cmd", "收到运维日志上传请求", "file_count", total_files)
     end
 
     log.info("开始处理运维日志上传请求", "文件总数:", total_files, "最新序号:", latest_index)
@@ -1322,11 +1322,23 @@ function excloud.upload_audio(file_path, file_name)
 end
 
 -- 记录运维日志
-function excloud.mtn_log(tag, ...)
+--[[
+输出运维日志并写入文件
+@api excloud.mtn_log(level, tag, ...)
+@string level 日志级别,必须是 "info", "warn", 或 "error"
+@string tag 日志标识,必须是字符串
+@... 需打印的参数
+@return boolean 成功返回true,失败返回false
+@usage
+excloud.mtn_log("info", "message", 123)
+excloud.mtn_log("warn", "message", 456)
+excloud.mtn_log("error", "message", 789)
+]]
+function excloud.mtn_log(level,tag, ...)
     if not config.aircloud_mtn_log_enabled then
         return false, "运维日志功能已禁用" -- 禁用时返回失败
     end
-    exmtn.log(tag, ...)
+    exmtn.log(level,tag, ...)
     return true
 end
 
@@ -1458,11 +1470,11 @@ local function tcp_socket_callback(netc, event, param)
     -- 记录连接状态变化的运维日志
     if config.aircloud_mtn_log_enabled then
         if event == socket.LINK then
-            exmtn.log("net_conn", "网络连接成功")
+            exmtn.log("info", "aircloud","net_conn", "网络连接成功")
         elseif event == socket.ON_LINE then
-            exmtn.log("net_conn", "TCP连接成功", "host", config.host, "port", config.port)
+            exmtn.log("info", "aircloud","net_conn", "TCP连接成功", "host", config.host, "port", config.port)
         elseif event == socket.CLOSED then
-            exmtn.log("net_conn", "TCP连接断开", "param", param)
+            exmtn.log("info", "aircloud","net_conn", "TCP连接断开", "param", param)
         end
     end
 
@@ -1532,11 +1544,11 @@ local function mqtt_client_event_cbfunc(connected, event, data, payload, metas)
     -- 记录MQTT状态变化的运维日志
     if config.aircloud_mtn_log_enabled then
         if event == "conack" then
-            exmtn.log("mqtt_conn", "MQTT连接成功", "host", config.host)
+            exmtn.log("info", "aircloud","mqtt_conn", "MQTT连接成功", "host", config.host)
         elseif event == "disconnect" then
-            exmtn.log("mqtt_conn", "MQTT连接断开")
+            exmtn.log("info", "aircloud","mqtt_conn", "MQTT连接断开")
         elseif event == "error" then
-            exmtn.log("mqtt_error", "MQTT错误", "type", data, "code", payload)
+            exmtn.log("info", "aircloud","mqtt_error", "MQTT错误", "type", data, "code", payload)
         end
     end
 
@@ -1990,7 +2002,7 @@ function excloud.open()
 
     -- 记录服务启动日志
     if config.aircloud_mtn_log_enabled then
-        exmtn.log("system", "excloud服务启动", "transport", config.transport, "host", config.host, "port", config.port)
+        exmtn.log("info", "aircloud","system", "excloud服务启动", "transport", config.transport, "host", config.host, "port", config.port)
     end
 
     log.info("[excloud]excloud service started")
@@ -2128,7 +2140,7 @@ function excloud.send(data, need_reply, is_auth_msg)
         callback_func("send_result", {
             success = success,
             error_msg = success and "Send successful" or err_msg,
-            sequence_num = current_sequence,
+            sequence_num = current_sequence
         })
     end
 
@@ -2173,7 +2185,7 @@ function excloud.close()
 
     -- 记录服务关闭日志
     if config.aircloud_mtn_log_enabled then
-        exmtn.log("system", "excloud服务关闭")
+        exmtn.log("info", "aircloud","system", "excloud服务关闭")
     end
 
     -- 重置状态