App not updating

hello !

I have a simple sync physical button running on nodemcu.
Everything seems to work fine, when the physical button is pressed it reflects on the app and vice versa .
But when i force close the app (ios) and press the physical button , the state will not be updated or synced to the app.
And if i press the physical button fast enough like one press per 2 seconds then it works for couple of push and later the app will not update the state of the button.

And can anyone please provide the bits that is responsible the connection and reconnection part !?
I want this very badly, I found quite a few in the forum but i am using the same technique and failing .

Assuming that you’re not using Bluetooth/BLE, the Blynk server is updated with the state of the button regardless of whether or not the app is running on a mobile device. When the app is launched on the mobile device then the app will get the current button state from the server and display the correct status, which will be the same as your device assuming that you had an internet/Blynk connection the last time you changed the status of the button on the device.

Are you running the Sync Physical Button example from Sketch Builder?
If so, what device are you running it on, and which physical pins have you chosen for the button and LED?

Pete.

NOPE !! I am using nodemcu as mentioned above.

This ain’t happening. That is what i am facing issue with

Yes from the sketch builder.

D6 = SW
D5 = LED

But i have used the same pins previously in many nodemcu’s and they work fine. only from past couple of weeks the app is not working as you mentioned above.

And i am using local server. Is it something to do with that ?? :roll_eyes:

It’s obviously possible to connect to a NodeMCU via Bluetooth/BLE with some additional hardware, which is why I raised the issue.

It obviously shouldn’t, but if you’re using the sketch builder sketch, which works fine with the Blynk cloud server and iOS (when you change the pins used by the switch and LED) the you probably have an issue with your setup.
The simple solution is to create a Blynk cloud account and test the same sketch with that.

Pete.

This is a new thing for me. Thanks for telling me about this…

I am using Blynk for quite a while now, and from this forum i have learnt quite a bit. So i don’t feel that the pins i am using may cause the issue.

I will try this out and keep it posted…

1 Like

I tested the sample code, with some minor modification (using local Blynk Server, and different pins for NodeMCU).
I haven’t found any problem as you described :

  1. But when i force close the app (ios) and press the physical button , the state will not be updated or synced to the app.

I tested and everything is OK:
a) Press physical button, see VPIN status and LED changed on APP, iOS Version 2.26.1 (9)
b) Close iOS APP
c) Press physical button, see VPIN status and LED changed on APP
d) Open APP, the button is changed according to physical button pressed (how many times) and LED status.

  1. And if i press the physical button fast enough like one press per 2 seconds then it works for couple of push and later the app will not update the state of the button.

Again, I pressed the physical button repetitively (faster than once per 2s) and the VPIN button is responding correctly for quite a while.

So, I guess your Network / Router / Blynk Local Server (settings) are creating the issue:

  1. the TCP packets are somehow dropped on the way to Blynk Local Server and not being resent. Therefore creating issue 2 => issue 1. Low possibility.
  2. The Blynk Local Server load was too high then and it couldn’t handle / ignore the packets / clients ?? Issue 2 and /or issue 1. Medium possibility.
  1. The Blynk Local Server default settings can limit certain number of msgs to be sent/received for clients. It can drop packets in that situation => issue 2 => issue 1. High possibility.
  2. Your ISP (if you use DDNS service) / Router / etc. can drop packets and we can’t control and know where and when. Low possibility.

It’s a little bit strange to me. If reliable TCP/IP (not UDP/IP) protocol is used, the TCP/IP sender will automatically resend packets if previous packets were lost / dropped. Certainly it depends on how the TCP/IP stack was implemented in ESP8266 core and if it’s really reliable or not !!!. We don’t know yet.

So my best guess now is that the Blynk Local Server is the culprit.

What kind of Local Server are you using (RPi, PC, RPi Zero W, etc…)?

If possible, you can try using the same code as I do and see if the issue persists or not.

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#define USE_BLYNK_WM      false   //true

#include <ESP8266WiFi.h>

#if USE_BLYNK_WM  
  #include <BlynkSimpleEsp8266_WM.h>
#else
  #include <BlynkSimpleEsp8266.h>
#endif

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

#define PIN_LED           2         // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266, NodeMCU and WeMoS, control on-board LED
#define PIN_D3            0         // Pin D3 mapped to pin GPIO0/FLASH of ESP8266

// Set your LED and physical button pins here
const int ledPin = PIN_LED;   //D5;        //7;
const int btnPin = PIN_D3;    //D6;        //8;

#define BLYNK_BUTTON_PIN        V6

BlynkTimer timer;
void checkPhysicalButton();

int ledState = LOW;
int btnState = HIGH;

// Every time we connect to the cloud...
BLYNK_CONNECTED() 
{
  // Request the latest state from the server
  Blynk.syncVirtual(BLYNK_BUTTON_PIN);

  // Alternatively, you could override server state using:
  //Blynk.virtualWrite(BLYNK_BUTTON_PIN, ledState);
}

// When App button is pushed - switch the state
BLYNK_WRITE(BLYNK_BUTTON_PIN) 
{
  ledState = param.asInt();
  digitalWrite(ledPin, ledState);
}

void checkPhysicalButton()
{
  if (digitalRead(btnPin) == LOW) 
  {
    // btnState is used to avoid sequential toggles
    if (btnState != LOW) 
    {
      // Toggle LED state
      ledState = !ledState;
      digitalWrite(ledPin, ledState);

      // Update Button Widget
      Blynk.virtualWrite(BLYNK_BUTTON_PIN, ledState);
    }
    
    btnState = LOW;
  } 
  else 
  {
    btnState = HIGH;
  }
}

void setup()
{
  // Debug console
  Serial.begin(115200);
  Serial.println("\nStarting");
  
  pinMode(ledPin, OUTPUT);
  pinMode(btnPin, INPUT_PULLUP);
  digitalWrite(ledPin, ledState);
  
#if USE_BLYNK_WM  
  Blynk.begin();
#else
  Blynk.begin(auth);
#endif

  // Setup a function to be called every 100 ms
  timer.setInterval(100L, checkPhysicalButton);
}

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

You can also try modifying server.properties to the extreme as follows to see if it’s better.

...
#maximum number of tags allowed per account
user.tags.limit=1000

#defines maximum allowed number of user dashboards. Needed to limit possible number of tokens.
user.dashboard.max.limit=400

#defines maximum allowed widget size in KBs as json string.
user.widget.max.size.limit=200

#user is limited with 100 messages per second.
user.message.quota.limit=100

#maximum allowed number of notification queue. Queue responsible for processing email, pushes, twits sending.
#Because of performance issue - those queue is processed in separate thread, this is required due
#to blocking nature of all above operations. Usually limit shouldn't be reached.
notifications.queue.limit=2000

#Number of threads for performing blocking operations - push, twits, emails, db queries.
#Recommended to hold this value low unless you have to perform a lot of blocking operations.
blocking.processor.thread.pool.limit=12

#this setting defines how often we can send mail/tweet/push or any other notification. Specified in seconds
notifications.frequency.user.quota.limit=2

#this setting defines how often we can send webhooks. Specified in miliseconds
webhooks.frequency.user.quota.limit=1000

#this setting defines how big could be response for webhook GET request. Specified in kbs
webhooks.response.size.limit=72

#maximum size of user profile in kb's
user.profile.max.size=2048

#number of strings to store in terminal widget
terminal.strings.pool.size=25

#number of strings to store in map widget
map.strings.pool.size=25

#number of strings to store in lcd widget
lcd.strings.pool.size=6

#maximum number of rows allowed
table.rows.pool.size=100

#period in millis for saving all user DB to disk.
profile.save.worker.period=60000

#period in millis for saving stats to disk.
stats.print.worker.period=60000

#max size of web request in bytes, 256 kb (256x1024) is default
web.request.max.size=524288

#maximum number of points that are fetched during CSV export
#43200 == 60 * 24 * 30 - minutes points for 1 month
csv.export.data.points.max=43200

#specifies maximum period of time when hardware socket could be idle. After which
#socket will be closed due to non activity. In seconds. Default value 15 if not provided.
#leave it empty for infinity timeout
hard.socket.idle.timeout=30

#enable DB
enable.db=false

#enable raw data storage to DB
enable.raw.db.data.store=false

#size of async logger ring buffer. should be increased for loads >2-3k req/sec
async.logger.ring.buffer.size=81920
....

@khoih Hello !!!
i am using the RPi Zero W… My old RPi3 was getting corrupted every often so i had a Zero W lying around. So i am running the server in that. May it has a very less processing power than RPi3.

And as Pete said to check on the cloud server witht the same code i was about to do the same, i felt before doing that let me check again and checked the same code and now it seems to work fine. Now i am going mad on whats happening !!! No loose wires, No changes made in the code, Internet is fast (70Mbps) downloaded few softwares and videos they downloaded pretty fast…

I have faced this issue previously too… Everything will be working fine. And after few weeks if i try to do the same with the other module or replicate it will either not compile or act weird once uploaded !!

I will do this as soon as i reach back home.

1 Like

Hi @Madhukesh

  1. My old RPi3 was getting corrupted every often
    It might be just the bad microSD card. Buy a new and good one to replace. Then run the Local server on RPi3.
  2. I am using the RPi Zero W… May it has a very less processing power than RPi3.
    I think this is the case of much less processing power. I tested several RPi Zero (W) long before and had to throw them all away.
  3. I have faced this issue previously too… Everything will be working fine. And after few weeks if i try to do the same with the other module or replicate it will either not compile or act weird once uploaded !!

Maybe you’re running development platform on unreliable Windows. If so, try to switch to Ubuntu or similar Linux-based OS and see it’ll be much more reliable, faster and more powerful, even on the same old PC.

:cold_sweat: I have paid for junk :man_facepalming:

Yes !! i am on Windows 8.1
I have never used Ubuntu !!
I guess i need to start learning Ubuntu or linux based once !!
Time to quit Windows !!

1 Like
  1. :cold_sweat: I have paid for junk :man_facepalming:
    Me too and learnt something.
  2. I guess i need to start learning Ubuntu or linux based once !!
    You’ll see your effort will be worth a fortune :slight_smile: . Learn once and Use for life.
1 Like