使用WiFiManger配网,连接成功后导致Blinker出现异常
本帖最后由 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: getCoreVersion(): 2_7_1
*WM: system_get_sdk_version():2.2.2-dev(38a443e)
*WM: system_get_boot_version(): 31
*WM: getFreeHeap(): 34112
*WM: resetSettings
*WM: WiFi station enable
*WM: enableSTA PERSISTENT ON
*WM: SETTINGS ERASED
*WM: AutoConnect
*WM: No Credentials are Saved, skipping connect
*WM: Starting Config Portal
*WM: AccessPoint set password is VALID
*WM: 12345678
*WM: WiFi station enable
*WM: Disabling STA
*WM: Enabling AP
*WM: StartAP with SSID:ESP_AP
*WM: SoftAP Configuration
*WM: --------------------
*WM: ssid: ESP_AP
*WM: password: 12345678
*WM: ssid_len: 6
*WM: channel: 1
*WM: authmode: 3
*WM: ssid_hidden:
*WM: max_connection: 4
*WM: country: CN
*WM: beacon_interval:100(ms)
*WM: --------------------
*WM: AP IP address: 192.168.4.1
*WM: setupConfigPortal
*WM: Starting Web Portal
*WM: dns server started with ip:192.168.4.1
*WM: HTTP server started
*WM: WiFi Scan completed in 2187 ms
*WM: Config Portal Running, blocking, waiting for clients...
*WM: lastconxresult: WL_IDLE_STATUS
*WM: Sent config page
*WM: <- HTTP Root
*WM: -> 192.168.4.1
*WM: lastconxresult: WL_IDLE_STATUS
*WM: Scan is cached 5425 ms ago
*WM: -> connect.rom.miui.com
*WM: <- Request redirected to captive portal
*WM: -> connect.rom.miui.com
*WM: <- Request redirected to captive portal
*WM: <- HTTP WiFi save
*WM: Method: POST
*WM: Sent wifi save page
*WM: processing save
*WM: Connecting as wifi client...
*WM: STA static IP:
*WM: setSTAConfig static ip not set, skipping
*WM: CONNECTED:
*WM: Connecting to NEW AP: SKY
*WM: Using Password: 12345678
*WM: WiFi station enable
*WM: enableSTA PERSISTENT ON
*WM: connectTimeout not set, ESP waitForConnectResult...
*WM: Connection result: WL_CONNECTED
*WM: lastconxresult: WL_CONNECTED
*WM: Connect to new AP
*WM: Got IP Address:
*WM: 192.168.100.173
*WM: disconnect configportal
*WM: restoring usermode STA
*WM: wifi status: WL_CONNECTED
*WM: wifi mode: STA
*WM: config portal exiting
Connected to Wifi.
My IP:192.168.100.173
SSID: SKY
PASS: 12345678
__ __ __
/\ \ /\ \ __ /\ \ v0.3.4
\ \ \___ \ \ \/\_\ ___\ \ \/'\ __ _ __
\ \ '__`\\ \ \ \/\ \ /' _ `\ \ , < /'__`\/\`'__\
\ \ \L\ \\ \ \_\ \ \/\ \/\ \ \ \\`\ /\__/\ \ \./
\ \_,__/ \ \__\\ \_\ \_\ \_\ \_\ \_\ \____\\ \_\
\/___/ \/__/ \/_/\/_/\/_/\/_/\/_/\/____/ \/_/
To better use blinker with your IoT project!
Download latest blinker library here!
=> https://github.com/blinker-iot/blinker-library
Connecting to SKY
ESP8266_MQTT initialized...
===========================================================
================== Blinker Timer loaded! ==================
Warning!EEPROM address 1536-2431 is used for Blinker Timer!
============= DON'T USE THESE EEPROM ADDRESS! =============
===========================================================
*WM: unloading
WiFi Connected.
IP Address:
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 Jan8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 3456, room 16
tail 0
chksum 0x84
csum 0x84
va5432625
~ld
其实只要连接WiFi就行了,这里用这个就行了,Blinker.begin(auth); MaK-er 发表于 2021-2-9 00:15
可以分享一下配网汉化库吗
之前社区有人实现过,这个只有看源码自己分析了 本帖最后由 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全部汉化界面了。
单片机菜鸟哥,讲过这个,非常详细,可以去看看, YLGZS 发表于 2020-6-13 17:59
单片机菜鸟哥,讲过这个,非常详细,可以去看看,
只是详细讲 WiFiManager用法。。。可没说过有此种现象 YLGZS 发表于 2020-6-13 17:56
其实只要连接WiFi就行了,这里用这个就行了,Blinker.begin(auth);
不能, 必须3个参数。 这个我搞过,不过不好用,全部做好运行有,剩余的内存已经很少了,不稳定,后来放弃了 blinker提供了esptouch和apconfig两种配网方式,为啥不用呢? 奈何col 发表于 2020-6-17 17:18
blinker提供了esptouch和apconfig两种配网方式,为啥不用呢?
不行,代码量多了就会占用blinker专用eeprom内存,无WiFi直接卡死
页:
[1]
2