• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Asyncrounus data collection crashes

Q&A Forum › Category: ESP32 › Asyncrounus data collection crashes
0 Vote Up Vote Down
Anders Gårdö asked 5 years ago

I am trying to make a simple data collection with two ESP32. The server uses a BME 280 to formulate data:

/*
ESP32 + BME280
Svarar på fråga om temperatur resp RF
*/
#include <SPI.h>
#include <WiFi.h>
#include <Wire.h>
#include <ESPAsyncWebServer.h>
#include <Adafruit_BME280.h>
#include <Adafruit_Sensor.h>
Adafruit_BME280 bme; // I2C
char ssid[] = "";
char pass[] = "";
AsyncWebServer server(80);
IPAddress local_IP(192, 168, 0, 205); // Suntak UTE
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
String getAnswer()
{
String temp = "0";
String RH = "0";
String svar;
delay(50);
bme.begin(0x76);
temp = bme.readTemperature();
delay(50);
RH = bme.readHumidity();
svar = temp + ";" + RH;
return svar;
}
void setup() {
Serial.begin(19200); // only for debug
if (!bme.begin(0x76))
{
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
if (!WiFi.config(local_IP, gateway, subnet)) {
Serial.println("STA Failed to configure");
}
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
// Serial.print(".");
delay(500);
}
//Serial.print("Local IP: "); Serial.println(WiFi.localIP());
// Serial.println("Connected to wifi");
server.on("/GetStatus", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(200, "text/plain", getAnswer());
});
server.begin();
}
void loop ()
{
}

The client uses HTTPClient to receive:

#include <WiFi.h>
#include <HTTPClient.h>
char ssid[] = "";
char pass[] = "";
IPAddress ip(192, 168, 0, 201); // IP address ofthis client
IPAddress gateway(192, 168, 0, 1); // gateway of your network
IPAddress subnet(255, 255, 255, 0); // subnet mask of your network
void setup() {
Serial.begin(19200);
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
//Serial.print(".");
delay(50);
}
Serial.println("Connected to wifi");
}
void loop ()
{
HTTPClient http;

http.begin("http://192.168.0.205/GetStatus");
int httpCode = http.GET();
if (httpCode > 0)
{
String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
}
else {
Serial.println("Error on HTTP request");
}
http.end();
delay(10000);
}

The problem is that the client crashes in a inpredictable manner. Sometimes it workes 50 times in a row, sometimes it crashes a couple of times and then works two times and then crashes etc. I can not find a pattern in it. To my mind it looks as some kind of memory problem but I need help to find out what it is.

Question Tags: ESP32 crashes
3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Hi.
When you say it crashes, what do you actually mean? What happens when it crashes? Can you describe?
Regards,
Sara

0 Vote Up Vote Down
Anders Gårdö answered 5 years ago

Hi Sara.
PROBLEM SOLVED!
It used to crash, reboot, now and then, but now it has been sending and receiveing every 10 second for 2,5 hours without any problems.
I wrote a line to check WiFI status prior to every hppt call, that did the trick. It seems that the WiFi connection can’t be trusted even if the connection has started in a normal way.
Sorry to bother you with such a trivial problem.
Regards
Anders

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Hi.
Great that you’ve solved the problem.

Something that can improve your code is replacing that delay with millis() instead.

I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.

Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.