I figure I am missing something simple, but I was trying to create a simple server with the adafruit Huzzah and after setting the board and libraries etc, I found "Hello Server" under the examples for the board. If I compile and load the example, it works fine, however it is using DHCP to get an IP address. Looking in the reference for WiFi WiFi - Arduino Reference there is an example for WiFi.config for setting a static IP address. When I follow the example, the call to WiFi.config(ip) breaks with the error message "HelloServer_hummer1:45: error: no matching function for call to 'ESP8266WiFiClass::config(IPAddress&)'" - if I comment out the line for WiFi.config(ip), then it compiles and loads without any problem (other than using DHCP for the IP address. Here is the basic code I have (my additions have "mjf" in the comment line)
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
// enter correct SSID and password below for my network
const char* ssid = "SSID here";
const char* password = "PASSWORD here";
IPAddress ip(192, 168, 2, 150); // mjf - added static IP address definition
// Create an instance of the server
// specify the port to listen on as an argument
ESP8266WebServer server(80);
const int led = 13;
void handleRoot() {
digitalWrite(led, 1);
server.send(200, "text/plain", "hello from esp8266 and Hummer 1");
digitalWrite(led, 0);
}
void handleNotFound(){
digitalWrite(led, 1);
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
digitalWrite(led, 0);
}
void setup(void){
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
WiFi.config(ip); // mjf - configure for static IP
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/inline", [](){
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}
What is the simple piece of the puzzle that I am missing ... please?