blynkkk / blynk-library

Blynk library for IoT boards. Works with Arduino, ESP32, ESP8266, Raspberry Pi, Particle, ARM Mbed, etc.
https://blynk.io
MIT License
3.81k stars 1.38k forks source link

Blynk mobile app stops sending commands to device . #572

Closed sonirohit3 closed 1 year ago

sonirohit3 commented 1 year ago

Blynk library version: [0.6.1 / 1.1.0 ] IDE: Arduino IDE version: 1.8.19 ESP32 core : 2.0.3 Board type: ESP32 DEV BOARD Additional modules: none Server : 0.41.17

Scenario, steps to reproduce

This is a Home automation board where we need to control relays using local server.

Expected Result

Actual Result

The initial connection is fine and shall work for around 30 mins to an hour.( this is totally random) After that we can see that the parameters are updated on mobile app like LCD, button colours etc from device side but when anything is triggered from mobile app like button action etc, the device won't respond. In-fact the Blynk.run() and Blynk.connected() always return true at that time. Also one more behaviour, if somehow Blynk get's disconnected from server, it won't connect again until and unless the device is reboot. This won't reconnect even if wifi is reconnected again. How to debug this issue? I have tried both Blynk library but same issue. The server version is 0.41.17

Main code:

include "Functions.h"

include "Configuration.h"

include

include

include

include

include

include

include "Variables.h"

include

include

include

include

Espalexa espalexa; WidgetLCD lcd(COMM_LCD); SimpleTimer blynk_timer;

void Device1callback(EspalexaDevice d); void Device2callback(EspalexaDevice d); void Device3callback(EspalexaDevice d); void Device4callback(EspalexaDevice d); void Device5callback(EspalexaDevice d); void Device6callback(EspalexaDevice d); void setup() { init_gpio(); init_pheripherals();

init_wifi_events();

//write_defaults();
//init_config_server();

load_config();
init_switches();
rtos_init_switch_loop();
rtos_init_wifi_connection();
Blynk.config(auth, IPAddress(blynk_ip_int[0], blynk_ip_int[1], blynk_ip_int[2], blynk_ip_int[3]), 8080);
Blynk.connect(2000);
DBGSERIAL.println("Setup done");
init_ota();

//add alexa devices changne name of devices
espalexa.addDevice(dev1_name, Device1callback, EspalexaDeviceType::onoff, 0);
espalexa.addDevice(dev2_name, Device2callback, EspalexaDeviceType::onoff, 0);
espalexa.addDevice(dev3_name, Device3callback, EspalexaDeviceType::onoff, 0);
espalexa.addDevice(dev4_name, Device4callback, EspalexaDeviceType::onoff, 0);
espalexa.addDevice(dev5_name, Device5callback, EspalexaDeviceType::onoff, 0);
espalexa.addDevice(dev6_name, Device6callback, EspalexaDeviceType::onoff, 0);
espalexa.begin();
//add alexa devices end

}

void loop() {

if (wifi_connected==1)
{
    if(Blynk.run()==0)Blynk.connect(2000);
    ota_loop();
    espalexa.loop();
}

}

RTOS thread which calls below function infinite:

void wifi_try_connect() { if(wifi_connected==0) { DBGSERIAL.println("WiFi not connected!"); switch(wifi_try) { case 1: { if (strlen(ssid0) > 1) { DBGSERIAL.println("Connecting ssid 1"); //Blynk.begin(auth, ssid0, passwd0, IPAddress(blynk_ip_int[0], blynk_ip_int[1], blynk_ip_int[2], blynk_ip_int[3]), 8080); WiFi.begin(ssid0, passwd0); delay(5000); wifi_try = 2; }

            else
            {
                DBGSERIAL.println("Blank ssid 1");
                wifi_try = 2;
                wifi_try_connect();
            }

        }break;
        case 2:
        {
            if (strlen(ssid1) > 1)
            {
                DBGSERIAL.println("Connecting ssid 2");
                //Blynk.begin(auth, ssid1, passwd1, IPAddress(blynk_ip_int[0], blynk_ip_int[1], blynk_ip_int[2], blynk_ip_int[3]), 8080);
                WiFi.begin(ssid1, passwd1);
                delay(5000);
                wifi_try = 3;
            }
            else
            {
                DBGSERIAL.println("Blank ssid 2");
                wifi_try = 3;
                wifi_try_connect();
            }

        }break;
        case 3:
        {
            if (strlen(ssid2) > 1)
            {
                DBGSERIAL.println("Connecting ssid 3");
                //Blynk.begin(auth, ssid2, passwd2, IPAddress(blynk_ip_int[0], blynk_ip_int[1], blynk_ip_int[2], blynk_ip_int[3]), 8080);
                WiFi.begin(ssid2, passwd2);
                delay(5000);
                wifi_try = 4;
            }
            else
            {
                DBGSERIAL.println("Blank ssid 3");
                wifi_try = 4;
                wifi_try_connect();
            }

        }break;
        case 4:
        {
            if (strlen(ssid3) > 1)
            {
                DBGSERIAL.println("Connecting ssid 4");
                //Blynk.begin(auth, ssid3, passwd3, IPAddress(blynk_ip_int[0], blynk_ip_int[1], blynk_ip_int[2], blynk_ip_int[3]), 8080);
                WiFi.begin(ssid3, passwd3);
                delay(5000);
                wifi_try = 1;
            }
            else
            {
                DBGSERIAL.println("Blank ssid 4");
                wifi_try = 1;
                wifi_try_connect();
            }
        }break;
    }
}
else
{
    static uint8_t err = 0;
    if (Blynk.connected()!= Blynk.CONNECTED)
    {
        err++;
        DBGSERIAL.println("Attempting to connect to Blynk");
        //Blynk.disconnect();
        Blynk.connect(10000);
        Blynk.run();
        if (err > 5)
        {
            err = 0;
            WiFi.disconnect();
            wifi_connected = 0;
        }
    }
    else
    {
        err = 0;
        DBGSERIAL.println("Wifi & Blynk connected");
        delay(5000);
    }

}

}

General Logs:

rst:0xc (SW_CPU_RESET),boot:0x1a (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff0030,len:1184 load:0x40078000,len:12812 load:0x40080400,len:3032 entry 0x400805e4 10:33:38:871 -> Processor booting.. Disconnected from WiFi access point- default 10:33:39:001 -> Disconnected from WiFi access point- default Wifi mac: C8:2B:96:BF: Disconnected from WiFi access point- default 10:33:39:124 -> mounted file system reading config file opened config file {"ssid0":"Soni_wifi2G","passwd0":"mitalirohit","ssid1":"","passwd1":"","ssid2":"","passwd2":"","ssid3":"","passwd3":"","ipaddr":"192.168.0.106","auth":"gZreUAf0hPSuWP0UpMcytDkMmjzlIIOc","dev1":"Device1","dev2":"Device2","dev3":"Device3","dev4":"Device4","dev5":"Device5","dev6":"Device6"} parsed json SSID0:Soni_wifi2G Passwd0:mitalirohit SSID1: Passwd1: SSID2: Passwd2: SSID3: Passwd3: Blynk Server:192.168.0.106 Blynk auth:gZreUAf0hPSuWP0UpMcytDkMmjzlIIOc Device 1 name:Device1 Device 2 name:Device2 Device 3 name:Device3 Device 4 name:Device4 Device 5 name:Device5 Device 6 name:Device6 WiFi not connected! Connecting ssid 1 [341]


/ )/ / _ / /_ / / / // / \/ '/ ///_, /////_\ /___/ v0.6.1 on ESP32

[362] Connecting to 192.168.0.106 10:33:39:255 -> Connected to access point Disconnected from WiFi access point 10:33:42:133 -> Setup done mDNS responder started 10:33:42:583 -> Obtained IP address: 192.168.0.12 10:33:44:153 -> Attempting to connect to Blynk [5363] Connecting to 192.168.0.106 [5363] Connecting to 192.168.0.106 10:33:44:280 -> [5451] Ready (ping: 24ms). Blynk Sync all 10:33:49:309 -> [10496] Connecting to 192.168.0.106 [10497] Connecting to 192.168.0.106 10:33:49:656 -> [10881] Ready (ping: 353ms). Blynk Sync all Wifi & Blynk connected 10:34:18:936 -> Wifi & Blynk connected Wifi & Blynk connected Wifi & Blynk connected Wifi & Blynk connected Wifi & Blynk connected 10:34:19:761 -> Wifi & Blynk connected 10:34:24:705 -> Wifi & Blynk connected 10:34:29:763 -> Wifi & Blynk connected 10:34:34:742 -> Wifi & Blynk connected 10:34:39:774 -> Wifi & Blynk connected 10:34:44:777 -> Wifi & Blynk connected 10:34:49:699 -> Wifi & Blynk connected 10:34:54:751 -> Wifi & Blynk connected 10:34:59:712 -> Wifi & Blynk connected 10:35:04:701 -> Wifi & Blynk connected 10:35:09:685 -> Wifi & Blynk connected 10:35:14:721 -> Wifi & Blynk connected 10:35:19:735 -> Wifi & Blynk connected 10:35:24:696 -> Wifi & Blynk connected 10:35:29:764 -> Wifi & Blynk connected 10:35:34:781 -> Wifi & Blynk connected 10:35:39:754 -> Wifi & Blynk connected 10:35:44:760 -> Wifi & Blynk connected 10:35:49:760 -> Wifi & Blynk connected 10:35:54:763 -> Wifi & Blynk connected 10:35:59:753 -> Wifi & Blynk connected 10:36:04:681 -> Wifi & Blynk connected 10:36:09:737 -> Wifi & Blynk connected 10:36:14:777 -> Wifi & Blynk connected 10:36:19:700 -> Wifi & Blynk connected 10:36:24:787 -> Wifi & Blynk connected 10:36:29:738 -> Wifi & Blynk connected 08:44:04:640 -> Wifi & Blynk connected

Blynk disconnected logs: 09:30:32:900 -> Attempting to connect to Blynk 09:30:42:890 -> Attempting to connect to Blynk 09:30:52:917 -> Attempting to connect to Blynk 09:31:02:865 -> WiFi not connected! Blank ssid 2 WiFi not connected! Blank ssid 3 WiFi not connected! Blank ssid 4 WiFi not connected! Connecting ssid 1Disconnected from WiFi access point

09:31:03:004 -> Connected to access point Disconnected from WiFi access point Obtained IP address: 192.168.0.101 09:31:07:958 -> Attempting to connect to Blynk 09:31:17:908 -> Attempting to connect to Blynk 09:31:27:880 -> Attempting to connect to Blynk 09:31:37:885 -> Attempting to connect to Blynk 09:31:48:582 -> Attempting to connect to Blynk 09:31:58:429 -> Attempting to connect to Blynk

sonirohit3 commented 1 year ago

Hi All, Any help on this is highly appreciated .

vshymanskyy commented 1 year ago

Please use Blynk Community for such questions. Thanks!