Go Down

Topic: ESP 8266 WiFi Libraries (Read 61742 times) previous topic - next topic

RayLivingston

I seem to be confused about WiFi libraries for the 8266.  There is the built-in WiFi library, and there is also the ESP8266WiFi library, which *appears* to be a super set of the built-in library with, in particular, more AP capabilities.  However, I cannot for the life of me get a sketch to build using ESP8266.  I am now wondering if that library is actually for the firmware running ON the 8266?  If not, how in the heck do you install ESP8266 in such a way that the compiler finds it?  It gets installed as a "package" in Users/user/AppData/Local/arduino15, where the compiler doesnt find it.

Regards,
Ray L.

RayLivingston

I think this is starting to sink in, but I hope someone here can confirm...  It does appear to me the ESP8266 library is used for creating code that runs ON the 8266.  The WiFi library is then used on the Arduino, to send/receive data with clients.

So I need to do a program using ESP8266 that puts it into AP mode.  Then just do a standard program on the Arduino (in this case a Mega2560) that uses the standard WiFi.h and WiFiUDP.h to send and receive UDP packets with the clients?

Is this correct?

Regards,
Ray L.

pert

The WiFi library is written for the Arduino WiFi Shield, which is completely different than the ESP8266. You can't use the WiFi library with the ESP8266. The ESP8266WiFi library is part of ESP8266 core for Arduino:
https://github.com/esp8266/Arduino
which is used to directly program the ESP8266 via the Arduino IDE. The ESP8266WiFi library is similar to the WiFi library in that it attempts to  use the same API but the actual code inside the libraries is different.

It appears that you are instead using the ESP8266 as a WiFi module. Likely it is connected to your Mega via serial and the ESP8266 is running the AT firmware. For that usage I recommend this library:
https://github.com/bportaluri/WiFiEsp
It also uses the standardized API. When you are using the ESP8266 as a module you will not want to use the ESP8266 core for Arduino as you will be programming the Mega rather than the ESP8266.

RayLivingston

#3
Oct 31, 2017, 04:25 am Last Edit: Oct 31, 2017, 04:28 am by RayLivingston
Ok.... I'm now thoroughly confused....  I thought the ESP8266 was the chip ON the WiFi sheild?

Here's what I need to do:

I have several (up to 9) ProMini "clients", each with an 8266 module connected via its serial port.  The modules are like this one:

https://www.ebay.com/itm/1x-ESP8266-Serial-WIFI-Wireless-Transceiver-Module-Send-Receive-LWIP-AP-STA-A/201919942897?hash=item2f035dd0f1:g:f78AAOSwT~9WhVbc

I then have a Mega2560, as it requires several additional serial ports for other devices.  This Mega will have the same 8266 module connected to one of its serial ports.  This 8266 needs to act as an AP, so the others can connect, send/receive packets using UPD, then disconnect.  I want the Mega to be able to actually receive and respond to the UDP packets from the clients.

How do I do that?  At first, I thought I could just use WiFi.softAP() to turn the 8266 into an AP, but the standard WiFi library does not seem to support softAP.  That's when I stumbled across the ESP8266 library, which I first thought was a super-set of the WiFi library.  Clearly I was wrong there.  So I'm now thinking I need to use the ESP8266 library to turn the 8266 module into an AP, then can use the WiFi and WiFiUDP libraries on the Mega to send and receive packets.

Is that even close to correct?

Regards,
Ray L.


pert

Ok.... I'm now thoroughly confused....  I thought the ESP8266 was the chip ON the WiFi sheild?
There are ESP8266 shields you can buy but they are not official Arduino products. The official Arduino WiFi Shield uses the HDG204 so it's completely different and that's the shield the WiFi library included with the Arduino IDE is compatible with.
So I'm now thinking I need to use the ESP8266 library to turn the 8266 module into an AP, then can use the WiFi and WiFiUDP libraries on the Mega to send and receive packets.

Is that even close to correct?
You can certainly use the ESP8266 core for Arduino and the ESP8266WiFi library to write a firmware sketch and upload it to the ESP8266 modules if you like and then use whatever communications protocol you have devised to communicate between your AVR Arduino boards and the ESP8266 modules. The more common alternative is to just use the standard AT firmware which most ESP8266 modules come already flashed with. The WiFiEsp library makes it very easy to control ESP8266 modules running that firmware by hiding the AT commands behind the standard API used in the official WiFi and Ethernet libraries. You can see an example of that library being used with an AP on the ESP8266 module in this example sketch:
https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebServerAP/WebServerAP.ino
But you need to get this idea of using the standard WiFi library out of your head. That said, because of the similar API it is possible to reuse code written for those libraries with the WiFiEsp or ESP8266WiFi libraries with minimal changes.

RayLivingston

Ok, it's sinking in slowly....  I did mis-state one thing:  the "server" is using one of these, and no AVR Arduino.

https://www.ebay.com/itm/NodeMcu-Lua-ESP8266-ESP-12E-CH340G-WIFI-Network-Development-Board-Module/172437818975?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2060353.m2749.l2649

So, it appears I can implement the entire functionality using the ESP8266 library.  Though it's not obvious to me how to do UDP on this, as there seems to be no UDP class as part of the ESP8266 library.

The clients are using the module I linked to previously, so I will use WiFiESP for those.

Is there a decent web page that explains this well?  I've spent a lot time Googling, and just gotten more confused.

Thanks much for your help!

Regards,
Ray L.

pert

the "server" is using one of these, and no AVR Arduino.
Those are great, you can just upload sketches over USB without having to deal with the hassle of connecting a separate USB-serial adapter like with the other modules and you have all the pins broken out and a 4 MB flash chip. I've mainly used the WeMos D1 Mini boards because they're smaller but I had one of those "NodeMCU" boards first.

So, it appears I can implement the entire functionality using the ESP8266 library.  Though it's not obvious to me how to do UDP on this, as there seems to be no UDP class as part of the ESP8266 library.
Here's the list of the UDP functions:
https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/udp-class.html
and some examples:
https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/udp-examples.html
And ESP8266WiFi library documentation:
https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/readme.html

RayLivingston

pert,

Thanks much!  I think I have a handle on it now.

Regards,
Ray L.

Go Up