Manual connection over ethernet

• ESP32 Wroom
• Blynk Library version 1.0.1

Hi I’m trying to setup ethernet support together with Blynk Edgent. I’m just trying to manually configure the ethernet to see if it is connecter or not, to determine whether or not to establish connection to Blynk through ethernet or the edgent. So the only way I have been able to connect over ethernet is with BlynkEthernetClient.begin(auth) (renamed the BlynkSimpleEthernet class name due to duplicate import with BlynkEdgent). But when using that begin call, if the ethernet is not plugged in, it seems to hang and won’t go further.

The code below however gets stuck on the while loop and can’t connect. This is when using Ethernet.begin() manually.


bool checkEthernetCable() 
{
    if (Ethernet.linkStatus() == EthernetLinkStatus::LinkON)
    {
        return true;
    }
    else 
    {
        return false;
    }    
}


void setupBlynk() 
{    
    Serial.println("[Portal] Setting up Blynk connection");
    Ethernet.init(ETHERNET_CS_PIN);
    Ethernet.begin(mac, ip);

    if(Ethernet.hardwareStatus() != EthernetNoHardware) 
    {       
        bHasEthernetChip = true;
        bEthernetConnected = checkEthernetCable();
    }
    else 
    {
        Serial.println("[MQTT] Ethernet initialising failed");
    }

    if(bEthernetConnected)
    {
        Serial.println("[Portal] Attempting to start Ethernet client");
        BlynkEthernetClient.config(BLYNK_AUTH_TOKEN);
        while(BlynkEthernetClient.connect() != true) 
        {
            Serial.println("Not connected");
        }      
    }
    else
    {
        Serial.println("[Portal] Attempting to start WiFi client");
        BlynkEdgent.begin(); 
    }
}

void blynkLoop() {  

    if (bHasEthernetChip)
    {     
        if(bEthernetConnected == true) 
        {   
            Serial.println("Ethernet");   
            BlynkEthernetClient.run();   
        }
        else 
        {        
            Serial.println("Wifi");       
            BlynkEdgent.run(); 
        }   
    }
    else
    {
        BlynkEdgent.run(); 
    }    

    mqttLoop();
}