Chat freely about anything...
User avatar
By hallgren
#20057 Hi everyone,

I'm still a newbie on the ESP8266 but I have a ESP-01 and I have flashed it with the latest AT firmware found here https://github.com/espressif/esp8266_at/tree/master/bin. I'm using the Arduino 1.6.4 IDE and everything seems to work as expected but I have a question about setting a static IP address for the device.

If I set the IP after I connect it works but based on other sources I should be able to do it before I do WiFi.begin. This works but what happens if there is no DHCP server? I assume that the device will try to get a DHCP address before looking at the next line of code and that will introduce a long wait, right?

Code: Select allWiFi.begin(AP_SSID, AP_PASSWORD);
WiFi.config(AP_IPADD,AP_IPGW,AP_IPSUB);


And how do I set a DNS server? By looking at the source code here https://github.com/esp8266/Arduino/blob/esp8266-sdk-1.0/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp I thought that it could be set like this:

Code: Select allWiFi.begin(AP_SSID, AP_PASSWORD);
WiFi.config(AP_IPADD,AP_IPGW,AP_IPSUB,AP_IPDNS);


based on this code:

Code: Select allvoid ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns)
{
    struct ip_info info;
    info.ip.addr = static_cast<uint32_t>(local_ip);
    info.gw.addr = static_cast<uint32_t>(gateway);
    info.netmask.addr = static_cast<uint32_t>(subnet);

    wifi_station_dhcpc_stop();
    wifi_set_ip_info(STATION_IF, &info);

    // Set DNS-Server
    ip_addr_t d;
    d.addr = static_cast<uint32_t>(dns);
    dns_setserver(0,&d);
   
   _useStaticIp = true;
}


but I get this

Code: Select all...packages/esp8266/hardware/esp8266/1.6.4-673-g8cd3697/libraries/ESP8266WiFi/src/ESP8266WiFi.h:88:10: note:   candidate expects 3 arguments, 4 provided
no matching function for call to 'ESP8266WiFiClass::config(IPAddress&, IPAddress&, IPAddress&, IPAddress&)'


Thanks in advance!
User avatar
By tytower
#21364 I agree with you its odd . The function you show has 4 variables and you provide 4 variables so why does the IDE want 3 ?

I would say its not using the library you show but another , perhaps ethernet library or something that uses a 3 variable function. Try updating the IDE if you are still working on this . There were quite a few changes in 1.6.4 and 1.6.5 is out so maybe try that if you don't have it updated already (turn update on in preferences)
Alternatively go github ESP8266/Arduino/Issues and have a look through or put a new one in
User avatar
By martinayotte
#21388 There is a simple reason for that : the 4 arguments function has been added on June 5th, so maybe the JSON package installer for Arduino IDE is providing an older version.
https://github.com/esp8266/Arduino/comm ... d96c58d8df
If it is the case, maybe you will need to update core files directly from GitHub or simply use the 3 arguments function without DNS.
User avatar
By ArnieO
#21391 This works for me:
Code: Select all#include <ESP8266WiFi.h>

const char *ssid =      "YourSSID";      
const char *pass =      "YourPassword";

// Update these with values suitable for your network.
IPAddress ip(192,168,0,128);  //Node static IP
IPAddress gateway(192,168,0,1);
IPAddress subnet(255,255,255,0);

void setup()
{
  WiFi.begin(ssid, pass);
  WiFi.config(ip, gateway, subnet);

  //Wifi connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("WiFi connected, using IP address: ");
  Serial.println(WiFi.localIP());
}

void loop()
{
}