Skip to content

Instantly share code, notes, and snippets.

@piedoom
Last active March 19, 2018 21:09
Show Gist options
  • Save piedoom/f816438479c1bc1ecebe97f5205156b1 to your computer and use it in GitHub Desktop.
Save piedoom/f816438479c1bc1ecebe97f5205156b1 to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
// How many clients should be able to telnet to this ESP8266
#define MAX_SERVER_CLIENTS 2
// Baud rate for serial monitors (useful for development)
#define BAUD_RATE 115200
// Network name and password for the ESP to connect
const char SSID[] = "nyanet";
const char PASS[] = "manner+tinge-";
// Port to serve and receive data
const int PORT = 69;
// Setup server
WiFiServer server(PORT);
WiFiClient client;
void setup() {
Serial.begin(BAUD_RATE);
// add a delay to make sure everything is in order and connected
delay(200);
// Debug network information
Serial.print("Connecting to: ");
Serial.println(SSID);
// Actually connect to the WiFi
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PASS);
// Delay execution of main loop until connected
uint8_t i = 0;
while (WiFi.status() != WL_CONNECTED && i++ < 20) delay(500);
if (i == 21) {
Serial.print("Could not connect to"); Serial.println(SSID);
delay(3000);
ESP.restart();
}
Serial.println("Connected.");
Serial.println(WiFi.localIP());
server.begin();
server.setNoDelay(true);
}
void loop() {
// listen for incoming clients
client = server.available();
if (client){
Serial.println("Client connected");
while (client.connected()){
if (client > 0) {
// Serial.write(client.read());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment