forked from boris1993/sms_forwarder_air780_esp32
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 03ab453
Showing
22 changed files
with
1,228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/windows,lua,visualstudiocode | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,lua,visualstudiocode | ||
|
||
### Lua ### | ||
# Compiled Lua sources | ||
luac.out | ||
|
||
# luarocks build files | ||
*.src.rock | ||
*.zip | ||
*.tar.gz | ||
|
||
# Object files | ||
*.o | ||
*.os | ||
*.ko | ||
*.obj | ||
*.elf | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Libraries | ||
*.lib | ||
*.a | ||
*.la | ||
*.lo | ||
*.def | ||
*.exp | ||
|
||
# Shared objects (inc. Windows DLLs) | ||
*.dll | ||
*.so | ||
*.so.* | ||
*.dylib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
*.i*86 | ||
*.x86_64 | ||
*.hex | ||
|
||
|
||
### VisualStudioCode ### | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
!.vscode/*.code-snippets | ||
|
||
# Local History for Visual Studio Code | ||
.history/ | ||
|
||
# Built Visual Studio Code Extensions | ||
*.vsix | ||
|
||
### VisualStudioCode Patch ### | ||
# Ignore all local history of files | ||
.history | ||
.ionide | ||
|
||
### Windows ### | ||
# Windows thumbnail cache files | ||
Thumbs.db | ||
Thumbs.db:encryptable | ||
ehthumbs.db | ||
ehthumbs_vista.db | ||
|
||
# Dump file | ||
*.stackdump | ||
|
||
# Folder config file | ||
[Dd]esktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msix | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/windows,lua,visualstudiocode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"Lua.diagnostics.globals": [ | ||
"wdt", | ||
"log", | ||
"gpio", | ||
"uart", | ||
"wlan", | ||
"http", | ||
"hmeta", | ||
"rtos", | ||
"json", | ||
"socket" | ||
], | ||
"Lua.completion.autoRequire": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2023 boris1993 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Air780E短信转发 | ||
|
||
利用ESP32驱动Air780E实现短信转发,兼容合宙ESP32S3和ESP32C3。 | ||
|
||
**⚠ 仅支持联通、移动网络,不支持电信网络 ⚠** | ||
|
||
# 功能 | ||
|
||
- [x] 自动转发收到的短信,短信内容支持多种语言(其实就是ASCII和UCS-2字符集),目前已测试过英文、中文、日语、俄语字符 | ||
- [x] 支持多个推送平台,目前接入: | ||
- [x] [LuatOS社区提供的推送服务器](https://push.luatos.org/) | ||
- [x] Bark | ||
- [x] Server酱 | ||
- [x] 钉钉机器人 | ||
- [x] 推送加 PushPlus | ||
|
||
# 使用方法 | ||
|
||
## 硬件组装 | ||
|
||
- 按照下图方向为Air780e和ESP32焊上排针和排座。注意合宙不送排座,需要自己买。 | ||
|
||
| Air780E | ESP32S3 | | ||
|--------------------------|--------------------------| | ||
| ![](/image/air780e.jpeg) | ![](/image/esp32s3.jpeg) | | ||
|
||
- 按图示方向插入SIM卡 | ||
|
||
![](/image/sim_card_direction.jpeg) | ||
|
||
- 按图示方向将Air780E和ESP32组合 | ||
|
||
![](/image/put_together.jpeg) | ||
|
||
## 修改脚本,刷入ESP32 | ||
|
||
- 修改[`config.lua`](config.lua) | ||
- 修改`config.board_type`为正确的型号,可选值见注释 | ||
- 修改`config.wifi`,填入无线网络的SSID和密码 | ||
- 修改`config.notification_channel`,将要启用的通知通道的`enabled`配置置为`true`,并填写推送平台相关配置 | ||
- 烧录脚本 | ||
- 将[`firmware`](firmware)目录中对应的固件烧入开发板 | ||
- 将所有`lua`脚本下载至开发板 | ||
![](/image/burning_firmware_and_scripts.png) | ||
- 将开发板上电开机,等待初始化完成后,即可转发短信到配置的通知通道 | ||
|
||
# LED灯状态含义 | ||
|
||
- ESP32 | ||
- C3的`D4`或S3的`LED A`为初始化状态灯,闪烁代表正在初始化,常亮代表初始化完成,准备转发短信 | ||
- C3的`D5`或S3的`LED B`为工作状态灯,平时长灭,收到新短信后高频闪烁,转发完成后熄灭 | ||
|
||
| ESP32C3 | ESP32S3 | | ||
|-----------------------------|-----------------------------| | ||
| ![](/image/esp32c3_led.jpg) | ![](/image/esp32s3_led.png) | | ||
|
||
- Air780 | ||
- `POW`灯为电源指示灯,通电后常亮。注意,这个LED不代表开机状态,只要板子有电这个灯就会亮 | ||
- `NET`灯为网络状态指示灯,长亮短灭代表正在初始化蜂窝网络,短亮长灭代表网络注册成功,可以接收短信 | ||
|
||
# Firmware目录下的文件说明 | ||
|
||
- `LuatOS-SoC_V1004_ESP32C3_classic.soc`对应`ESP32C3 经典款` | ||
- `LuatOS-SoC_V1004_ESP32C3_lite.soc`对应`ESP32C3 简约款` | ||
- `LuatOS-SoC_V1004_ESP32S3.soc`对应`ESP32S3` | ||
|
||
固件均通过[合宙云编译](https://wiki.luatos.com/develop/compile/Cloud_compilation.html)精简掉了不需要的功能,以保证内存空间充足。`LuaTools`自动下载的固件不能用,系统启动之后内存就不够用了,发不出去HTTP请求。 | ||
|
||
目前固件包含`gpio`、`uart`、`pwm`、`wdt`、`crypto`、`rtc`、`network`、`sntp`、`tls`、`wlan`、`pm`、`cjson`、`ntp`、`shell`、`dbg`。 | ||
|
||
# 致谢 | ||
|
||
本项目参考[低成本短信转发器](https://github.com/chenxuuu/sms_forwarding)而来,尤其是PDU相关代码,没有`chenxuuu`的这份项目和[50元内自制短信转发器(Air780E+ESP32C3)](https://www.chenxublog.com/2022/10/28/19-9-sms-forwarding-air780e-esp32c3.html)这篇文章,我不会这么快就完成开发。 | ||
|
||
# 赞助 | ||
|
||
| 支付宝 | 微信 | Bitcoin | | ||
| ------ | ---- | ------- | | ||
| ![](https://sat02pap001files.storage.live.com/y4mQubRjj6HwFcaRN5WA43bM81G13d2xI-3OAoLSsXXDxJQZ_inF6qA_OFDB51Pg3yfjXu8CSyioCTUI3StB_Dltd7vmBWNHRT0Ok8zMd9Rf_WU42mgDY-pJW_yCrJ0KEUsd32yi5xqB1wjR4lv8jzMboKmpphgwoeOpPR5xgnfhNbfU8ozvDcfnnEiCpvZ6rLk?width=548&height=542&cropmode=none) | ![](https://sat02pap001files.storage.live.com/y4mRChq9zMZbQZK0gVO19Smbyt74YG1QWTI9RAgewZpJKn6BOEg0GK-_AgR9LwdjDSJriEgnz05YSc9fYUiH09i-PKnb40lZI0AqbvtcyXJvqVSdiWbGpeqPFmIktJb2t-bjIXqrupCzZxXWPXmrrFXXdFzgSWstjebkOujhr-ByhKWoLvgn3GHu2WpnGzbKgXs?width=602&height=599&cropmode=none) | ![3H8yBE359vkbpvC4nSP5xwafWThUh4JvGB](https://sat02pap001files.storage.live.com/y4m7ll7ouERuCbkCXI1x-PQJMYTzonfgpFoEL7Odz8HwPC-O2DngJrulJd23PzD6dJnucGf1zC6zGp4PFyVZjJecRWVT69c06Y4OPdjpEh5Z3E6qkRNg1ZMuP9bxQ3R_YKt2HtjzG_BD3_a9gUkRwHm-zmNH1gxJxnSbysa_qbS8xoiFenQioB4RcU-tMZn71z8?width=1044&height=1098&cropmode=none) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
local air780_helper = {} | ||
|
||
local sys = require("sys") | ||
local constants = require("constants") | ||
local pdu_helper = require("pdu_helper") | ||
local utils = require("utils") | ||
|
||
local uart_timeout = 100 | ||
|
||
-- 使用UART 1接口与Air780E通信 | ||
-- ESP32 <--> Air780E | ||
-- 02(UART1_TX) <--> 31(UART1_RXD) | ||
-- 03(UART1_RX) <--> 30(UART1_TXD) | ||
local uart_id = 1 | ||
local uart_setup_result = uart.setup(uart_id, 115200, 8, 1) | ||
if uart_setup_result ~= 0 then | ||
log.error("air780_helper", "UART初始化失败,返回值:"..uart_setup_result..",ESP32将重启") | ||
sys.wait(1000) | ||
rtos.reboot() | ||
end | ||
|
||
-- 串口读缓冲区 | ||
local send_queue = {} | ||
|
||
-- 注册串口接收事件回调 | ||
uart.on(uart_id, "receive", function(id, length) | ||
local s = "" | ||
|
||
repeat | ||
s = uart.read(id, length) | ||
if #s > 0 then | ||
table.insert(send_queue, s) | ||
sys.timerStart(sys.publish, uart_timeout, constants.uart_ready_message) | ||
end | ||
until s == "" | ||
end) | ||
|
||
-- 发送AT指令 | ||
function air780_helper.send_at_command(command) | ||
uart.write(uart_id, command) | ||
uart.write(uart_id, "\r\n") | ||
log.debug("air780_helper", "发送AT指令\""..command.."\"") | ||
end | ||
|
||
sys.subscribe(constants.uart_ready_message, function() | ||
-- 拼接所有收到的数据 | ||
local data = table.concat(send_queue) | ||
log.debug("air780_helper", data) | ||
|
||
-- 读取完成后清空缓冲区 | ||
utils.clear_table(send_queue) | ||
|
||
data = data:gsub("\n", "\r") | ||
data = data:split("\r") | ||
|
||
while #data > 0 do | ||
local current_line = table.remove(data, 1) | ||
|
||
-- 响应指令"AT",用于检测连接Air780E是否成功 | ||
if current_line == "AT" then | ||
sys.publish(constants.air780_message_topic_at_received) | ||
return | ||
end | ||
|
||
-- 响应设定短消息格式指令 | ||
if current_line:find("AT+CMGF", 1, true) then | ||
sys.publish(constants.air780_message_topic_sms_format_set) | ||
return | ||
end | ||
|
||
-- 响应设定字符集指令 | ||
if current_line:find("AT+CSCS", 1, true) then | ||
sys.publish(constants.air780_message_topic_charset_configured) | ||
return | ||
end | ||
|
||
-- 响应配置新消息提示指令 | ||
if current_line:find("AT+CNMI", 1, true) then | ||
sys.publish(constants.air780_message_topic_new_message_notification_configured) | ||
return | ||
end | ||
|
||
local urc = current_line:match("^%+(%w+)") | ||
|
||
if urc then -- URC上报 | ||
if urc == "CGATT" then | ||
-- 基站附着状态 | ||
sys.publish(constants.air780_message_topic_network_connected, current_line:match("%+CGATT: *(%d)") == "1") | ||
elseif urc == "CMT" then | ||
-- 收到短信 | ||
local pdu_length = tonumber(current_line:match("%+CMT: *, *(%d+)")) | ||
|
||
repeat | ||
local line = table.remove(data, 1) | ||
if #line > 0 then | ||
local phone_number, sms_content, receive_time, is_long_sms, total, current_id = pdu_helper.decode_pdu(line, pdu_length) | ||
log.info("air780_helper", "于 "..receive_time.." 收到短信,来自号码"..phone_number..", 内容:\""..sms_content.."\"") | ||
|
||
sys.publish( | ||
constants.air780_message_topic_new_sms_received, | ||
phone_number, | ||
sms_content, | ||
receive_time, | ||
is_long_sms, | ||
total, | ||
current_id) | ||
break | ||
end | ||
until #data == 0 | ||
end | ||
else -- 其他命令 | ||
local cmd = current_line:match("^AT%+(%w+)") | ||
if cmd then--命令回复 | ||
if cmd == "CPIN" then | ||
-- 检查卡 | ||
repeat | ||
local l = table.remove(data, 1) | ||
if #l > 0 then | ||
if l:find("READY") then | ||
-- 找到卡了 | ||
sys.publish(constants.air780_message_topic_sim_detected, true) | ||
return | ||
elseif l:find("CME ERROR") then | ||
-- 没卡? | ||
sys.publish(constants.air780_message_topic_sim_detected, false) | ||
return | ||
end | ||
end | ||
until #data == 0 | ||
end | ||
end | ||
end | ||
end | ||
end) | ||
|
||
-- 发送AT指令并等待指定topic | ||
function air780_helper.send_at_command_and_wait(command, topic_listen_to, timeout) | ||
while true do | ||
air780_helper.send_at_command(command) | ||
local is_successful, r1, r2, r3 = sys.waitUntil(topic_listen_to, timeout or 1000) | ||
if is_successful then | ||
return r1, r2, r3 | ||
end | ||
end | ||
end | ||
|
||
return air780_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
local config = {} | ||
|
||
config.log_level = log.LOG_INFO | ||
|
||
-- ESP32板子型号 | ||
-- esp32c3 / esp32s3 | ||
config.board_type = "esp32s3" | ||
|
||
-- 是否禁止RNDIS | ||
-- 禁止RNDIS可以防止流量流失 | ||
config.disable_rndis = true | ||
|
||
config.wifi = { | ||
ssid = "Wi-Fi名", | ||
password = "Wi-Fi密码" | ||
} | ||
|
||
config.notification_channel = { | ||
-- 合宙推送服务器 | ||
luatos = { | ||
enabled = true, | ||
token = "" | ||
}, | ||
-- Bark | ||
bark = { | ||
enabled = true, | ||
api_key = "" | ||
}, | ||
-- Server酱 | ||
server_chan = { | ||
enabled = false, | ||
send_key = "" | ||
}, | ||
-- 钉钉Webhook机器人 | ||
ding_talk = { | ||
enabled = true, | ||
-- Webhook地址 | ||
webhook_url = "", | ||
-- 机器人安全设定中的关键词 | ||
keyword = "" | ||
}, | ||
-- PushPlus 推送加 | ||
pushplus = { | ||
enabled = true, | ||
token = "" | ||
} | ||
} | ||
|
||
return config |
Oops, something went wrong.