[学习笔记]Esp32 + 4G模块,随身wifi,ppp拨号上网

一、简介

偶然在b站看到这个项目,视频中只有演示,教程不多。所以我弄了一遍,写出这篇学习笔记用作参考。有问题评论区留言,看到回复

示例硬件:Esp32S3 + Air724ug 【下面有图】
这个文章适用的硬件
Esp32s2Esp32s3
4g模块
Air724ugML302,Air780E,EC600,A7600C1,BG95M3,BG96MA,MC610_EU
上述的4g模块可以直接使用,其他的4g模块也可通过配置使用。

代码例程:乐鑫官方示例usb_cdc_4g_module
开发环境:ESP-IDF 5.3
所用工具:Git
环境搭建可以从csdn上找教程,挺多的就不细说了

Air724ug

Esp32S3
这俩硬件都是从某宝上买的(图片侵权请联系我)
接线

接线
随身wifi的速度我测试的:8M下行,34M上行(刷刷短视频还可以)

二、实现

第一步:打开ESP-IDF 5.3 PowerShell

第二步:使用cd命令切换文件夹,按情况修改路径

cd E:\Desktop\gitck

路径显示为你修改的
路径显示为你修改的表示成功

第三步:使用git命令克隆仓库,可以直接复制我这个代码

git clone https://github.com/espressif/esp-iot-solution.git

克隆完毕以后应该会出现esp-iot-solution文件夹,要是慢就上魔法或者想其他办法
在这里插入图片描述

第四步:切换到项目文件夹,同样使用cd命令

cd E:\Desktop\gitck\esp-iot-solution\examples\usb\host\usb_cdc_4g_module

在这里插入图片描述
文件方面就算结束了,后面就是ESP-IDF的编译烧录,我这里是用的命令,如果你用的vscode或者其他,自行找到对应的功能。

第五步:设置目标芯片,根据你使用的芯片修改

idf.py set-target esp32s3

在这里插入图片描述

第六步:打开menuconfig,进行项目配置

idf.py menuconfig

在这里插入图片描述
按上面的目录进到对应的位置,下面选择对应的4g模块型号。
键盘的上下用于调整,Enter是确定
选择好以后,按Q推出menuconfig,提示保存就按Y,也可以之前按S保存一下

第七步:编译、烧录、调试

//编译
idf.py build
//烧录
idf.py -p PORT flash
//调试
idf.py -p PORT monitor
//退出调试
用 Ctrl + ]
//编译、烧录、调试三合一
idf.py -p PORT flash monitor

这其中PORT是设备端口号,如果不知道用windows设备管理器查看

默认 Wi-Fi 名为 esp_4g_router
默认Wi-Fi密码为 12345678
可在 menuconfig4G Modem Configuration → WiFi soft AP 中修改 Wi-Fi 配置信息

后台账号:esp32
后台密码:12345678
后台ip:192.168.4.1

在这里插入图片描述
这是Esp32S3打印的信息和WIFI信息
在这里插入图片描述
这是随身wifi的管理后台,链接好WiFi以后,在浏览器输入192.168.4.1就能进去,到这就完事了。

对了、我这个Esp32s3板子5V电压没有,所以接入724ug的VBUS时有问题
我的解决办法是从ams1117输入端接出来的5V

最后

学习笔记,仅供参考,互相学习

您可以使用以下代码来设置esp32 4G MQTT订阅温度传感器的主题: #include <PubSubClient.h> #include <WiFi.h> #include <Wire.h> #include <Adafruit_Sensor.h> #include <Adafruit_BME280.h> // Replace with your network credentials const char* ssid = "your_SSID"; const char* password = "your_PASSWORD"; // Replace with your MQTT Broker IP address const char* mqtt_server = "your_MQTT_BROKER_IP"; WiFiClient espClient; PubSubClient client(espClient); Adafruit_BME280 bme; void setup() { Serial.begin(115200); delay(100); // Connect to Wi-Fi network with SSID and password Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); } Serial.println("WiFi connected!"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); // Connect to MQTT Broker client.setServer(mqtt_server, 1883); while (!client.connected()) { Serial.println("Connecting to MQTT Broker..."); if (client.connect("ESP32Client")) { Serial.println("Connected to MQTT Broker!"); } else { Serial.print("Failed with state "); Serial.print(client.state()); delay(2000); } } // Initialize BME280 sensor if (!bme.begin(0x76)) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); while (1); } // Subscribe to temperature sensor topic client.subscribe("temperature_sensor"); } void loop() { // Check if MQTT client is connected if (!client.connected()) { reconnect(); } // Read temperature from BME280 sensor float temperature = bme.readTemperature(); // Publish temperature to MQTT Broker char temperature_str[10]; dtostrf(temperature, 4, 2, temperature_str); client.publish("temperature_sensor", temperature_str); // Wait for 5 seconds delay(5000); } void reconnect() { // Loop until we're reconnected while (!client.connected()) { Serial.println("Attempting MQTT connection..."); // Attempt to connect if (client.connect("ESP32Client")) { Serial.println("Connected to MQTT Broker!"); // Subscribe to temperature sensor topic client.subscribe("temperature_sensor"); } else { Serial.print("Failed with state "); Serial.print(client.state()); delay(2000); } } }
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值