Blynk is great! But my network is unstable

Blynk is great! But my network is unstable.
My APP connection Blynk is very difficult, the command issued by APP is always invalid.
For example, I use the buttons on the APP to control the small lights. I click on the button, need to wait for a long time to react or not respond. Can I connect to my own server to control? Or can Blynk optimize China’s connection to Blynk servers?

Poor responses are normally a result of poor sketches but based in China it might be a server issue.

Yes you can run you own server and there is loads of information available on setting one up. Almost any machine will do, even $5 “Pi’s”.

You might want to post your sketch to see if it is bad code that is giving you poor response times.

Thank you very much, how should I fix it?
Can I buy a server connection myself?
Or do you need me to help buy the server in China?

Can you tell me how to set up their own server, and connect to the blynk this APP, I like this APP very much~

Paste your results from the following console / terminal / Dos prompt command:

ping blynk-cloud.com

Is pinging blynk-cloud.com [188.166.206.43] with 32 bytes of data:
Response from 188.166.206.43: Bytes = 32 Times = 184ms TTL = 46
Request timed out.
From 188.166.206.43 reply: byte = 32 times = 196ms TTL = 46
Response from 188.166.206.43: Bytes = 32 Times = 186ms TTL = 46

Login statistics for 188.166.206.43:
Packet: sent = 4, received = 3, lost = 1 (25% lost),
Estimated time for round trip (in milliseconds):
The shortest = 184ms, the longest = 196ms, the average = 188ms

To the Blynk servers for Europe we get around 70ms but 188ms is not bad and should be fine for most projects.

What is more worrying is your 25%packet loss.

Try the following and let it run for perhaps a minute, then CTRL C and paste just the summary.

ping blynk-cloud.com -t

Login statistics for 188.166.206.43:
Packet: sent = 37, received = 37, lost = 0 (0% lost),
Estimated time for round trip (in milliseconds):
The shortest = 181ms, the longest = 271ms, the average = 192ms

The network looks no problem, it should be my program.

/*************************************************************
  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
    Blynk community:            http://community.blynk.cc
    Social networks:            http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

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

 *************************************************************

  You’ll need:
   - Blynk App (download from AppStore or Google Play)
   - Arduino UNO or similar microcontroller board
   - Decide how to connect Arduino to the Internet
     (USB, Ethernet, Wi-Fi, Bluetooth, ...)

  There is a bunch of great example sketches included to show you how to get
  started. Think of them as LEGO bricks  and combine them as you wish.
  For example, take the Ethernet Shield sketch and combine it with the
  Servo example, or choose a USB sketch and add a code from SendData
  example.
 *************************************************************/

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


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//#include <OneWire.h>
//#include <DallasTemperature.h>
//
#define ONE_WIRE_BUS D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

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

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

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

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
  sensors.begin();
}

void sendTemps()
{
  sensors.requestTemperatures(); // Polls the sensors

  float temp = sensors.getTempCByIndex(0); // Gets first probe on wire in lieu of by address

  Serial.println(temp);

  Blynk.virtualWrite(V1, temp);
}

void loop()
{
  Blynk.run();
  sendTemps();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

thank you very much for your help!

Spot on, your program is dreadful :slight_smile:

but only 99% of the time.

Do i need to add a delay function?

NEVER use delay() other than say 50ms.

You MUST use one of the six libraries you installed when you loaded Blynk, it is called SimpleTimer.

At the moment this:

void sendTemps()
{
  sensors.requestTemperatures(); // Polls the sensors

  float temp = sensors.getTempCByIndex(0); // Gets first probe on wire in lieu of by address

  Serial.println(temp);

  Blynk.virtualWrite(V1, temp);
}

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

says in loop() read the sensors a thousand times a second and then send the results to Blynk at the same speed. Some sensors can take 1 to 2 seconds to take their readings and Blynk couldn’t handle 1000 responses from you and 20,000+ other devices every second.

Take a look at the 6 lines marked // Costas

You should be good to go now, but study the Blynk docs, SimpleTimer and the getting started example PushData

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>   // Costas not sure why you commented this out
#include <DallasTemperature.h>   // Costas not sure why you commented this out
#define ONE_WIRE_BUS D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#include <SimpleTimer.h>  // Costas

char auth[] = "auth";
char ssid[] = "ssid";
char pass[] = "password";

SimpleTimer timer4mtrucc;   // Costas

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  sensors.begin();
  timer4mtrucc.setInterval(3000L, sendTemps); // Costas read sensors every 3s and send to Blynk server
}

void sendTemps()
{
  sensors.requestTemperatures(); // Polls the sensors
  float temp = sensors.getTempCByIndex(0); // Gets first probe on wire in lieu of by address
  Serial.println(temp);
  Blynk.virtualWrite(V1, temp);
}

void loop()
{
  Blynk.run();
  timer4mtrucc.run();  // Costas, keep timer running
}

Thank you for your help, I am studying and studying now.
In addition, can modify the APP UI? The color is a bit dark, if the same bright as the site just fine. Of course, can add two kinds of color better.

Blynk are working on different themes, keep reading the Announcements.

Nice!