Created
November 4, 2017 09:49
-
-
Save mims92/2d6111da6b5c1ee305bd3bd3e6e9e4fb to your computer and use it in GitHub Desktop.
ESP8266 - C - Connect to Wifi with static IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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