Problem with button colors staying set (after exiting a device and then returning)

On the iPhone app I use a Styled Button to show the color of a LED on my hardware. I set the button’s color in the firmware using the following Blynk.setProperty function

Blynk.setProperty(MYBUTTON_VPIN, "onBackColor", "#D3435C");
Blynk.setProperty(MYBUTTON_VPIN, "offBackColor", "#D3435C");

I’m able to set the button colors, but when I exit the device and then come back to it, the colors often revert back to the color that is set in the styled button widget’s settings (but sometimes my new color is still set to the last firmware setting).

Is there some way keep these colors set to the last set value?

Thanks,
Gary

Which iOS app version are you using?

@Eugene - one for you?

Pete.

Thanks, we’ll check

The about page in the app says version 3.4.1 (0)
I just downloaded the latest version from the app store which says 1.18
It shows the same intermittent behavior when opening a device (sometimes the colors will be correct and sometimes they revert back to the widget’s settings value).

Is this flagged as a known problem? I’m using colors on a LED to indicate warning and alarm states. When first opening the device after an alarm notification it shows the LED default color.

I did some testing and found that the device state was okay and the label was also okay, but the color does not show correctly until an update occurs:

.

and if you leave the device and return, it shows the widget default color until an update. Note that the device state and label are correct.

Using Blynk IoT iOS Version 3.4.6 (0)

Here is the simple snippet of code that I used for testing…

void TestLED()
{
  Blynk.virtualWrite(V1, 1);
 
  Blynk.setProperty(V1, "color", BLYNK_YELLOW);
  Blynk.setProperty(V1, "label", "YELLOW");
  delay(10000);
  
  Blynk.setProperty(V1, "color", BLYNK_RED);
  Blynk.setProperty(V1, "label", "RED");
  delay(10000);

  Blynk.virtualWrite(V1, 0);
  Blynk.setProperty(V1, "label", "OFF");  
  delay(5000);
}

Posting your whole sketch might help.

It’s not a good idea to use delay because it’s a blocking function. You should get rid of it.

Here is the total test sketch as suggested. Not much more since it is a modified example for testing only. Delays shouldn’t be normally used as John93 suggests, however in this test example, the program can be blocked since it has only 1 function.

I was really hoping someone from Blynk or Eugene of the iOS team would respond.

#define BLYNK_TEMPLATE_ID "REDACTED"
#define BLYNK_DEVICE_NAME "TestLED"
#define BLYNK_AUTH_TOKEN "REDACTED"


#define BLYNK_YELLOW    "ED9D00"
#define BLYNK_RED       "D3435C"

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266_SSL.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.
// WiFi credentials.
char ssid[] = "REDACTED";
char pass[] = "REDACTED";

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
  Serial.println( "Setup End reached...............");
}

void TestLED()
{
  Blynk.virtualWrite(V1, 1);
  
  Blynk.setProperty(V1, "color", BLYNK_YELLOW);
  Blynk.setProperty(V1, "label", "YELLOW");
  delay(10000);
  
  Blynk.setProperty(V1, "color", BLYNK_RED);
  Blynk.setProperty(V1, "label", "RED");
  delay(10000);

  Blynk.virtualWrite(V1, 0);
  Blynk.setProperty(V1, "label", "OFF");  
  delay(5000);
}

void loop()
{
  Blynk.run();
  TestLED();
}

Sounds like the color property is not stored on server.
@Oleksii-QA please reproduce and create internal ticket.

Hello, @jacko

You use wrong color format in code. Please use hex color with #
#define BLYNK_YELLOW "#ED9D00"
#define BLYNK_RED "#D3435C"

Regards

Thanks for the reply. The original reason the # hex was removed is that it throws an error when used with HTTP_API.
https://blynk.cloud/external/api/update/property?token=REDACTED&pin=v1&color=#D3435C
The error is: {“error”:{“message”:“No properties for update provided.”}}

Without the #, the color does update and there is no error shown, but the original problem occurs.

So how does one send the correct color property?

Thanks again

In sketch use # with color

Regards

Doesn’t work… Same original problem.

Works correctly as you pointed out in NORMAL NON-HTTP connection, but NOT if using HTTP API.

I think the language you’re using here is potentially somewhat confusing.

The syntax for the HTTP(S) REST API calls is totally different to the syntax used within a sketch when using the Blynk C++ library.

The two aren’t interchangeable, and when you’re using a C++ sketch the # symbol is required.

However, Eugene believes that the colour property isn’t being stored on the server, so it only takes effect when the property is updated and isn’t available to refresh the widget when the app is refreshed. This needs investigated and fixed, but once it is fixed the. You still need to be using the correct syntax in your sketch or API calls.

Pete.

Thanks Pete for the reply. I’ll try to make things a bit clearer. I do understand that there is a difference between using the Blynk app and the HTTP(S) REST API.

In the case of using Blynk sketch, Oleksii correctly identified my issue. The color requires “#” and this cleared up my problem for that scenario. The code used is “Blynk.setProperty(V1, “color”, BLYNK_RED)” where BLYNK_RED is “#D3435C” with # preceding the numeric value.

However when using HTTP (I used your example code), when sending color with the #, the server does not store it at all as shown on the datastream. When using without the #, the color is stored in the datastream without the # which causes display problems as detailed originally.

http://ny3.blynk.cloud/external/api/update/property?token=REDACTED&pin=v4&color=#D3435C

Note: color has no value.

http://ny3.blynk.cloud/external/api/update/property?token=REDACTED&pin=v4&color=ED9D00

Note: color has value with no “#”

Both the web console and the Blynk app do not show persistent color (as shown in screenshots previously).

I also tried an escape character proceeding the # ("#D3435C") to no avail. The Blynk server shows ""only.

I think I’m sending the data correctly formatted so my conclusion is that the Blynk server does not handle the color property correctly when sent via HTTP.

Jacko

1 Like

Hi,

Please, try:
http://ny3.blynk.cloud/external/api/update/property?token=REDACTED&pin=v4&color=%23ED9D00

Dmitriy from Blynk
blynk.io

Dimitry - thanks. Problem solved, colors now work as expected!

Jacko

2 Likes