Slider Widget keeps resetting to 0 on Android only

You have pin 3 in your ESP code.

You canā€™t have an int of 0.3 and you canā€™t currently use floatā€™s in the slider for Android.

Hi @Costas

Ok so I have changed this back to a float vrbl (i was experimenting with the int for this to see if it made any difference - it didnt) but why is this relevant to the slider? the slider is on V29 ?

Cheers

kev

@newdos Iā€™m just pointing out some of the bugs in your code.

Declaring an int at 0.3 means the variable will always be 0 (significant number for you) and therefore your Hysteresis will not be working.

Trying to use pins that are not externally exposed on an ESP (pin 3 in your sketch) is very bad form as there is always a chance that the ESP tries to access an internal pin setting etc.

You also have pin 9 declared which is another pin that is not externally exposed on an ESP.
DO NOT RUN YOUR SKETCH ON AN ESP UNTIL YOU HAVE CHANGED IT.

Edit: pin 3 is actually exposed on an ESP but itā€™s actually the UART Rx pin and normally avoided.

Pins 6 to 11 are not exposed on most ESPā€™s but I believe there are a few boards that make some of these pins available. Interesting article on what can happen if you accidentally select pin 9 (as per your sketch) https://www.letscontrolit.com/forum/viewtopic.php?t=1462

Hi @Costas

Ok all taken on board. I will modify sketch to use different pins to see if it makes any difference then I will com back to you and let you know the outcome

Cheers

kev

Hi Guys,

Still trying to get to the bottom of this and I have now narrowed it down to a loop in my code that I cant see why it would affect the sliders on V29 and V28. It is this loop that causes the sliders to jump to zero but only on android - void sendStatus - shown below. If I donā€™t call this loop the sliders works fine. Full code is further up the thread if required.

I cannot see anything wrong with this loop so a little baffled at the moment - hoping extra pairs of eyes can tell me why this loop is causing this ?

Cheers

kev

void sendStatus()
{
  // has Arduino been reset or just started.
  if (resetFlag == true && year() != 1970)
  {
    resetTimeDate = currentTimeDate;
    Blynk.virtualWrite(V31, currentStatus);
    Blynk.setProperty(V31, "label", String("Current Status:                    SYSTEM RESET at ") + resetTimeDate);
  }

  if (Heat1_Status == 1 && resetFlag == true)   // Runs once following reset/start if Heat is ON.
  {
    startFlag = true;
    resetFlag = false;
  }
  else if (Heat1_Status == 0 && resetFlag == true) // Runs once following Arduino reset/start if heat is OFF.
  {
    stopFlag = true;
    resetFlag = false;
  }

  // Display all the data on the app
  // Have we passed threshold of heat limit? if so turn it off
  if (digitalRead(Heat1_pin) == 1 && startFlag == true) // now OFF, but was on
  {
    // Purpose: To swap between ON and OFF display once heating state change.
    stopTimeDate = currentTimeDate;                                   // Set off time.
    Blynk.setProperty(V31, "color", "#23C48E");   // Green
    Blynk.virtualWrite(V31, String("Heat OFF since ") + stopTimeDate); // Write to app.
    currentStatus = String("Heat OFF since ") + stopTimeDate;
    stopFlag = true;   // Ready flag when heat turns on.
    startFlag = false;// Keep everything locked out until the next cycle.
  }
  else if (digitalRead(Heat1_pin) == 0 && stopFlag == true) // ON, but was off
  {
    startTimeDate = currentTimeDate;
    Blynk.setProperty(V31, "color", "#D3435C");   // Red
    Blynk.virtualWrite(V31, String("Heat ON since ") + startTimeDate);
    currentStatus = String("Heat ON since ") + startTimeDate;
    startFlag = true;
    stopFlag = false;
  }
  
}

@newdos I would try deleting V28 to V31 in your project and recreating the widgets in case the system has got confused what virtual pins you selected. After deleting them, logout, turn phone off and then start again with those 4 pins.

OK @Costas will try that and come back to you

Cheers

kev

Hi @Costas

Now I have logged out of the blynk app on my phone I cannot get logged back in. This goes back to the email issues I was having. The app actual says my email address which is my login is not in the blynk database!!! - how can this be ???

Can someone look at this please as itā€™s doing my head in !!!

Cheers

kev

Hi @Costas think my iphone app was screwed so deleted it and reinstalled it and it has let me back in with my original ID and password so ignore last message.

Cheers

Kev

Hi @Costas,

Ok done what you said and even had to delete the app because of login screw ups. I have now rebuild the widgets and it is exactly the same - works fine on ios but still jumps to zero on android

Over to you!

Cheers

kev

@newdos until I have chance to study all the code in detail can you try and isolate the problem further i.e. comment out some of the if and else parts of the problem section.

Will do @Costas that was my next plan anyway

Will let you know if I find anything further.

Cheers

kev

Hi @Costas,

Not getting much further with this - It is not just the loop I thought it was it is any of them. ie if the simpletimer calls any loop as you are dragging the slider it jumps to zero. I have proven that the more frequently the loop is called the more the slider will do it so my loop that is called every 200 milliseconds really screws it up.

I even commented out the blynk_write(V29) code (my slider in question) to see if it was interaction with this call and the timer, and that proved it was the timer alone, as the slider still did it.

Would you consider this as a bug as it doesnā€™t do this in ios and consider a fix, or am I going to have try and work the code with simpletimer in a different fashion (havenā€™t a clue how though!!)?

Cheers

kev

@newdos perhaps go back to one of your earlier basic sketches that was working ok and add a 200ms timer to see if that indicates a Blynk bug.

I know Blynk have recently done some work with SimpleTimer and I think the minimum setting is now 10ms.

I have to say that the Slider widget is very popular and we are not seeing reports from others of the issue you have. That said most people will not have a 200ms timer in their project.

OK @Costas I will look at that an report back.

Meanwhile I also just had a thought - I note the actual Blynktimer states in the docs that it fixes some issues for use with Blynk. Might it be worth trying this library to see if works with the slider ?

Cheers

kev

I was just going to say upgrade to 0.4.7 if you havenā€™t already.

If you are using latest Blynk library, you are automatically using BlynkTimer.

@Gunner, @Costas

Ah ok guys guess thatā€™s not going to make any difference then as I am already on v0.4.7. So even though I use simpletimer itā€™s automatically using blynktimer correct ?

Cheers

kev

Hi @Costas, @Gunner

Think I have found the cause. It seems to be caused by calling a void from a timer that has a virtualwrite within the loop

here is a cut down version of the code that runs on arduino

#include<SimpleTimer.h>
SimpleTimer timer;
int feedback1;            // AC feedback1 variable
int SetPoint1;            // Temp setting for room monitored by DHT22
int AC_Sens1_pin = 3;     // Relay 1 ac sens pin
char auth[] = "xxx";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth);

  //Lets sync up all the store states for the V pins and load the appropriate variables listed below
  Blynk.syncVirtual(V29);            // SetPoint1
  timer.setInterval(200, AC_detect); // Check if the room is occupied via PIR sensor
}

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

void AC_detect()
{
  feedback1 = digitalRead(AC_Sens1_pin);
  Blynk.virtualWrite(V2, feedback1); // update SWITCH widget state from AC input only if it has changed
}

BLYNK_WRITE(V29)  // Input from slider in app to set SetPoint1
{
  SetPoint1 = param.asInt();
  Serial.println(SetPoint1);
}

If you comment out the line in the AC_detect void that has the Blynk.virtualwrite in it, the slider works fine, put that line back in and it jumps around all over the place!!

I have also tried this with another loop not called so often ie every second - and if it has the virtualwrite in it, it screws up - take it out and its fine

So, I am hoping you guys will accept this a bug (unless you tell me otherwise!!)

Cheers

kev