I just want to confirm that I finally got this working!
I did get a replacement ESP8266 board in the end, as I noticed the original one wouldn't blink the onboard LED during boot. Whereas the replacement did.
I still had quite the struggle to get any code to work, and getting the controller to respond to AT commands.
In the end, it was down to starting up the ESP8266 driver in client mode, which wasn't clear from other examples I saw online from older versions of Mbed.
I did purchase some 5v to 3v3 level converters which worked exactly as expected - I got my multimeter to confirm it was outputting 3.3V before connecting up the ESP8266 so I wouldn't accidentally fry it.
I am also powering it from the power bank, not from the 3.3V/5V output on the FRDM-K64F board.
Then for pinout from ESP8266 to breadboard/FRDM board:
VCC -> 3V3
CHPD(ENABLE) -> 3V3
TXD -> RXD (D0)
RXD -> TXD (D1)
GP0 -> 3V3 (or leave disconnected)
I didn't use the J199 pins in the end.
I tried numerous different versions of code, including using the FRDM board as a middleman serial between my PC and the ESP8266. I would get no response or AT timeouts. Even tried updating the firmware to no evail. Finally, after reading through the driver code and running the startup method, I could see networks being printed in the terminal.
I never like those forum posts that say they solved the problem without giving the solution. Here is my code now:
#include "mbed.h"
#include "ESP8266.h"
// Debug is true so I could figure out what was happening.
ESP8266 wifi(ARDUINO_UNO_D1, ARDUINO_UNO_D0, true);
// Built-in LED on FRDM-K64F board. Red for no networks, green for networks found.
DigitalOut red(LED1);
DigitalOut green(LED2);
// Store up to 10 results
WiFiAccessPoint accessPoints[10];
WiFiAccessPoint* accessPointsPointer = accessPoints;
// main() runs in its own thread in the OS
int main()
{
red = 1;
green = 1;
// Verify that we start up in client mode.
if (wifi.startup(1)) {
printf("Startup: yes\n");
} else {
printf("Startup: no\n");
}
ThisThread::sleep_for(1s);
// Verify we can start sending AT commands.
if (wifi.at_available()) {
printf("Available: yes\n");
} else {
printf("Available: no\n");
}
ThisThread::sleep_for(1s);
while (true) {
ThisThread::sleep_for(2s);
printf("Scanning...\n");
int count = wifi.scan(accessPointsPointer, 10, wifi.SCANMODE_ACTIVE, ESP8266_SCAN_TIME_MIN_DEFAULT, ESP8266_SCAN_TIME_MAX_DEFAULT);
if (count <= 0) {
red = 0;
green = 1;
printf("No networks found.\n");
} else {
printf("Number of networks found: %d\n", count);
red = 1;
green = 0;
for (int i = 0; i < count; i++) {
printf("- Network: %s RSSI: %d\n", accessPoints[i].get_ssid(), accessPoints[i].get_rssi());
}
}
}
}
I hope anyone else in the future who comes across this problem can be saved by this post, I can't estimate how many hours I spent trying to get this working. Now to make some wireless stuff!