[SOLVED] If don't connect to Internet device go slowly

Good morning, I built a thermostat connected to Blink, the development has gone quite well, now I have realized that if the Arduino Mega with esp8266 not find a wifi just started, the whole system slows becoming virtually unusable, I saw that the problem is the library Blynk working constantly until it finds an internet connection, also if the connection appears after powering Arduino does not connect automatically, but I have to press the reset button. You can enter a time out and reconnect? Using Arduino Mega 2560 and esp8266 connected to the serial hardware 1. Thanks for your attention

@Thomas I’m actually having a very similar (perhaps the same) issue with My Mega + Esp-01 (using HardSerial library) and temperature sensor (HTU21D) and was just about to post on the issue… Something is just not working right.

Here’s my code that’s running incredibly inconsistently (mostly not running)

One thing that’s a little beyond my current arduino knowledge is my HTU21D sensor connects to the SDA/SCL ports on my Mega and also uses the wire library… Could this possibly be causing issues with my esp?

#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>

#include <Wire.h>
#include <SparkFunHTU21D.h>
#include <SimpleTimer.h>


// Set ESP8266 Serial object
#define EspSerial Serial2


ESP8266 wifi(EspSerial);
SimpleTimer timer;

HTU21D myClimate;    //Instance of HTU sensor

int t;
int h;


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

void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(10);

  Blynk.begin(auth, wifi, "NETGEAR21", "nerp");
  myClimate.begin();
  
  timer.setInterval(3000L, currentTemp);    


}

void currentTemp() {
  float celsiusTemp = myClimate.readTemperature();
  celsiusTemp = (celsiusTemp * 9.0) / 5.0 + 32.0; //convert to fahrenheit
  t = celsiusTemp;
  h = myClimate.readHumidity();
}


BLYNK_READ(0) {  
  Blynk.virtualWrite(0, t);
}

//Humidity Display
BLYNK_READ(1) {  
  Blynk.virtualWrite(1, h);
}


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

I use a dht11 temperature and humidity sensor and esp8266 01, I also use nextion serial display, I think the library flood serial for try to connect but it slow all process

The Wire library will, as far as I can see, not interfere with your ESP Serial connection because it uses a very different protocol (I2C instead of good ol’ serial)

It could be the Arduino has difficulty powering everything, so it’s advisable to have all the components on a different power supply and just have a common ground. E.g. all your peripherals on a good supply separate from the Arduino. I had issues with that too and after doing that they all went away.

Your code looks pretty basic and should therefor not be the problem.

@Lichtsignaal I don’t want to hijack the thread but I just wanted to ask a few questions about power for ESP projects.

You will be familiar with @psoro’s Blynk controlled robot at Robot with Esp8266 Shield and Arduino Nano

He is running his robot (Nano and ESP) from batteries. I have the same set up (Nano and ESP) but for a different end use and the cloud, rather than local server. I copied his circuit diagram and have my system set up the same except I provide mains power to the Nano rather than running it on batteries.

I also have the same project running very well with USB rather than with ESP.

The project runs reasonably with ESP but nowhere near as well as with the USB. The Nano has a temperature sensor and an RF transmitter attached. With the ESP I found working with virtual pins was crashing the system so I resorted to digital pins but this is not ideal. Also some features working on the USB just wouldn’t work at all on the ESP (thermostatic control).

With the USB I am using 25K of the 32K program memory and about 1K of the 2K dynamic memory. With ESP the program memory is similar but maybe up to 1.6K of the dynamic memory.

Compared with psoro’s project my demands on the system seem quite light but I am using the cloud server.

Any ideas where I am going wrong (power, memory etc) or am I expecting too much from a Nano with ESP over the cloud server?

I will try one more time with ESP and set up a local server to try to identify some of the problems but ultimately I don’t want to operate with a local server.

Hi I don’t assume that wire library interfere with serial, I’ve tell about temperature sensor for complete details, I think the problem is on the library who seem enter in to blind loop, maybe I’m wrong, anyway all peripheral have a good alimentation, 1 DC dc 3.3 700mah for esp and 2 dcdc 700 mah each for display, arduino, sensor and relay, all have common ground, also if was a alimentation problem I haven’t problem only when Internet connection is unavailable, or not?

Maybe we are finding a common issue related to temperature sensors when connecting ESP’s to Arduino’s?

@Thomas I think perhaps you are saying you only have a problem with obtaining a WiFi connection.

Not quite sure what you mean about the system slows but from the rest of your description maybe the following extract will help.

 #include <avr/wdt.h> // watchdog timer

void setup()
{
  ........................... 
  Blynk.begin(auth, wifi, "GargoyleTest", "xxxxxxx");
   while (Blynk.connect() == false) {
    wdt_enable(WDTO_8S);
  }
  ....................
}

void loop()
{
  Blynk.run();
  timer.run();
  wdt_reset(); // if we get here turn off 8 second WDT
}

With the wdt_enable(WDTO_8S) sandwiched between the while loop the Arduino will reset if it fails to connect within 8 seconds (just about long enough).

If using Arduino with USB move the wdt_enable(WDTO_8S) before Blynk.begin(auth) and delay(24000) before the wdt_enable(WDTO_8S). Basically this will ensure that the tcp connection is reset in blynk-ser.bat when the Arduino resets.

Hope this helps.

Edit: the USB details are for Windows not the Raspberry Pi.

Thank you, I use mega 2560 so I must upgrade the bootloader for use watch dog, I try this but the problem is if my connection is unavailable arduino go slowly, I mean when press any button on my touch it not response and the temperature and humidity are show every 5-10 second instead 1 second when blink is connected, I would like use this thermostat also if Internet connection is unavailable, but blynk library seem work hard and not relase more time for other

I’m not sure what the problem can be, it sounds a bit vague. And usually when it sounds vague it’s a bad Wifi signal or interference from other sources of Wifi. This could be Bluetooth, other wifi, microwave or radar detection from alarm-sensors (the bulky white ones, they operate on 2.4 Ghz too).

The last problem, with the alarm systems, is only detectable with a spectrum analyzer, which is not cheap. This interference or bad signal is VERY hard to diagnose if you are not up to specs. You could consider changing your Wifi channel on your router for example and play with different settings in your router. Because the ESP has a very small antenna it’s usable range is very limited. You could buy one with an external antenna and see what that does.

I’d still suspect the quality of the wifi signal, whatever the cause may be (I manage over 700 accesspoints at a fairly large hospital and I run into this same stuff on a daily basis…).

I tend to run ESP’s standalone, but I guess you guys are limited by the number of pins (I just switch two relays and one led, so an ESP-01 is fine for me). The setup and schematics with the cap is fine. It doesn’t have to be big, but it has to be there. That way you can probably exclude power problems for 99%.

When I had flaky problems with the ESP I noticed it was either:
-Not enough power going to my whole rig. I had to be a step-up module to crank my voltage. I was getting about 4.8 V (4 x 1.4V rechargeables) which wasn’t enough to power everything. My ESP would basically blink its blue transmission light non-stop. With the step-up I cranked it to about 10 V, which was enough power for my Nano+ESP+2 motors.

-Wifi interference. I know it sounds like a “catch all” problem, but in my case, wifi interference was causing my ESP to perform abyssmally (instead of <100ms ping times, it would response with almost 1000ms pings).

I have a feeling it’s power related, because when you are running from USB you say everything runs well.

One moment, my problem is not that I can not use Blynk, indeed works fine, the problem is that if for some reason the Internet is not present, perhaps because the router is switched off or the operator has problems, when I turn on the device which obviously can not connect to the Internet, the system is slowed down, I understand why instead of every second step is performed every 5 10 seconds

@Thomas I think @Lichtsignaal and @cyberbum were trying to resolve my problems.

Back you yours:

So you want to be able to run your system with and without Blynk, right?

Unless you had a very basic Blynk app then you might need quite a lot of code to work around Blynk not being available. It could be done but might be messy. Are you able to provide a sample of the code which uses some of the Blynk widgets etc and we could indicate how you might add extra code when Blynk is not available to you? Are you without internet very often?

@Lichtsignaal and @cyberbum I will start a new thread and post a link here asap (where is ESP8266_SoftSer.h ?)

That is probably because of a time out in the Blynk functions. Just guessing, but maybe @vshymanskyy has a better answer :slight_smile:

I find it odd that a 5v 2a USB wall wart can’t supply enough juice, but I do think it’s a power issue…

And as for wiring… I picked up a cheap 5v to 3.3 v breadboard friendly module… Im guessing i just take the hot and go straight to the esp (vcc and chpd) and do I take the ground from the 3.3v module and go through my esp and then ground it on the arduino board or do I just tie every ground together, including the ground on the module, and tie all of those to the arduino?

@Thomas I’ve definitely thought about the no internet problem. Perhaps a timed switching function that reads from a blynk virtual value you’ve set- If virtual value is zero, virtualwrite it = to 1, and vice versa, additionally making a global ‘isBlynkRunning’ = 1. If the function Can’t accomplish that task, make the isBlynkRuning value = 0 and use that in the rest of your code.

Hi @Costas!
It’s true that I’m running the Nano and Esp from batteries but, as I’ve got 7.4 V in total (2x3.7v) and I power the Nano Shield through 5V regulated external power supply, I use a small PCB with a LM7805. At the same time, my Shield has a LM1117 3.3 V to power the ESP (regulators everywhere! :blush:)

At the same time as @cyberbum says, check channels around your WiFi signal.

Regards!!

I had the same issues as @Thomas, with Blynk constantly trying to connect when Internet was not available therefore causing the rest of the sketch to not be run. I now use 2x arduino’s. One runs Blynk and the other handles the other functions. They communicate together via hard wired serial. It works great.

You could consider using I2C to communicate so you have the serial port free for other usage. Or if you have Mega than there is no problem of course :slight_smile:

Sorry but this thread is getting very confused, I kindly ask you to seek help in a thread here on purpose because we do not understand anything, however for the kind responses I got give other information, I have no connection problems and in 99 percent of all cases It works well, but since it is a thermostat would be useless if it became unusable because the Internet does not work, I repeat is not a frequent problem, but when it coming will be a big problem, I’ll do some testing today with the flags to see if I solve. PS. The project will work with both with Blynk connected to the internet without Blynk