Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esp8266 automatic reset after about 5 darksky reads #24

Open
pvdw0310 opened this issue Oct 28, 2019 · 9 comments
Open

Esp8266 automatic reset after about 5 darksky reads #24

pvdw0310 opened this issue Oct 28, 2019 · 9 comments

Comments

@pvdw0310
Copy link

pvdw0310 commented Oct 28, 2019

Hi,
I' am using the My_DarkSkyWeather_Test.ino sketch and after about 5 times reading the weatherdata, I get a connection fail and with the next read I get a dump and a reset of the esp8266. I added a => Serial.println(String(ESP.getFreeHeap())); and after each weatherread the freeheap is less. When it comes to about 29000 I get the error.
Do you have any idee how to solve that problem?
Many thanks
Peter

@pvdw0310
Copy link
Author

pvdw0310 commented Oct 28, 2019

Hi, some extra info:
I changed/added the sketch with =>hourly = nullptr; daily = nullptr; => to read only the current info.
Then I have the problem, NOT if you read the full json file.

Bodmer added a commit that referenced this issue Oct 28, 2019
@Bodmer
Copy link
Owner

Bodmer commented Oct 28, 2019

Thanks for reporting this. There was a bug where the space reserved for minutely data was not released.

Added line here.

If you are not collecting the hourly and daily data you do not need to reserve the space for the results, so you can delete the unused reservations and deletions.

@pvdw0310
Copy link
Author

Thanks to have a look, but I still have the same problem. This is what I changed =>


// Create the structures that hold the retrieved weather

DSW_current *current = new DSW_current;
DSW_minutely *minutely = new DSW_minutely;
DSW_hourly *hourly = new DSW_hourly;
DSW_daily *daily = new DSW_daily;
// if daily not used by this sketch, set to nullptr
minutely = nullptr; // extra
hourly = nullptr; // extra
daily = nullptr; // extra
dsw.getForecast(current, minutely, hourly, daily, api_key, latitude, longitude, units, language);
.
.
.
// Delete to free up space and prevent fragmentation as strings change in length
delete current;
delete minutely; //extra
delete hourly;
delete daily;

@Bodmer
Copy link
Owner

Bodmer commented Oct 29, 2019

The structures cannot be deleted if you set them to nullptr! Just put nullptr in the call:
dsw.getForecast(current, nullptr, nullptr, nullptr, api_key, latitude, longitude, units, language);

@Bodmer
Copy link
Owner

Bodmer commented Oct 29, 2019

This is the main function from my adapted test sketch:

void printCurrentWeather()
{
  // Create the structures that hold the retrieved weather
  DSW_current *current = new DSW_current;

  time_t time;

  Serial.print("\nRequesting weather information from DarkSky.net... ");

  dsw.getForecast(current, nullptr, nullptr, nullptr, api_key, latitude, longitude, units, language);

  Serial.println("Weather from Dark Sky\n");

  // We can use the timezone to set the offset eventually...
  // Serial.print("Timezone            : "); Serial.println(current->timezone);
  
  Serial.println("############### Current weather ###############\n");
  Serial.print("Current time             : "); Serial.print(strTime(current->time));
  Serial.print("Current summary          : "); Serial.println(current->summary);
  Serial.print("Current icon             : "); Serial.println(getMeteoconIcon(current->icon));
  Serial.print("Current precipInten      : "); Serial.println(current->precipIntensity);
  Serial.print("Current precipType       : "); Serial.println(getMeteoconIcon(current->precipType));
  Serial.print("Current precipProbability: "); Serial.println(current->precipProbability);
  Serial.print("Current temperature      : "); Serial.println(current->temperature);
  Serial.print("Current humidity         : "); Serial.println(current->humidity);
  Serial.print("Current pressure         : "); Serial.println(current->pressure);
  Serial.print("Current wind speed       : "); Serial.println(current->windSpeed);
  Serial.print("Current wind gust        : "); Serial.println(current->windGust);
  Serial.print("Current wind dirn        : "); Serial.println(current->windBearing);

  Serial.println();

  // Delete to free up space and prevent fragmentation as strings change in length
  delete current;
}

@Tokn59
Copy link

Tokn59 commented Nov 18, 2019

Hello, I have the exact same problem where my ESP32 crashes after reading nn readings. This is my (partly) code. Anything else I should do ?

void weather_Today() {

// Create the structures that hold the retrieved weather
DSW_current *current = new DSW_current;
// DSW_minutely *minutely = new DSW_minutely;
// DSW_hourly *hourly = new DSW_hourly;
// DSW_daily *daily = new DSW_daily;

time_t time;

draw_Grid();
get_Date_time();

dsw.getForecast(current, nullptr, nullptr, nullptr, api_key, latitude, longitude, units, language);

Thanks for your help !!!

Tony

@Lebo77
Copy link

Lebo77 commented Nov 18, 2019

You are calling new DSW-current. Are you calling delete as well somewhere? You may just be running out of memory.

@Tokn59
Copy link

Tokn59 commented Nov 18, 2019

Yes, got it working for current right now. When I add "daily" the crashes occur again. It has to do with hom many times and how you get the weather info .. Still trying to find out ...

@Tokn59
Copy link

Tokn59 commented Nov 19, 2019

Problem solved. Best seems to read all values in one go (current, daily, hourly ...) And not read in any data in parts. Delete current, daily .. etc after you are done with their values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants