-
-
Save rDr4g0n/ce7efedad7d814c38019 to your computer and use it in GitHub Desktop.
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
#include <ESP8266WiFi.h> | |
// credentials for server_a AP | |
const char* ssid = "phoxlightpublic"; | |
const char* pass = "phoxlightpublic"; | |
// ip and port for server_a tcp server | |
IPAddress serverIP = {192, 168, 4, 1}; | |
const int port = 6262; | |
void setup(void){ | |
Serial.begin(9600); | |
// connect to AP | |
Serial.print("Connecting to "); | |
Serial.println(ssid); | |
WiFi.begin(ssid, pass); | |
int status = WiFi.status(); | |
while(status != WL_CONNECTED){ | |
delay(500); | |
status = WiFi.status(); | |
Serial.print(status); | |
} | |
IPAddress ip = WiFi.localIP(); | |
Serial.print("Connected!"); | |
Serial.print("IP: "); | |
Serial.println(ip); | |
} | |
void loop(void){ | |
// wait a sec | |
delay(1000); | |
// try to connect to server_a | |
Serial.print("Attempting to connect to"); | |
Serial.print(serverIP[0]); | |
Serial.print(serverIP[1]); | |
Serial.print(serverIP[2]); | |
Serial.println(serverIP[3]); | |
WiFiClient client; | |
int connectState = client.connect(serverIP, port); | |
Serial.print("connectState: "); | |
Serial.println(connectState); | |
} |
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
#include <ESP8266WiFi.h> | |
// credentials for AP | |
const char* ssid = "phoxlightpublic"; | |
const char* pass = "phoxlightpublic"; | |
// ip and port for tcp server | |
IPAddress serverIP = {192, 168, 4, 1}; | |
const int port = 6262; | |
WiFiServer server(port); | |
void setup(void){ | |
Serial.begin(9600); | |
// bring up AP | |
Serial.println("Setting up AP"); | |
WiFi.mode(WIFI_AP); | |
WiFi.softAP(ssid, pass); | |
Serial.println("AP up!"); | |
IPAddress ip = WiFi.softAPIP(); | |
Serial.print("AP IP: "); | |
Serial.println(ip); | |
// bring up tcp server | |
Serial.println("Setting up server"); | |
server.begin(); | |
Serial.println("Server up!"); | |
} | |
void loop(void){ | |
// check for clients | |
WiFiClient client = server.available(); | |
if(!client){ | |
return; | |
} | |
// yay! got one! | |
Serial.println("Got client!"); | |
while(!client.available()){ | |
delay(1); | |
} | |
client.flush(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment