关于blinker连接超时或者连接不上的问题
本帖最后由 sting2k1 于 2020-5-16 16:25 编辑最近,blinker的连接有时一直连不上,超时。查看了一下,原来是升级了blinker库后,库程序判断连接上的程序问题。
库程序位于blinker-library-master\src\Adapters文件中的BlinkerMQTT.h文件,子函数是BlinkerMQTT::checkInit() (2242行)
原来的程序是这样的,
更改为,
bool BlinkerMQTT::checkInit()
{
connectCount = 40;
if (!_isWiFiInit)
{
switch (_configType)
{
case COMM :
_connectTime = millis();
// BLINKER_LOG(BLINKER_F("checkInit..."));
while ((WiFi.status() != WL_CONNECTED) && connectCount > 0) {
::delay(500);
connectCount --;
if (millis() - _connectTime > BLINKER_CONNECT_TIMEOUT_MS && WiFi.status() != WL_CONNECTED) {
// _connectTime = millis();
BLINKER_LOG(BLINKER_F("WiFi connect timeout, please check ssid and pswd!"));
BLINKER_LOG(BLINKER_F("Retring WiFi connect again!"));
return false;
}
BLINKER_LOG(BLINKER_F("checkInit..."), connectCount);
if (connectCount == 0) {
return false;
}
}
BLINKER_LOG(BLINKER_F("WiFi Connected."));
BLINKER_LOG(BLINKER_F("IP Address: "));
BLINKER_LOG(WiFi.localIP());
_isWiFiInit = true;
_connectTime = 0;
// begin();
return false;
case BLINKER_SMART_CONFIG :
switch (_configStatus)
{
case SMART_BEGIN :
if (WiFi.smartConfigDone())
{
BLINKER_LOG(BLINKER_F("SmartConfig received."));
_connectTime = millis();
#if defined(ESP8266)
BLINKER_LOG(BLINKER_F("SSID: "), WiFi.SSID(), BLINKER_F(" PSWD: "), WiFi.psk());
#endif
_configStatus = SMART_DONE;
}
else return false;
case SMART_DONE :
if (WiFi.status() != WL_CONNECTED)
{
if (millis() - _connectTime > 15000)
{
BLINKER_LOG(BLINKER_F("SmartConfig timeout."));
WiFi.stopSmartConfig();
_configStatus = SMART_TIMEOUT;
}
return false;
}
else if (WiFi.status() == WL_CONNECTED)
{
// WiFi.stopSmartConfig();
BLINKER_LOG(BLINKER_F("WiFi Connected."));
BLINKER_LOG(BLINKER_F("IP Address: "));
BLINKER_LOG(WiFi.localIP());
_isWiFiInit = true;
_connectTime = 0;
// begin();
return false;
}
// return false;
case SMART_TIMEOUT :
WiFi.beginSmartConfig();
_configStatus = SMART_BEGIN;
BLINKER_LOG(BLINKER_F("Waiting for SmartConfig."));
return false;
default :
return false;
}
case BLINKER_AP_CONFIG :
#if defined(BLINKER_APCONFIG)
switch (_configStatus)
{
case APCFG_BEGIN :
checkAPCFG();
return false;
case APCFG_DONE :
if (WiFi.status() != WL_CONNECTED)
{
if (millis() - _connectTime > 15000)
{
BLINKER_LOG(BLINKER_F("APConfig timeout."));
_configStatus = APCFG_TIMEOUT;
}
return false;
}
else if (WiFi.status() == WL_CONNECTED)
{
BLINKER_LOG(BLINKER_F("WiFi Connected."));
BLINKER_LOG(BLINKER_F("IP Address: "));
BLINKER_LOG(WiFi.localIP());
_isWiFiInit = true;
_connectTime = 0;
// begin();
return false;
}
// return false;
case APCFG_TIMEOUT :
softAPinit();
return false;
default :
return false;
}
#endif
default :
return false;
}
}
if (!_isBegin)
{
_isBegin = begin();
return _isBegin;
}
return true;
}
更改后的程序能清楚看到连接的时间,不容易断了。
以上是我的使用体验,不对的地方请大家指正。
串口显示连接上了,但是app显示离线
本帖最后由 q1127957008 于 2020-5-16 21:08 编辑我的问题和你的一样吗?
页:
[1]