使用WiFiManger配网,连接成功后导致Blinker出现异常-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 7431|回复: 17

[已解答] 使用WiFiManger配网,连接成功后导致Blinker出现异常

[复制链接]
发表于 2020-6-11 00:25 | 显示全部楼层 |阅读模式
本帖最后由 skygz 于 2020-6-11 17:19 编辑


//使用这句就会出现异常
Blinker.begin(auth, WiFi.SSID().c_str(),WiFi.psk().c_str());  

//直接指定WIFI参数, 则使用正常
Blinker.begin(auth, ssid, pswd);

//---------------------------------------------------------------------------------------
#define BLINKER_WIFI

#include <Blinker.h>
#include <WiFiManager.h>
//for LED status
#include <Ticker.h>

char auth[] = "*********";
//char ssid[] = "SKY";
//char pswd[] = "12345678";

// 新建组件对象
BlinkerButton Button1("btn-switch");

bool oState = false;
int Pin = 0;    //定义控制引脚
Ticker ticker;

void tick();


// 按下按键即会执行该函数
void button1_callback(const String & state)
{
    BLINKER_LOG("get button state: ", state);
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));

    digitalWrite(Pin, !digitalRead(Pin));
}

// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
    BLINKER_LOG("Blinker readString: ", data);

    Blinker.vibrate();
    uint32_t BlinkerTime = millis();
    Blinker.print("millis", BlinkerTime);
}

void setup()
{
    // 初始化串口
    Serial.begin(115200);
    BLINKER_DEBUG.stream(Serial);

    // 初始化有LED的IO
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, HIGH);

    pinMode(Pin, OUTPUT);              //定义io口为输出
    digitalWrite(Pin, HIGH);           //定义io默认电平
    //闪烁
    ticker.attach(0.6, tick);
    Serial.println("Connecting...");

    WiFiManager wifiManager;
    WiFi.mode(WIFI_STA);
    wifiManager.setDebugOutput(true);

    // 重置保存的修改 目标是为了每次进来都是去掉配置页面
    wifiManager.resetSettings();

    if(!wifiManager.autoConnect("ESP_AP","12345678")) {
        Serial.println(F("Failed to connect. Reset and try again. . ."));
        delay(3000);
        ESP.restart();;
        delay(5000);
    }

    Serial.println(F("Connected to Wifi."));
    Serial.print(F("My IP:"));
    Serial.println(WiFi.localIP());

    ticker.detach(); //取消闪烁
    digitalWrite(BUILTIN_LED, HIGH);

    // 初始化blinker
    Blinker.begin(auth, WiFi.SSID().c_str(),WiFi.psk().c_str());  //使用这句就会出现异常
    //Blinker.begin(auth, ssid, pswd); //直接指定WIFI参数, 则使用正常
    Blinker.attachData(dataRead);

    Button1.attach(button1_callback);
}

void loop() {
    Blinker.run();
}

/**
* 功能描述:设置LED灯闪烁,提示用户进入配置模式
*/
void tick(){
  int state = digitalRead(LED_BUILTIN);
  digitalWrite(LED_BUILTIN, !state);
}

//-----------------------------------------------------------------------------------


Connecting...
*WM: [1] getCoreVersion():          2_7_1
*WM: [1] system_get_sdk_version():  2.2.2-dev(38a443e)
*WM: [1] system_get_boot_version(): 31
*WM: [1] getFreeHeap():             34112
*WM: [1] resetSettings
*WM: [3] WiFi station enable
*WM: [3] enableSTA PERSISTENT ON
*WM: [1] SETTINGS ERASED
*WM: [1] AutoConnect
*WM: [1] No Credentials are Saved, skipping connect
*WM: [2] Starting Config Portal
*WM: [2] AccessPoint set password is VALID
*WM: [1] 12345678
*WM: [3] WiFi station enable
*WM: [2] Disabling STA
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID:  ESP_AP
*WM: [1] SoftAP Configuration
*WM: [1] --------------------
*WM: [1] ssid:             ESP_AP
*WM: [1] password:         12345678
*WM: [1] ssid_len:         6
*WM: [1] channel:          1
*WM: [1] authmode:         3
*WM: [1] ssid_hidden:     
*WM: [1] max_connection:   4
*WM: [1] country:          CN
*WM: [1] beacon_interval:  100(ms)
*WM: [1] --------------------
*WM: [1] AP IP address: 192.168.4.1
*WM: [3] setupConfigPortal
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip:  192.168.4.1
*WM: [2] HTTP server started
*WM: [2] WiFi Scan completed in 2187 ms
*WM: [2] Config Portal Running, blocking, waiting for clients...
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [3] Sent config page
*WM: [2] <- HTTP Root
*WM: [3] -> 192.168.4.1
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 5425 ms ago
*WM: [3] -> connect.rom.miui.com
*WM: [2] <- Request redirected to captive portal
*WM: [3] -> connect.rom.miui.com
*WM: [2] <- Request redirected to captive portal
*WM: [2] <- HTTP WiFi save  
*WM: [3] Method: POST
*WM: [3] Sent wifi save page
*WM: [2] processing save
*WM: [2] Connecting as wifi client...
*WM: [3] STA static IP:
*WM: [2] setSTAConfig static ip not set, skipping
*WM: [1] CONNECTED:
*WM: [1] Connecting to NEW AP: SKY
*WM: [3] Using Password: 12345678
*WM: [3] WiFi station enable
*WM: [3] enableSTA PERSISTENT ON
*WM: [1] connectTimeout not set, ESP waitForConnectResult...
*WM: [2] Connection result: WL_CONNECTED
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] Connect to new AP [SUCCESS]
*WM: [1] Got IP Address:
*WM: [1] 192.168.100.173
*WM: [2] disconnect configportal
*WM: [2] restoring usermode STA
*WM: [2] wifi status: WL_CONNECTED
*WM: [2] wifi mode: STA
*WM: [1] config portal exiting
Connected to Wifi.
My IP:192.168.100.173
SSID: SKY
PASS: 12345678
[171712]
[171713]
__       __                __
/\ \     /\ \    __        /\ \              v0.3.4
\ \ \___ \ \ \  /\_\    ___\ \ \/'\      __   _ __   
\ \ '__`\\ \ \ \/\ \ /' _ `\ \ , <    /'__`\/\`'__\
  \ \ \L\ \\ \ \_\ \ \/\ \/\ \ \ \\`\ /\  __/\ \ \./
   \ \_,__/ \ \__\\ \_\ \_\ \_\ \_\ \_\ \____\\ \_\  
    \/___/   \/__/ \/_/\/_/\/_/\/_/\/_/\/____/ \/_/  
    To better use blinker with your IoT project!
    Download latest blinker library here!
    => https://github.com/blinker-iot/blinker-library

[171757] Connecting to SKY
[172167] ESP8266_MQTT initialized...
[172167]
===========================================================
================== Blinker Timer loaded! ==================
Warning!EEPROM address 1536-2431 is used for Blinker Timer!
============= DON'T USE THESE EEPROM ADDRESS! =============
===========================================================

*WM: [3] unloading
[174231] WiFi Connected.
[174231] IP Address:
[174231] 192.168.100.173

Exception (29):
epc1=0x40212201 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffbc0 end: 3fffffc0 offset: 0190
3ffffd50:  3fff0bf8 3fff0c08 3fff0c04 4020ab7d  
3ffffd60:  00000000 00000000 3fff3a94 3fff3e0c  
3ffffd70:  0011001f 00ff05bc 3f0101bb 40001388  
3ffffd80:  3fff3e34 004e004f 00ff00c8 70747468  
3ffffd90:  3fff0073 85ff05bc 3fff52ec 0000001f  
3ffffda0:  00000000 3fff6bdc 0011001f 00ff3abf  
3ffffdb0:  3fff3a00 3fff3a94 80ff3aa4 00000000  
3ffffdc0:  00000000 00000000 ffffffff 4022cc01  
3ffffdd0:  00000000 0000000a 33373100 4022a63d  
3ffffde0:  80fffe50 00000000 00000000 3fffbe00  
3ffffdf0:  3fff1a74 3fff1b7f 3fff1dd4 3fff1e74  
3ffffe00:  3fff1e64 3fff1dd4 3ffffe20 3fffbe00  
3ffffe10:  0037003f 80ff115c 3fff1f00 0027002f  
3ffffe20:  80000031 0000000a 3ffffe4c 40227589  
3ffffe30:  3fffbde4 0020002f 00fffe7a 79696c61  
3ffffe40:  40006e75 86ff115c 3fff3eb4 000b000f  
3ffffe50:  00000000 3fffbdac 0020002f 00227589  
3ffffe60:  3fff5314 001a001f 00000a0d 3fff3e8c  
3ffffe70:  0018001f 00000002 3fff3c5c 0149014f  
3ffffe80:  00000000 3fff633c 0067006f 00000000  
3ffffe90:  3fff6b44 003b003f 00c6a7f0 3fff6c9c  
3ffffea0:  0011001f 00ff115c 40100498 0002a8a1  
3ffffeb0:  3ffffe00 3ffffdf0 00000000 3fff3a94  
3ffffec0:  3fffbe8c 00000000 3fff0c0c 4020fc59  
3ffffed0:  40218c78 3fffff00 3fffff00 3fff12b8  
3ffffee0:  3fffdad0 00000000 3fff05bc 4020ad61  
3ffffef0:  007a1200 00000000 3fff05bc 4020af19  
3fffff00:  40105461 033e99fd 3fff1318 00000000  
3fffff10:  3ffef890 3fff1318 0000000a 3fff12b8  
3fffff20:  3fffdad0 3fff1318 0000000a 402292ac  
3fffff30:  3fffdad0 00000000 3fff05bc 4020af5a  
3fffff40:  3fffdad0 00000000 3fff00c8 4020f69c  
3fffff50:  0000203a 80efeffe 3fff5100 000e000f  
3fffff60:  007a1200 359c59bf 000f0000 80efeffe  
3fffff70:  00000000 feefeffe 80efeffe 3fff5100  
3fffff80:  00000000 00000000 00000001 3fff12b8  
3fffff90:  3fffdad0 00000000 3fff1278 4020fa68  
3fffffa0:  3fffdad0 00000000 3fff1278 402293c4  
3fffffb0:  feefeffe feefeffe 3ffe85b0 40100ee5  
<<<stack<<<

last failed alloc call: 4020AB7D(2280)

ets Jan  8 2013,rst cause:2, boot mode3,6)

load 0x4010f000, len 3456, room 16
tail 0
chksum 0x84
csum 0x84
va5432625
~ld

发表于 2020-6-13 17:56 来自手机 | 显示全部楼层
其实只要连接WiFi就行了,这里用这个就行了,Blinker.begin(auth);
 楼主| 发表于 2021-2-10 00:22 | 显示全部楼层
MaK-er 发表于 2021-2-9 00:15
可以分享一下配网汉化库吗

WiFiManager.rar (107.05 KB, 下载次数: 98)
发表于 2020-6-11 08:52 | 显示全部楼层
之前社区有人实现过,这个只有看源码自己分析了
 楼主| 发表于 2020-6-11 17:07 | 显示全部楼层
本帖最后由 skygz 于 2020-6-11 21:37 编辑

给个不完全的解决方法吧,这是我免强能接受的用法了,这个用法 依然偶尔会重启,  但起码不是 每次重启了。没有别的办法了,原因我也找不出来

文件头全局变量定义如下(不能在void setup()里定义为局部变量,一样会异常重启), 不要用char ssid[],char* ssid 之类的声明,之后在代码里用memcpy,strlcpy, str.copy()等方法,反复试过了,都是必定会异常重启。要定义为String全局变量

String ssid;
String pswd;

void setup()里的配置里,经过 wifiManager.autoConnect配网成功之后取出ssid和密码 给 string 变量里, 再给Blinker使用。不能在Blinker.begin里这样使用WiFi.SSID().c_str()

    Serial.println(F("Connected to Wifi."));


    ssid=WiFi.SSID();
    pswd=WiFi.psk();
    Blinker.begin(auth, ssid.c_str(), pswd.c_str());  

WiFiManager全部汉化界面了。
1.JPG

发表于 2020-6-13 17:59 | 显示全部楼层
单片机菜鸟哥,讲过这个,非常详细,可以去看看,
 楼主| 发表于 2020-6-13 21:19 | 显示全部楼层
YLGZS 发表于 2020-6-13 17:59
单片机菜鸟哥,讲过这个,非常详细,可以去看看,

只是详细讲 WiFiManager用法。。。可没说过有此种现象
 楼主| 发表于 2020-6-13 21:23 | 显示全部楼层
YLGZS 发表于 2020-6-13 17:56
其实只要连接WiFi就行了,这里用这个就行了,Blinker.begin(auth);

不能, 必须3个参数。
发表于 2020-6-17 15:49 | 显示全部楼层
这个我搞过,不过不好用,全部做好运行有,剩余的内存已经很少了,不稳定,后来放弃了
发表于 2020-6-17 17:18 | 显示全部楼层
blinker提供了esptouch和apconfig两种配网方式,为啥不用呢?
发表于 2021-2-9 00:14 | 显示全部楼层
奈何col 发表于 2020-6-17 17:18
blinker提供了esptouch和apconfig两种配网方式,为啥不用呢?

不行,代码量多了就会占用blinker专用eeprom内存,无WiFi直接卡死

点评

那建议使用esp32  详情 回复 发表于 2021-2-9 09:52
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 12:51 , Processed in 0.190695 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表