Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By mconsidine
#56512 Hi,
I have tried searching these forums, Google and github for an answer to this question and am coming up short. So apologies in advance if I missed the answer to this question.

TL;DR : I want to use the Arduino IDE and sketch to setup an ESP8266-12 such that it has a specific IP address (e.g. 1.2.3.4), a server on a specific port and is in AP mode. I know how to get the server started. And can get it running in AP mode. Getting it to come up using a non-192.168.x.x IP address is eluding me. Can someone point me to a sketch that accomplishes this?

Longer version : I am using Arduino IDE 1.6.11 with an ESP8266-12 on an adapter board. 3.3V is supplied to the module and I am talking to it via an FTDI-type cable (USB-to-four-wires). When the board is set to "Generic ESP8266" and the correct options and when baud rates are set correctly, everyone is happy. I can see "Serial" output on the IDE serial monitor when I am running a sketch on the module.

Using this
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino
as a basis, I am trying to talk to a piece of software that expects a WiFly module on the other end of its line. For the moment, that is neither here nor there - I just want to establish a connection to see what the dialogue is between the software and the instrument.

I have no problem getting a server set up but because it is expected to be found at a specific IP address I need to have the module identify as such. The module does not need to connect to any other existing network as it is for use in the field.

I've seen this topic ("Configure esp as access point")
http://www.esp8266.com/viewtopic.php?f=8&t=1925&start=12
as well as discussions of problems getting Wifi.config, Wifi.begin, etc. used, e.g.
https://github.com/esp8266/Arduino/issues/128
https://github.com/esp8266/Arduino/issues/2182

But I haven't seen a clean example of setting up a module as an access point with a non-default IP address (i.e. something other than 192.168.4.1, such as 1.2.3.4).

Can someone point me to a sketch or provide some code that can accomplish this? I have been using version 2.3 of the Arduino IDE and reverted last night to 2.2, per some of the Github comments. But that doesn't seem to work - the module still comes up with the default IP address.

Is there some data in the EEPROM I need to delete first or some other trick that I am not appreciating?

Thanks in advance for reading and for any help that can be shared.
Matt
User avatar
By mrburnette
#56986 Several ways to pull this off, but the simple way is:

Code: Select allIPAddress    apIP(10, 10, 10, 1);                               // Private network address: local & gateway

<...>
void setup() {
  WiFi.mode(WIFI_AP_STA);
  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));   // subnet FF FF FF 00
  WiFi.softAP("TardisTime");




Ray
User avatar
By mconsidine
#57319 Thank you for this. This seems to be exactly what I need. For some reason or another, I thought I could use WiFi.config and completely missed setting it up in this order.

Much obliged!

Matt

mrburnette wrote:Several ways to pull this off, but the simple way is:

Code: Select allIPAddress    apIP(10, 10, 10, 1);                               // Private network address: local & gateway

<...>
void setup() {
  WiFi.mode(WIFI_AP_STA);
  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));   // subnet FF FF FF 00
  WiFi.softAP("TardisTime");




Ray
User avatar
By mconsidine
#58055 Just to close the loop on this, this code is what ended up working :
Code: Select all  Serial.begin(115200);
  Serial1.begin(19200);
  WiFi.mode(WIFI_AP_STA);  //need both to serve the webpage and take commands via tcp
  IPAddress ip(1,2,3,4);
  IPAddress gateway(1,2,3,1);
  IPAddress subnet(255,255,255,0);
  WiFi.softAPConfig(ip, gateway, subnet);
  WiFi.softAP("ESPname1"); //Access point is open

  delay(1000);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);


Thanks again for the help.
Matt