Defer Writes

For those interested, here is what I am seeing. about 175ms for one call, and 1.7s for 10 (10 before another blynk.run()).

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example runs directly on ESP8266 chip.

  Note: This requires ESP8266 support package:
    https://github.com/esp8266/Arduino

  Please be sure to select the right ESP8266 module
  in the Tools -> Board menu!

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

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


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***";
char pass[] = "***";
char server[]= "***";

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

  Blynk.begin(auth, ssid, pass, server, 8442);
}
bool value = false;
void myTask(void){
  Blynk.virtualWrite(V1, value);
  value = !value;
}

unsigned int t0, t1;

unsigned int process_time = 0;


void loop()
{

  t0 = micros();
  myTask();
  process_time = micros() - t0; 
  Blynk.run();

  Serial.println(process_time);
  yield();
}

DO NOT USE THAT WITH BLYNK.

guys, i do not know how you’re calculating, but for me, 0.15 ms X 128 is 19.2 ms, not 19.2 sec!

For the record, its 150ms * 128 writes = 19.2 seconds…

Anyway. 2.4.0rc2 gives about 60-75ms per write; about 3 times better than 2.3.0

Edit:

increasing the message limit (#define BLYNK_MSG_LIMIT 100) reduces the delay in the blynk calls. I can reliably get 10ms updates now. Please do not do this unless you’re on a private server.

@BoogaBooga unless version 0.5.0 has changed the message limit then Blynk’s cloud server can in theory handle 100 messages per second. That is if the hardware you are using can handle it but an ESP with 2.3.0 core can’t and requires 2.4.0-rc2.

What are you trying to do that needs so many virtualWrite() calls?

@Costas

I also increased the limit on the server side (default is 100 messages/second, as you said). Not that you’d be able to reach their default limit anyway.

Its not so much needing that many writes, my current application has about a dozen. What caught me off guard is the amount of delay required to service such a small pay load. I was using a timer of 1 second (not unreasonable IMO) and it was executing less frequent than that. Granted that this was made worse by 2.3.0 (which is still the ‘latest’ release :confused:)

I understand why they implemented the rate limit but I think its a poor implementation. Its just sitting there burning CPU cycles making the entire program slow; and I am not sure that this behavior is documented (other than ‘we fixed the flood error’).

Anyway, thanks for the help.

Let me remind you that the library is open-source and you’re free to adjust it to your needs.

2 Likes