Handle ESP8266 response to CWLAP

I’m running an Arduino and ESP8266 together via SoftwareSerial and I experience quite some instability in how they communicate. What I want to be able to do is to handle a CWLAP response. I want to be able to store the different SSIDs to then later present them as options to the user to select which one to connect to.

I can get it to work but all the different setups I’ve tried seems very fragile, there might be errors relating to buffer sizes, memory constrains due to String-objects, etc. Seems to me that Serial communication and string handling is very poor? Or am I just doing a lot of things wrong?

What would be the optimal way to handle a CWLAP response from the ESP8266?

Seems to me that Serial communication and string handling is very poor?

Your string handling might be. The Arduino compiler is perfectly capable of compiling robust code.

Or am I just doing a lot of things wrong?

Your first one was failing to post any code.

What would be the optimal way to handle a CWLAP response from the ESP8266?

Correctly.

My question is broader than debugging specific code. I’m asking for your best practices around these issues I’m experiencing. So what principles should be followed to handle the response correctly?

I'm asking for your best practices around these issues I'm experiencing

I don't see any issues, just hand-waving.

(Was the "report to moderator" really necessary?)

johanekman:
... setups I've tried seems very fragile, there might be errors relating to buffer sizes, memory constrains due to String-objects, etc. ...

These are the issues, hope you understand. Seems like bad practice to e.g. increase the buffer size in the header-files just to get it work or setting fixed delays to wait for the buffer to start (as many other examples propose).

Asking for best practices on how you handle this particular kind of serial communication with the ESP8266. A good answer could e.g. to this question would be guidance on to use char instead of string instead? (Not saying this is true - only giving an example of what I'm asking for).

OK - don't use String.
Ever.

Ok, why? Is it true that the Arduino string handling is poor?

What should I use instead?

Is it true that the Arduino string handling is poor?

No - where did you get that idea?

It's limited by memory, but within limits, it's as accurate as any other platform.

AWOL:
No - where did you get that idea?

From your answer: "Don't use String. Ever." Kind of indicating that String isn't the best thing to use...

AWOL:
It's limited by memory

The answer from the ESP8266 can be quite long, especially if there are many available WiFi-networks. How would you go about to handle the response. I guess reading the full response into a string is a bad practice, but how to handle it without running into limitations of SoftwareSerial buffer?

From your answer: "Don't use String. Ever." Kind of indicating that String isn't the best thing to use

Absolutely. Never use String.

I didn't say anything about not using strings.
I wholeheartedly recommend using strings.

I don’t know if it is “best practice” but in my opinion it is a lot easyer to skip the AT commands to talk to the ESP8266.

You can program the ESP8266 directly using the Arduino IDE, or use LUA.

Good suggestion - however, I really need the pins from the Arduino. And is the ESP8266 really as powerful as the Arduino?

More powerful faster and more RAM and Flash

I need to one pin for output controlling a relay and another for reading value from a temp-sensor. Can this be done with GPIO0 and GPIO2 from ESP8266-1 or do I need to fix a ESP8266 with more pins?