ESP8266 - Solving problems

I have been playing with using ESP8266 to access openweather.org's API for current weather.

The data is received as a JSON structure, documented here. The original code I stole was actually crap - it didn't attempt to parse the JSON correctly, merely removed the array-indicating "[]" and parsed it as a flat structure! Needless to say, it broke once there was more than one entry in "weather"... Took me a while to realise that.

Next was having the device crash, with a couple of different exceptions, all pointing to something memory-based.  So I tried clearing the JsonBuffer structure between parse attempts, which seemed to help.

Still kept crashing - I tried doing the API data fetch once, and repeating the parsing endlessly - no crashes! So it looks like something in WiFi/WiFiClient that is giving me problems. Maybe I need to initialise it each time...

Right. This is dull. It's almost completely unpredictable, which makes me think it's not the code per se, but power/timing/whatever. Failure cause is different, not every time, but different enough. Recovery is different too, depending on what happened! It's failed

  • In JSON code
  • Loop thread
So I don't really know how to make this reliable, except
  1. Make sure it always reboots after a crash
  2. Any data is stored somewhere less volatile than on board :-p
2 is a bit hard - that involves getting access to somewhere it can be stored, probably online!


Comments

Popular posts from this blog

Replacing Coffee Machine Pump (Dualit Espressivo)

Multiple SHT30 sensors on a single I2C bus with Sonoff-Tasmota

NodeMCU + Tasmota code + SHT30