[Solved] Problem WidgetLED and Color Property

Hi,

from several days I notice a strange behavior for WidgetLed color property.

Closing Blynk app, at reopening, if led are ON, color changes without no setProperty calls in meantime (if led are OFF nothing happen to this led), many days ago it did not happen and code, for this managment, in hardware side, is not changed.
On no call to setProperty I’m sure because nothing is print on SerialMonitor and nothing changes on Hardware side (no relay ON/OFF and no button pressed), at app reopening no new print in SerialMonitor is reported.

Problem appear to be independent from library version (checked with 0.4.0, 0.4.2 and 0.4.3 versions) and from last APKs (2.0.3, 2.0.5 and 2.1 versions).

Here is the code that deals with WidgetLed management and synchronization (I reduce code and remove unnecessary part to make it more readable):

  • main
        BLYNK_ATTACH_WIDGET(rtc, V99);

        BLYNK_CONNECTED() {	
        	if (isFirstConnect) {
        		isFirstConnect = false;

        		/* all firsts synchronization	*/
        	}
        }

        void syncLED() {
        	SyncSmartphone *sync = SyncSmartphone::istanza();
        	
        	WidgetLED ledRaffreddamento(V4);
        	if (sync->led[LED_RAFFREDDAMENTO].syncColore) {
        		Blynk.setProperty(V4, "color", sync->led[LED_RAFFREDDAMENTO].colore);
        		sync->led[LED_RAFFREDDAMENTO].syncColore = false;
        #ifdef ENABLE_SERIAL_LOG
        		Tools::stampaOrario();
        		Serial.println(F("BLYNK - LED_RAFFREDDAMENTO - syncColore"));
        #endif
        	}
        	if (sync->led[LED_RAFFREDDAMENTO].syncStato) {
        		sync->led[LED_RAFFREDDAMENTO].acceso ? ledRaffreddamento.on() : ledRaffreddamento.off();
        		sync->led[LED_RAFFREDDAMENTO].syncStato = false;
        #ifdef ENABLE_SERIAL_LOG
        		Tools::stampaOrario();
        		Serial.println(F("BLYNK - LED_RAFFREDDAMENTO - syncStato"));
        #endif
        	}

        	WidgetLED ledRiscaldamento(V6);
        	if (sync->led[LED_RISCALDAMENTO].syncColore) {
        		Blynk.setProperty(V6, "color", sync->led[LED_RISCALDAMENTO].colore);
        		sync->led[LED_RISCALDAMENTO].syncColore = false;
        #ifdef ENABLE_SERIAL_LOG
        		Tools::stampaOrario();
        		Serial.println(F("BLYNK - LED_RISCALDAMENTO - syncColore"));
        #endif
        	}
        	if (sync->led[LED_RISCALDAMENTO].syncStato) {
        		sync->led[LED_RISCALDAMENTO].acceso ? ledRiscaldamento.on() : ledRiscaldamento.off();
        		sync->led[LED_RISCALDAMENTO].syncStato = false;
        #ifdef ENABLE_SERIAL_LOG
        		Tools::stampaOrario();
        		Serial.println(F("BLYNK - LED_RISCALDAMENTO - syncStato"));
        #endif
        	}

        	WidgetLED ledSkimmer(V7);
        	if (sync->led[LED_SKIMMER].syncColore) {
        		Blynk.setProperty(V7, "color", sync->led[LED_SKIMMER].colore);
        		sync->led[LED_SKIMMER].syncColore = false;
        #ifdef ENABLE_SERIAL_LOG
        		Tools::stampaOrario();
        		Serial.println(F("BLYNK - LED_SKIMMER - syncColore"));
        #endif
        	}
        	if (sync->led[LED_SKIMMER].syncStato) {
        		sync->led[LED_SKIMMER].acceso ? ledSkimmer.on() : ledSkimmer.off();
        		sync->led[LED_SKIMMER].syncStato = false;
        #ifdef ENABLE_SERIAL_LOG
        		Tools::stampaOrario();
        		Serial.println(F("BLYNK - LED_SKIMMER - syncStato"));
        #endif
        	}
        	
        	/* other LEDs synch (managed in same way) */
        }


        void setup() {
        #if defined(ENABLE_SERIAL_LOG) // || defined(DEBUG)
        	Serial.begin(ESP8266_BAUD);
        #endif

        	connected = false;
        	tReconnect = millis();
        	isFirstConnect = true;

        	/* 	init for all sensors, relay, RTC, etc. */

        	EspSerial.begin(ESP8266_BAUD);

        	delay(100);

        	Blynk.config(wifi, BLYNK_AUTH, BLYNK_IP, BLYNK_PORT);
        	Blynk.connectWiFi(BLYNK_SSID, BLYNK_PWD);
        	Blynk.connect();
        	
        	timer.setInterval(500, syncLED);
        	timer.setInterval(1100, syncTemperature);
        	timer.setInterval(2400, syncLivelli);
        	timer.setInterval(3700, syncLivelliLow);
        	timer.setInterval(5800, syncAltro);
        	timer.setInterval(1800000, syncRTC);
        }


        void loop() {
        		/* management functions for all sensors, relay, RTC, etc. (all without delay)	*/

        	SyncSmartphone::istanza()->gestione(temperaturaAcquario, temperaturaCambio);
        	SyncSmartphone::istanza()->riconnetti();

        	if (Blynk.connected()) {
        		Blynk.run();

        		if (!connected) {
        			connected = true;
        			rtc.begin();
        			setSyncInterval(1800);
        		}
        		timer.run();
        	}
        	else {
        		if (connected) {
        			connected = false;
        			tReconnect = millis();
        		}
        	}
        }
  • SyncSmartphone.h
    #define BLYNK_GREEN     "#23C48E"
    #define BLYNK_BLUE      "#04C0F8"
    #define BLYNK_YELLOW    "#ED9D00"
    #define BLYNK_RED       "#D3435C"
    #define BLYNK_DARK_BLUE "#5F7CD8"
    #define BLYNK_ORANGE		"#FF6600"

    struct Led {
    	Led() {
    		syncColore = true;
    		syncStato = true;
    		acceso = false;
    		colore = BLYNK_RED;
    	}

    	bool	syncStato, syncColore;
    	char*	colore;
    	bool	acceso;
    };
  • SyncSmartphone.cpp
    void SyncSmartphone::riconnetti() {
    	if (!Blynk.connected()) {
    			if(millis() - tReconnect > 20000) {
    				wifi.restart();	
    				delay(1000);

    				Blynk.connectWiFi(BLYNK_SSID, BLYNK_PWD);
    				Blynk.connect();
    		}
    	}
    }

    void SyncSmartphone::gestione() {
    	verificaLed(LED_RAFFREDDAMENTO, ModuloRele::istanza()->raffreddamento, 	Attrezzatura::istanza()->interruttori[Attrezzatura::istanza()->ventole]);
    	verificaLed(LED_RISCALDAMENTO, 	ModuloRele::istanza()->riscaldatore, 		Attrezzatura::istanza()->interruttori[Attrezzatura::istanza()->riscaldatore]);
    	verificaLed(LED_SKIMMER, 				ModuloRele::istanza()->skimmer, 				Attrezzatura::istanza()->interruttori[Attrezzatura::istanza()->skimmer]);
    }


    void SyncSmartphone::verificaLed(uint8_t idLed, uint8_t idRelay, bool interruttore) {
    	if ((led[idLed].acceso && !interruttore) || (!led[idLed].acceso && interruttore)) {
    		led[idLed].acceso = !led[idLed].acceso;
    		led[idLed].syncStato = true;
    	}

    	if (ModuloRele::istanza()->rele[idRelay].acceso) {
    		if (strcmp(led[idLed].colore, BLYNK_GREEN) != 0) {
    			led[idLed].colore = BLYNK_GREEN;
    			led[idLed].syncColore = true;
    		}
    	}
    	else {
    		if (strcmp(led[idLed].colore, BLYNK_RED) != 0) {
    			led[idLed].colore = BLYNK_RED;
    			led[idLed].syncColore = true;
    		}
    	}
    }

I can’t find anything wrong, do you see something wrong?
Any advise?

Thanks.

To try to explain better attach two screenshots, I start from following situation (for example):

(STEP1)

If I close Blynk App at reopening I get GREEN led:

(STEP2)

but I’m sure that between STEP1 and STEP2 no setProperty or sync related to this LED was sent.

I try also with Blynk App clean data or removing/re-adding LED, but unsuccessfully.

So you have debug output that shows that?

Hi,

if you means BLYNK Debug no, I use mine Debug (ENABLE_SERIAL_LOG), in previous code, in no other points are used virtual pin of WidgetLed.

ASAP I try with Blynk Debug mode Active and I’ll provide you logs.

Thanks!

@Aro1do no need. I reproduced your issue. We will try to fix it ASAP.

Great! Thanks! I love your app and your work! :slight_smile:

With today updates issue was fixed!

Thanks for support! :slight_smile: