Blinker.connected函数在WiFi无法连通外网时返回1
本帖最后由 Blowind 于 2021-2-25 14:35 编辑代码如下,我希望通过LED快闪指示联通服务器,熄灭指示无法连接服务器。每秒检查一次连接状态。如下图串口打印结果,在WiFi正常连接外网时可以判断连接服务器,当我通过路由限制该设备连接外网时,开始打印MQTT Ping!但是Blinker.connected()返回还是1。请问应该如何实现我的需求?
bool isConnected = false;
unsigned long currentMillis, checkLoopTs, ledFlashTs;
void loop()
{
Blinker.run();
currentMillis = millis();
if(currentMillis - checkLoopTs > 1000){
checkLoopTs = currentMillis;
isConnected = Blinker.connected();
BLINKER_LOG("connected status : ", isConnected);
if(!isConnected){
digitalWrite(LED_BUILTIN, LOW);
}
}
if(isConnected){
if(currentMillis - ledFlashTs > 200){
ledFlashTs = currentMillis;
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
}
}
页:
[1]