Problems compiling with ESP8266WiFi.h with Mega & ESP8266

I am trying to add WiFi to a Mega2560 using an ESP8266 board. Hardware is working fine. I am also using PubSubClient.h. as I wish to use MQTT for control
I have Arduino 1.6.13 & I have downloaded the ESP core for the ESP8266 BUT I do not wish to compile programs for flashing to the ESP, I wish to leave the ESP with AT command set & compile programs for the Mega.
ESP8266WiFi from the core only seems to be available if the board type is set to “ESP8266 generic” but not if set to “Mega2560”
I obtained ESP8266WiFi.h from but this causes 3 errors

  1. Missing “queue.h” Solved by downloading it from Arduino/queue.h at master · esp8266/Arduino · GitHub
  2. missing
  3. if the board is set to “ESP8266 generic” there is an error message “…duplicate ESP826WiFi.h…”

How can I use ESP826WiFi.h in programs on the Mega?

I would be grateful for some advice


If you “do not wish to compile programs for flashing to the ESP”, then esp8266WiFi.h won’t be any good to you. It (and the corresponding .c or .cpp file) will have been specifically written for the esp8266 hardware, and will make no sense to a Mega.
You’ll need to find a different library (presumably one that handles AT commands); sorry I can’t help you with which one because I’m using sketches compiled for the ESP8266, so I am using esp8266WiFi.h . The WiFi works very well by the way.

This is the library you want:

Many Thanks!
I have tried WiFiEsp with PubSubClient. The sketches compile fine and almost work! I can connect to wifi & to MQTT broker & publishing messages is fine but I cannot get it to receive subscribed messages. I wondered if I could use a different WiFi library but I will give up that line of enquiry.
My problem is getting PubSubClient to receive subscribed messages - I will continue working on that!

Please post your sketch using code tags(</> button on the toolbar).