浏览代码

Merge branch '0wQ:main' into main

机丸 2 年之前
父节点
当前提交
af39f6004e
共有 9 个文件被更改,包括 73 次插入12 次删除
  1. 4 2
      README.md
  2. 二进制
      core/LuatOS-SoC_V1104_EC618.soc
  3. 二进制
      core/LuatOS-SoC_V1104_EC618_RNDIS.soc
  4. 二进制
      core/LuatOS-SoC_V1106_EC618.soc
  5. 二进制
      core/LuatOS-SoC_V1106_EC618_RNDIS.soc
  6. 11 4
      script/config.lua
  7. 4 5
      script/main.lua
  8. 11 1
      script/util_mobile.lua
  9. 43 0
      script/util_notify.lua

+ 4 - 2
README.md

@@ -1,4 +1,4 @@
-# Air780E 短信转发
+# Air700E / Air780E / Air780EG 短信转发
 
 ## 保姆级教程:https://kdocs.cn/l/coe1ozIlSX70
 
@@ -13,6 +13,8 @@
     - [x] [企业微信群机器人 WeCom](https://developer.work.weixin.qq.com/document/path/91770)
     - [x] [Pushover](https://pushover.net/api)
     - [x] [邮件 next-smtp-proxy](https://github.com/0wQ/next-smtp-proxy)
+    - [x] [Gotify](https://gotify.net)
+    - [x] [Inotify](https://github.com/xpnas/Inotify) / [合宙官方的推送服务](https://push.luatos.org)
 - [x] 通过短信控制设备
     - [x] 发短信, 格式: `SMS,10010,余额查询`
 - [x] 定时基站定位
@@ -29,7 +31,7 @@
 
 ### 2. 烧录脚本
 
-> 推荐使用 `core` 目录下的固件, 本项目可能会使用一些合宙官方固件还未更新的 API
+> 推荐使用 `core` 目录下的固件
 >
 > `core` 目录下文件名中带有 `RNDIS` 的, 支持 RNDIS 网卡功能, 如果 SIM 卡流量不多请勿选择
 

二进制
core/LuatOS-SoC_V1104_EC618.soc


二进制
core/LuatOS-SoC_V1104_EC618_RNDIS.soc


二进制
core/LuatOS-SoC_V1106_EC618.soc


二进制
core/LuatOS-SoC_V1106_EC618_RNDIS.soc


+ 11 - 4
script/config.lua

@@ -1,6 +1,6 @@
 return {
     -- 通知类型, 支持配置多个
-    -- NOTIFY_TYPE = {"telegram", "pushdeer", "bark", "dingtalk", "feishu", "wecom", "pushover", "inotify", "next-smtp-proxy"},
+    -- NOTIFY_TYPE = {"telegram", "pushdeer", "bark", "dingtalk", "feishu", "wecom", "pushover", "inotify", "next-smtp-proxy", "gotify"},
     NOTIFY_TYPE = "pushdeer",
     --
     -- telegram 通知配置, https://github.com/0wQ/telegram-notify
@@ -31,6 +31,7 @@ return {
     --
     -- inotify 通知配置, https://github.com/xpnas/Inotify 或者使用合宙提供的 https://push.luatos.org
     INOTIFY_API = "https://push.luatos.org/XXXXXX.send",
+    --
     -- next-smtp-proxy 通知配置, https://github.com/0wQ/next-smtp-proxy
     NEXT_SMTP_PROXY_API = "",
     NEXT_SMTP_PROXY_USER = "",
@@ -41,11 +42,17 @@ return {
     NEXT_SMTP_PROXY_TO_EMAIL = "",
     NEXT_SMTP_PROXY_SUBJECT = "来自 Air780E 的通知",
     --
+    -- gotify 通知配置, https://gotify.net/
+    GOTIFY_API = "",
+    GOTIFY_TITLE = "Air780E",
+    GOTIFY_PRIORITY = 8,
+    GOTIFY_TOKEN = "",
+    --
     -- 定时查询流量间隔, 单位毫秒, 设置为 0 关闭 (建议检查 util_mobile.lua 文件中运营商号码和查询代码是否正确, 以免发错短信导致扣费, 收到查询结果短信发送通知会消耗流量)
-    QUERY_TRAFFIC_INTERVAL = 1000 * 60 * 60 * 6,
+    QUERY_TRAFFIC_INTERVAL = 0,
     --
     -- 定时基站定位间隔, 单位毫秒, 设置为 0 关闭 (定位成功后会追加到通知内容后面, 基站定位本身会消耗流量, 通知内容增加也会导致流量消耗增加)
-    LOCATION_INTERVAL = 1000 * 60 * 30,
+    LOCATION_INTERVAL = 0,
     --
     -- 开机通知 (会消耗流量)
     BOOT_NOTIFY = true,
@@ -54,7 +61,7 @@ return {
     NOTIFY_APPEND_MORE_INFO = true,
     --
     -- 通知最大重发次数
-    NOTIFY_RETRY_MAX = 100,
+    NOTIFY_RETRY_MAX = 20,
     --
     -- 开启低功耗模式, USB 断开连接无法查看日志, RNDIS 网卡会断开
     LOW_POWER_MODE = false,

+ 4 - 5
script/main.lua

@@ -127,14 +127,13 @@ sys.taskInit(
             sys.wait(1000 * 15)
             log.warn("main", "即将关闭 usb 电源, 如需查看日志请在配置中关闭低功耗模式")
             sys.wait(1000 * 5)
-
-            -- 关闭 USB
-            pm.power(pm.USB, false)
+            gpio.setup(23, nil)
+            gpio.close(33)
+            pm.power(pm.USB, false) -- 关闭 USB
             pm.power(pm.GPS, false)
             pm.power(pm.GPS_ANT, false)
             pm.power(pm.DAC_EN, false)
-            -- 休眠
-            pm.force(pm.LIGHT)
+            pm.force(pm.LIGHT) -- 进入休眠
         end
     end
 )

+ 11 - 1
script/util_mobile.lua

@@ -2,9 +2,19 @@ local util_mobile = {}
 
 -- 运营商数据
 local oper_data = {
+    -- 中国移动
     ["46000"] = {"CM", "中国移动", {"10086", "CXLL"}},
+    ["46002"] = {"CM", "中国移动", {"10086", "CXLL"}},
+    ["46007"] = {"CM", "中国移动", {"10086", "CXLL"}},
+    -- 中国联通
     ["46001"] = {"CU", "中国联通", {"10010", "2082"}},
-    ["46011"] = {"CT", "中国电信"},
+    ["46006"] = {"CU", "中国联通", {"10010", "2082"}},
+    ["46009"] = {"CU", "中国联通", {"10010", "2082"}},
+    -- 中国电信
+    ["46003"] = {"CT", "中国电信", {"10001", "108"}},
+    ["46005"] = {"CT", "中国电信", {"10001", "108"}},
+    ["46011"] = {"CT", "中国电信", {"10001", "108"}},
+    -- 中国广电
     ["46015"] = {"CB", "中国广电"}
 }
 

+ 43 - 0
script/util_notify.lua

@@ -31,6 +31,32 @@ local notify = {
         log.info("util_notify", "POST", config.TELEGRAM_PROXY_API)
         return util_http.fetch(nil, "POST", config.TELEGRAM_PROXY_API, header, msg)
     end,
+    -- 发送到 gotify
+    ["gotify"] = function(msg)
+        if config.GOTIFY_API == nil or config.GOTIFY_API == "" then
+            log.error("util_notify", "未配置 `config.GOTIFY_API`")
+            return
+        end
+        if config.GOTIFY_TOKEN == nil or config.GOTIFY_TOKEN == "" then
+            log.error("util_notify", "未配置 `config.GOTIFY_TOKEN`")
+            return
+        end
+
+        local url = config.GOTIFY_API .. "/message?token=" .. config.GOTIFY_TOKEN
+        local header = {
+            ["Content-Type"] = "application/json; charset=utf-8"
+        }
+        local body = {
+            title = config.GOTIFY_TITLE,
+            message = msg,
+            priority = config.GOTIFY_PRIORITY
+        }
+        local json_data = json.encode(body)
+        json_data = string.gsub(json_data, "\\b", "\\n")
+
+        log.info("util_notify", "POST", config.GOTIFY_API)
+        return util_http.fetch(nil, "POST", url, header, json_data)
+    end,
     -- 发送到 pushdeer
     ["pushdeer"] = function(msg)
         if config.PUSHDEER_API == nil or config.PUSHDEER_API == "" then
@@ -275,6 +301,23 @@ local function append()
         msg = msg .. "\n频段: B" .. band
     end
 
+    -- 流量统计
+    local uplinkGB, uplinkB, downlinkGB, downlinkB = mobile.dataTraffic()
+    uplinkB = uplinkGB * 1024 * 1024 * 1024 + uplinkB
+    downlinkB = downlinkGB * 1024 * 1024 * 1024 + downlinkB
+    local function formatBytes(bytes)
+        if bytes < 1024 then
+            return bytes .. "B"
+        elseif bytes < 1024 * 1024 then
+            return string.format("%.2fKB", bytes / 1024)
+        elseif bytes < 1024 * 1024 * 1024 then
+            return string.format("%.2fMB", bytes / 1024 / 1024)
+        else
+            return string.format("%.2fGB", bytes / 1024 / 1024 / 1024)
+        end
+    end
+    -- msg = msg .. "\n流量: ↑" .. formatBytes(uplinkB) .. " ↓" .. formatBytes(downlinkB)
+
     -- 位置
     local _, _, map_link = util_location.get()
     if map_link ~= "" then