{"id":24091677,"url":"https://github.com/RT-Thread-packages/ppp_device","last_synced_at":"2025-09-17T01:31:42.580Z","repository":{"id":44540665,"uuid":"210350507","full_name":"RT-Thread-packages/ppp_device","owner":"RT-Thread-packages","description":"lwIP PPP porting for GSM modem (like sim800)","archived":false,"fork":false,"pushed_at":"2022-10-26T03:43:56.000Z","size":235,"stargazers_count":39,"open_issues_count":4,"forks_count":33,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-02-16T11:02:05.960Z","etag":null,"topics":["air720","gprs","iot","lwip","m6312","ppp","sim800"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RT-Thread-packages.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-23T12:32:36.000Z","updated_at":"2024-11-26T15:07:11.000Z","dependencies_parsed_at":"2023-01-20T05:47:52.554Z","dependency_job_id":null,"html_url":"https://github.com/RT-Thread-packages/ppp_device","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/RT-Thread-packages/ppp_device","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RT-Thread-packages%2Fppp_device","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RT-Thread-packages%2Fppp_device/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RT-Thread-packages%2Fppp_device/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RT-Thread-packages%2Fppp_device/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RT-Thread-packages","download_url":"https://codeload.github.com/RT-Thread-packages/ppp_device/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RT-Thread-packages%2Fppp_device/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275519682,"owners_count":25479434,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-16T02:00:10.229Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["air720","gprs","iot","lwip","m6312","ppp","sim800"],"created_at":"2025-01-10T07:44:39.751Z","updated_at":"2025-09-17T01:31:42.289Z","avatar_url":"https://github.com/RT-Thread-packages.png","language":"C","readme":"# PPP Device\n\n## 1. 简介\n\nPPP Device 软件包，是 RT-Thread 针对不同模块的 lwIP PPP 功能实现的软件包。它使蜂窝模块不再需要发送 AT 命令，使用 PPP 方式即可实现网络数据传输。\n\nPPP Device 软件包特点如下：\n\n- 支持多种蜂窝模块；\n- 无缝兼容多种应用层网络协议（HTTP、MQTT、TLS 等）；\n- 支持数据差错检测，提供可靠数据传输；\n\n* 提供 CHAT 方式初始化功能，方便设备移植；\n\n目前 PPP 功能支持 Luat Air720，Quectel EC20，China mobile M6312,  SIMCOM SIM800 模块，后续会接入更多蜂窝模块。\n\n\n\n对 PPP Device 有疑惑，或者对 PPP Device 感兴趣的开发者欢迎入群详细了解。\n\nQQ群：749347156 [\u003c传送门\u003e](https://jq.qq.com/?_wv=1027\u0026k=5KcuPGI)\n\n移植文档地址：[\u003c移植文档\u003e](./docs/port.md)\n\n### 1.1 框架图\n\n![](docs/figures/ppp_frame.jpg)\n\n- ppp_device 软件包是 lwIP 协议栈中 ppp 功能针对不同设备的具体实现；\n- ppp_device 软件包中实现 netdev 网卡设备，并对接 SAL 抽象层，应用层可直接使用 BSD Socket API 进行网络编程；\n\n### 1.2 目录结构\n\n| 名称 | 说明 |\n| ---- | ---- |\n| src | PPP Device 实现源码目录 |\n| inc | PPP Device 头文件目录 |\n| sample | PPP 功能示例文件目录 |\n| class | 不同设备针对 PPP 功能的移植适配目录 |\n\n### 1.3 许可证\n\nppp_device 软件包遵循 Apache-2.0 许可，详见 LICENSE 文件。\n\n### 1.4 依赖\n\n- RT-Thread 3.1.0+\n- lwIP 组件（ ppp 功能）\n\n## 2. 获取方式\n\n**PPP Device 软件包相关配置选项介绍**\n\n\n```c\n[*] PPP DEVICE: lwIP PPP porting for Cellular Module( 2G/3G/4G )\n    [ ]   Enable debug log output\n    [ ]   Enbale authorize connect feature\n    [*]   Enable link status detect feature\n    (10)     Link status detecct timeout\n          Select Internet Service Provider (china mobile)  ---\u003e\n          Select modem type (Luat Air720)  ---\u003e\n    [*]    Enable ppp device sample\n    (uart3) ppp device uart name\n          Version (latest)  ---\u003e\n```\n- **Enable debug log output:** 开启调试日志功能\n- **Enbale authorize connect feature:** 开启身份认证功能\n- **Enable lin status detect feature:** PPP链路连接监控，检测链路连接正常；设置为 0 则不开启链路监控；\n- **Select modem type:** 模块选择\n- **Select Internet Service Provider:** 网络运营商选择\n- **Enable ppp device sample:**  选择模块后会提示的模块使用示例\n- **ppp device uart name:** 模块使用的串口\n- **Version:** 软件包版本号\n\n## 3. 使用方式\n\nPPP Device 软件包初始化函数如下所示：\n\n**PPP 功能启动函数，该函数自动调用；没有调用停止函数前，不可再次调用**\n\n```c\nint ppp_sample_start(void)\n{\n    rt_device_t device = RT_NULL;\n    device = rt_device_find(PPP_DEVICE_NAME);\n    if(device == RT_NULL)\n    {\n        LOG_E(\"Can't find device (%s).\", PPP_DEVICE_NAME);\n        return -RT_ERROR;\n    }\n    if(ppp_device_attach((struct ppp_device *)device, PPP_CLIENT_NAME, RT_NULL) != RT_EOK)\n    {\n        LOG_E(\"ppp_device_attach execute failed.\");\n        return -RT_ERROR;\n    }\n    return RT_EOK;\n}\n// 自动初始化\nINIT_APP_EXPORT(ppp_sample_start);\n// 命令导出到MSH( ppp_sample_start 变更为ppp_start )\nMSH_CMD_EXPORT_ALIAS(ppp_sample_start, ppp_start, a sample of ppp device  for dailing to network);\n```\n\n* 模块拨号，模块进入 PPP 模式；\n* 注册 netdev 设备，接入标准网络框架；\n\n**PPP 功能停止函数，该函数可以退出 PPP 模式**\n\n```c\nint ppp_sample_stop(void)\n{\n    rt_device_t device = RT_NULL;\n    device = rt_device_find(PPP_DEVICE_NAME);\n    if(device == RT_NULL)\n    {\n        LOG_E(\"Can't find device (%s).\", PPP_DEVICE_NAME);\n        return -RT_ERROR;\n    }\n    if(ppp_device_detach((struct ppp_device *)device) != RT_EOK)\n    {\n        LOG_E(\"ppp_device_detach execute failed.\");\n        return -RT_ERROR;\n    }\n    return RT_EOK;\n}\nMSH_CMD_EXPORT_ALIAS(ppp_sample_stop, ppp_stop, a sample of ppp device for turning off network);\n```\n\n* 退出 PPP 模式，模块退出拨号模式；\n* 解注册 netdev 设备；\n\n模块上电后，自动初始化流程如下：\n\n```c\n \\ | /\n- RT -     Thread Operating System\n / | \\     4.0.2 build Sep 23 2019\n 2006 - 2019 Copyright by rt-thread team\nlwIP-2.0.2 initialized!\n[I/sal.skt] Socket Abstraction Layer initialize success.\n[I/ppp.chat] (uart3) has control by modem_chat.\n[I/ppp.dev] (uart3) is used by ppp_device.\nmsh /\u003e[I/ppp.dev] ppp connect successful.\n```\n\n设备上电初始化完成，模块提示拨号成功，然后可以在 FinSH 中输入命令 `ifconfig` 查看设备 IP 地址、MAC 地址等网络信息，如下所示：\n\n```shell\nmsh /\u003eifconfig\nnetwork interface device: pp (Default)           ## 设备名称\nMTU: 1500                                        ## 网络最大传输单元\nMAC: 95 45 68 39 68 52                           ## 设备 MAC 地址\nFLAGS: UP LINK_UP INTERNET_DOWN DHCP_DISABLE     ## 设备标志\nip address: 10.32.76.151                         ## 设备 IP 地址\ngw address: 10.64.64.64                          ## 设备网关地址\nnet mask  : 255.255.255.255                      ## 设备子网掩码\ndns server #0: 114.114.114.114                   ## 域名解析服务器地址0\ndns server #1: 120.196.165.7                     ## 域名解析服务器地址1\n```\n\n获取 IP 地址成功之后，如果开启 Ping 命令功能，可以在 FinSH 中输入命令 `ping + 域名地址` 测试网络连接状态， 如下所示：\n\n```shell\nmsh /\u003eping www.baidu.com\n60 bytes from 183.232.231.172 icmp_seq=0 ttl=55 time=84 ms\n60 bytes from 183.232.231.172 icmp_seq=1 ttl=55 time=78 ms\n60 bytes from 183.232.231.172 icmp_seq=2 ttl=55 time=78 ms\n60 bytes from 183.232.231.172 icmp_seq=3 ttl=55 time=78 ms\n```\n\n`ping` 命令测试正常说明 PPP Device 设备网络连接成功，之后可以使用 SAL（套接字抽象层） 抽象出来的标准 BSD Socket APIs 进行网络开发（MQTT、HTTP、MbedTLS、NTP、Iperf 等）。\n\n## 4. 注意事项\n\n* 一般的 SIM 卡因为只能从运营商网络获取内网地址，所以一般不能实现服务器相关功能\n* 特殊的 SIM 卡可以从运营商获取公网地址，可是实现服务器功能\n* 目前只支持一个设备通过 PPP 连接网络\n* 建议不要打开 RT_DEVICE_FLAG_DMA_TX\n* 如果网络环境不好，建议关闭 Enable lin status detect feature 选项，或调整成大一点的时间\n* RT_LWIP_TCPTHREAD_STACKSIZE 需要配置为不小于 2048，及时在 network 组件中修改\n* 不要忘记打开串口\n* 对于开启模块电源控制引脚的开发者，要注意模块的启动时间；通常模块启动时间较长，这时会出现长时间拨号不成功的问题，一定要注意模块的启动时间，避免造成使用上的一些障碍。\n\n## 5. 联系方式\n\n联系人：xiangxistu\n\nEmail: liuxianliang@rt-thread.com\n\n## 6. 致谢\n\n感谢网友 [@xfan1024](https://github.com/xfan1024) 的一些贡献及建议，在制作PPP DEVICE 时给与的帮助。提出了很多宝贵的意见来一同完善PPP DEVICE 软件包。","funding_links":[],"categories":["Packages"],"sub_categories":["IoT"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRT-Thread-packages%2Fppp_device","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRT-Thread-packages%2Fppp_device","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRT-Thread-packages%2Fppp_device/lists"}