Skip to content

Instantly share code, notes, and snippets.

@prasertsakd
Last active August 29, 2015 14:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prasertsakd/976588e458d8064d3964 to your computer and use it in GitHub Desktop.
Save prasertsakd/976588e458d8064d3964 to your computer and use it in GitHub Desktop.
esp8266 + arduino code fix ip
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
WiFiUDP Udp;
const char* ssid = "------------";
const char* password = "---------------";
IPAddress local_ip = {192,168,1,200};
IPAddress gateway = {192,168,1,1};
IPAddress subnet = {255,255,255,0};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(10);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
WiFi.config(local_ip, gateway, subnet);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
Udp.begin(49999);
Serial.println("UDP Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
Udp.parsePacket();
while(Udp.available()){
Serial.print(Udp.remoteIP());
Serial.print(" : ");
String req = Udp.readStringUntil('\r');
Serial.println(req);
Udp.flush();
delay(5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment