小漠的博客 - 物联网
type: channel
link: http://www.liaosearch.com/category/物联网/
items: 下载到内存中播放图片
items: 雷达传感器数据写入sd卡的代码
items: 果云版接线图
items: esp32s3使用arduino通过TJpg_Decoder实现屏幕上图片显示效果
items: esp32s3使用arduino 通过热点连接wifi，并且led指示灯闪烁
items: esp32s3管脚
items: esp32s3使用wifimanager中文配置
items: esp32 ap热点连接wifi

下载到内存中播放图片
type: item
date: 2025-06-24T21:16:00+08:00
description: #include <WiFiManager.h> #include <WiFi.h> #include <TFT_eSPI.h> #include <PubSubClient.h> #include "esp_system.h" #include <Arduino.h> #include <TJpg_Decoder.h> #include <HTTPClient.h> #include <src/CommonUtils.h> TFT_eSPI tft = TFT_eSPI(); // 创建TFT对象 WiFiManager wifiManager; unsigned long buttonPressTime = 0; bool isConnected = false; // 正在连接标记 bool resetTriggered = false; #define BOOT_BUTTON_PIN 0 // 显示状态常量 #define STATUS_WIFI_CONNECTING 0 #define STATUS_WIFI_CONNECTED 1 #define STATUS_WIFI_DISCONNECTED 2 #define STATUS_MQTT_CONNECTING 3 #define STATUS_MQTT_CONNECTED 4 #define STATUS_DOWNLOADING 5 #define STATUS_DISPLAYING_IMAGE 6 #define STATUS_PLAYING_MJPEG 7 int currentStatus = STATUS_WIFI_CONNECTING; // MQTT 配置 const char* mqttServer = "xxxx"; const int mqttPort = 1883; const char* mqttUser = "xxxx"; // 无需认证留空 const char* mqttPassword = "xxxx"; const char* clientId = "arduino_client_1232"; // 客户端ID需唯一 WiFiClient espClient; PubSubClient client(espClient); bool isVideo = false; // 内存缓冲区 uint8_t* jpegBuffer = NULL; // JPEG原始数据缓冲区 (PSRAM) size_t jpegSize = 0; // JPEG图片大小 uint8_t* mjpegBuffer = NULL; // MJPEG文件缓冲区 (PSRAM) size_t mjpegSize = 0; // MJPEG文件大小 size_t mjpegPosition = 0; // 当前MJPEG文件位置 // 帧缓冲区 uint8_t* frameBuffer = NULL; // 单帧数据缓冲区 size_t frameSize = 0; // 当前帧大小 // 流缓冲区 uint8_t* streamBuffer = NULL; // 流数据缓冲区 size_t streamBufferSize = 0; // 流缓冲区大小 size_t streamBufferPos = 0; // 流缓冲区位置 // 定义常量以提高可读性和可维护性 #define BUFFER_SIZE 4096 // 增大缓冲区大小 #define DOWNLOAD_TIMEOUT 15000 // 下载超时时间(毫秒) #define DATA_TIMEOUT 5000 // 数据超时时间(毫秒) #define PROGRESS_INTERVAL 500 // 进度显示间隔(毫秒) // 帧处理相关 #define MAX_FRAME_SIZE (1024 * 1024) // 最大帧大小1MB #define STREAM_BUFFER_SIZE (16 * 1024) // 流缓冲区大小16KB #define FRAME_DELAY 40 // 帧延迟(毫秒)，影响播放速度 // 默认MJPEG URL const char* defaultMjpegUrl = "https://chenhuan-esp.oss-cn-beijing.aliyuncs.com/output.avi"; // 当前播放状态 bool isPlayingMjpeg = false; unsigned long lastFrameTime = 0; unsigned long frameCount = 0; unsigned long mjpegStartTime = 0…

雷达传感器数据写入sd卡的代码
type: item
date: 2025-05-29T23:36:00+08:00
description: [scode type="yellow"]雷达传感器也遇到了问题最终原因查明仍然是需要接入5v电压的问题[/scode]#include <SPI.h> #include <SD.h> #include <SoftwareSerial.h> #include <HMMD_Radar.h> // 自定义SPI引脚定义 #define SD_CS_PIN 10 // 片选引脚 #define SD_MOSI_PIN 2 // 主输出从输入 #define SD_MISO_PIN 1 // 主输入从输出 #define SD_SCK_PIN 3 // 时钟引脚 // 定义UART和引脚 #define RADAR_RX_PIN 20 #define RADAR_TX_PIN 21 SoftwareSerial mySerial(RADAR_TX_PIN, RADAR_RX_PIN); File dataFile; const char* filename = "/data.txt"; // 存储数据的文件名 void setup() { Serial.begin(115200); Serial.println("Initializing SD card..."); // 初始化自定义SPI引脚 SPI.begin(SD_SCK_PIN, SD_MISO_PIN, SD_MOSI_PIN, SD_CS_PIN); // 初始化SD卡 if (!SD.begin(SD_CS_PIN, SPI, 1000000)) { Serial.println("SD初始化失败"); return; } else { Serial.println("SD初始化成功"); } // 检查文件是否存在，如果不存在则创建并写入标题行 if (!SD.exists(filename)) { dataFile = SD.open(filename, FILE_WRITE); if (dataFile) { dataFile.println("Timestamp,Data"); // 添加标题行 dataFile.close(); Serial.println("Created new file with headers."); } else { Serial.println("Error creating file!"); } } Serial1.begin(115200, SERIAL_8N1, RADAR_TX_PIN, RADAR_RX_PIN); // UART1 初始化 } void loop() { if (Serial1.available()) { String line = Serial1.readStringUntil('\n'); // 按行读取 UART1 数据 line.trim(); // 去除多余的 \r 或空格 if (line.length() > 0) { Serial.println("接收到： " + line); // 将数据写入SD卡 dataFile = SD.open(filename, FILE_APPEND); if (dataFile) { // 添加时间戳（以毫秒为单位） dataFile.print(millis()); dataFile.print(","); dataFile.println(line); dataFile.close(); Serial.println("数据已写入SD卡"); } else { Serial.println("错误：无法打开文件进行写入！"); } } } delay(10); }

果云版接线图
type: item
date: 2025-05-24T14:18:00+08:00

esp32s3使用arduino通过TJpg_Decoder实现屏幕上图片显示效果
type: item
date: 2025-05-22T22:00:00+08:00
description: #include <SPIFFS.h> #include <Arduino.h> #include <TFT_eSPI.h> #include "src/WIFILedManager.h" #include <TJpg_Decoder.h> #define BOOT_BUTTON_PIN 0 WIFILedManager ledManager(48, 1); TFT_eSPI tft = TFT_eSPI(); void listSPIFFSFiles() { File root = SPIFFS.open("/"); if (!root) { Serial.println("无法打开根目录"); return; } Serial.println("SPIFFS 文件列表:"); File file = root.openNextFile(); while (file) { Serial.printf(" %s (%d Bytes)\n", file.name(), file.size()); file = root.openNextFile(); } root.close(); } // TFT渲染回调函数（必须实现） bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap) { tft.pushImage(x, y, w, h, bitmap); // 将解码后的像素块推送到屏幕 return true; // 返回true表示渲染成功 } void setup() { Serial.begin(115200); Serial.println("开始启动"); Serial.println("初始化按钮引脚..."); pinMode(BOOT_BUTTON_PIN, INPUT_PULLUP); Serial.println("初始化屏幕..."); tft.init(); tft.setRotation(1); tft.fillScreen(TFT_BLACK); digitalWrite(TFT_BL, HIGH); Serial.println("屏幕初始化完成"); Serial.println("初始化 LED 管理器..."); ledManager.begin(); Serial.println("挂载 SPIFFS..."); if (!SPIFFS.begin()) { Serial.println("SPIFFS Mount Failed"); return; } Serial.println("SPIFFS 挂载成功"); listSPIFFSFiles(); bool exist = SPIFFS.exists("/test.jpg"); if (exist) { Serial.println("The file exists!"); } else { Serial.println("No such file found."); } // 设置TJpgDec TJpgDec.setJpgScale(1); // 缩放比例（1:1） TJpgDec.setSwapBytes(true); // 交换颜色字节序（适配TFT_eSPI） TJpgDec.setCallback(tft_output); // 绑定渲染回调函数 // 显示图片（全屏居中） TJpgDec.drawFsJpg(0, 0, "/test.jpg"); } void loop() { static unsigned long pressStart = 0; static bool resetFlag = false; // 按钮检测 if (digitalRead(BOOT_BUTTON_PIN) == LOW) { if (!resetFlag) { pressStart = millis(); resetFlag = true; } if (millis() - pressStart > 3000) { ledManager.resetSettings(); } } else { resetFlag = false; } // 更新网络状态 ledManager.update(); delay(100); }

esp32s3使用arduino 通过热点连接wifi，并且led指示灯闪烁
type: item
date: 2025-05-21T21:27:00+08:00
description: #include <WiFiManager.h> #include <WiFi.h> #include <Adafruit_NeoPixel.h> #include <Ticker.h> #define BOOT_BUTTON_PIN 0 // BOOT按钮对应GPIO0 // 定义WS2812 LED参数 #define LED_PIN 48 #define LED_COUNT 1 Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); // LED状态控制 Ticker ledTicker; bool isConnected = false; const uint8_t BRIGHTNESS = 12; // 整体亮度 const uint32_t CONNECTED_COLOR = strip.Color(0, 255, 0); // 绿色 const uint32_t CONNECTING_COLOR = strip.Color(255, 255, 0); // 黄色 unsigned long buttonPressTime = 0; bool resetTriggered = false; void updateLed() { static bool ledState = false; if (!isConnected) { uint32_t color = ledState ? CONNECTING_COLOR : 0; for(int i=0; i<LED_COUNT; i++) { strip.setPixelColor(i, color); } strip.show(); ledState = !ledState; } } void setup() { Serial.begin(115200); pinMode(BOOT_BUTTON_PIN, INPUT_PULLUP); // 初始化LED strip.begin(); strip.setBrightness(BRIGHTNESS); strip.show(); // 启动连接状态闪烁 ledTicker.attach(0.5, updateLed); WiFiManager wifiManager; wifiManager.setTimeout(180); if (!wifiManager.autoConnect("ESP32-Config")) { Serial.println("配网失败，重启设备"); ledTicker.detach(); delay(5000); ESP.restart(); } // 连接成功处理 ledTicker.detach(); isConnected = true; for(int i=0; i<LED_COUNT; i++) { strip.setPixelColor(i, CONNECTED_COLOR); } strip.show(); Serial.println("\nWiFi已连接！"); Serial.print("IP地址: "); Serial.println(WiFi.localIP()); } void loop() { // 按钮检测（保持原功能） if (digitalRead(BOOT_BUTTON_PIN) == LOW && !resetTriggered) { delay(50); if (digitalRead(BOOT_BUTTON_PIN) == LOW) { buttonPressTime = millis(); resetTriggered = true; while (digitalRead(BOOT_BUTTON_PIN) == LOW) { if (millis() - buttonPressTime > 3000) { Serial.println("\n重置WiFi配置..."); WiFiManager wifiManager; wifiManager.resetSettings(); // 重置LED状态 ledTicker.detach(); for(int i=0; i<LED_COUNT; i++) { strip.setPixelColor(i, 0); } strip.show(); delay(2000); ESP.restart(); } } resetTriggered = false; } } // WiFi状态监测 if (WiFi.status() != WL_CONNECTED && isConnected) { is…

esp32s3管脚
type: item
date: 2025-05-21T20:46:00+08:00
description: #define BOOT_BUTTON_PIN 0 // BOOT按钮对应GPIO0 #define BOOT_LED 97 // BOOT WS2812 LED 使用GPIO时为97，固定白色，不可调节颜色 #define LED_PIN 48 // BOOT WS2812 LED 设置为可调节led灯时，可调节颜色 用Adafruit_NeoPixel触发

esp32s3使用wifimanager中文配置
type: item
date: 2025-05-21T17:04:35+08:00
description: /** * wm_strings_en.h * engligh strings for * WiFiManager, a library for the ESP8266/Arduino platform * for configuration of WiFi credentials using a Captive Portal * * @author Creator tzapu * @author tablatronix * @version 0.0.0 * @license MIT */ #ifndef _WM_STRINGS_EN_H_ #define _WM_STRINGS_EN_H_ #ifndef WIFI_MANAGER_OVERRIDE_STRINGS // !!! ABOVE WILL NOT WORK if you define in your sketch, must be build flag, if anyone one knows how to order includes to be able to do this it would be neat.. I have seen it done.. // strings files must include a consts file! #include "wm_consts_en.h" // include constants, tokens, routes const char WM_LANGUAGE[] PROGMEM = "en-US"; // i18n lang code const char HTTP_HEAD_START[] PROGMEM = " " " " " " " " " " " {v} "; const char HTTP_SCRIPT[] PROGMEM = " "; // @todo add button states, disable on click , show ack , spinner etc const char HTTP_HEAD_END[] PROGMEM = " "; // {c} = _bodyclass // example of embedded logo, base64 encoded inline, No styling here // const char HTTP_ROOT_MAIN[] PROGMEM = "<img title=' alt=' src='[binary]' /> {v} WiFiManager "; const char HTTP_ROOT_MAIN[] PROGMEM = " {t} {v} "; const char * const HTTP_PORTAL_MENU[] PROGMEM = { " 配置WiFi \n", " 配置WiFi（不扫描） \n", " 系统信息 \n", " 参数设置 \n", " 关闭门户 \n", " 重启设备 \n", " 退出配置 \n", " 清除配置 \n", " 固件升级 \n", " " }; // const char HTTP_PORTAL_OPTIONS[] PROGMEM = strcat(HTTP_PORTAL_MENU[0] , HTTP_PORTAL_MENU[3] , HTTP_PORTAL_MENU[7]); const char HTTP_PORTAL_OPTIONS[] PROGMEM = ""; const char HTTP_ITEM_QI[] PROGMEM = " "; const char HTTP_ITEM_QP[] PROGMEM = " {r}% "; const char HTTP_ITEM[] PROGMEM = " {v}{qi}{qp} "; const char HTTP_FORM_START[] PROGMEM = " "; const char HTTP_FORM_WIFI[] PROGMEM = " 网络名称 密码 显示密码 "; const char HTTP_FORM_WIFI_END[] PROGMEM = ""; const char HTTP_FORM_STATIC_HEAD[] PROGMEM = " "; const char HTTP_FORM_END[] PROGMEM = " 保存设置 "; const char HTTP_FORM_LABEL[] PROGMEM = " {t} "; const char HTTP_FORM_PARAM_HEAD[] PROGMEM = " "; const char HTTP_FORM_PARAM[] PROGMEM…

esp32 ap热点连接wifi
type: item
date: 2025-05-16T21:18:00+08:00
description: #include <stdio.h> #include <string.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_wifi.h" #include "esp_event.h" #include "esp_log.h" #include "nvs_flash.h" #include "esp_netif.h" #include "esp_http_server.h" // 配置参数 #define EXAMPLE_ESP_WIFI_SSID "ESP321_Config" // 热点名称 #define EXAMPLE_ESP_WIFI_PASS "12345678" // 热点密码 #define EXAMPLE_ESP_WIFI_CHANNEL 6 // 热点信道 #define MAX_STA_CONN 4 // 最大连接数 #define CONFIG_EXAMPLE_WEB_MOUNT_POINT "/www" // Web挂载点 static const char *TAG = "wifi_config"; // 宏定义 #define MIN(a, b) ((a) < (b) ? (a) : (b)) // 函数前置声明 static void wifi_init_softap(void); static void wifi_stop_ap(void); static void wifi_connect_sta(const char *ssid, const char *password); static bool check_saved_wifi_config(void); static void start_webserver(void); static void stop_webserver(void); static void save_wifi_config(const char *ssid, const char *password); static void url_decode(char *str); static httpd_handle_t server = NULL; /* 配置页面的HTML */ static const char* CONFIG_HTML = " " " " " " " " " " " WiFi Configuration " " " " " " " " " " WiFi Configuration " " " " WiFi SSID: " " " " WiFi Password: " " " " Connect " " " " " " " " "; /* 成功页面的HTML */ static const char* SUCCESS_HTML = " " " " " " " " " Configuration Successful " " " " " " " " Configuration Successful! " " ESP32 is now connecting to your WiFi network. " " " " "; /* 处理根路径请求 */ static esp_err_t root_get_handler(httpd_req_t *req) { httpd_resp_set_type(req, "text/html"); return httpd_resp_send(req, CONFIG_HTML, strlen(CONFIG_HTML)); } /* URL解码 */ static void url_decode(char *str) { char *p = str; char decoded; while (*p) { if (*p == '%') { sscanf(p + 1, "%2hhx", &decoded); *str++ = decoded; p += 3; } else if (*p == '+') { *str++ = ' '; p++; } else { *str++ = *p++; } } *str = '\0'; } /* 处理配置提交 */ static esp_err_t configure_post_handler(httpd_req_t *req) { char buf[100]; int ret, remaining = req->content_len; char ssid[32] = {0}; char password[64] = {0}; while (remaining > 0) { if ((…