Skip to content

Instantly share code, notes, and snippets.

@mims92
Created November 4, 2017 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mims92/2d6111da6b5c1ee305bd3bd3e6e9e4fb to your computer and use it in GitHub Desktop.
Save mims92/2d6111da6b5c1ee305bd3bd3e6e9e4fb to your computer and use it in GitHub Desktop.
ESP8266 - C - Connect to Wifi with static IP
/**
* 4-10-2017
* Can be improved to try to reconnect in case of failure.
*/
#include "ESP8266WiFi.h"
char pass[] = "PASS";
char ssid[] = "SSID";
IPAddress ip(192, 168, 42, 200); //Static ip
IPAddress dns(8, 8, 8, 8);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
int status;
void setup() {
Serial.begin(115200);
Serial.print("Trying connect to ");
Serial.println(ssid);
// attempt to connect to Wifi network:
WiFi.config(ip, dns, gateway, subnet);
status = WiFi.begin(ssid, pass);
status = WiFi.waitForConnectResult();
if (status != WL_CONNECTED) {
Serial.print("Connection Failed!");
} else {
Serial.print(status);
Serial.println("Connected!");
Serial.println(WiFi.localIP());
}
}
void loop() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment