Page 2 of 3
Re: Simple TCP server
Posted:
Fri Jan 29, 2016 3:50 pm
by martinayotte
Maybe you should share your code to see if we can pin-point the error.
Also, have a look at ESP8266WiFi/examples/WiFiTelnetToSerial example, but instead of outputting to serial accumulate the characters received into a buffer until new line and then execute your command parsing on that buffer.
Re: Simple TCP server
Posted:
Thu Jan 05, 2017 7:45 am
by Joy Acharya
please check this code...
Code: Select all#include <ESP8266WiFi.h>
// wifi connection variables
const char* ssid = "xxxxxxxx";
const char* password = "xxxxxx";
WiFiServer server(2000);
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(" connected");
server.begin();
Serial.printf("TCP server started, open %s in your com operator\n", WiFi.localIP().toString().c_str());
}
void loop()
{
WiFiClient client = server.available();
if (client) {
Serial.println("Client connected.");
while (client.connected())
{
if (client.available())
{
//String line = client.readStringUntil('\r');
// Read incoming message
char inChar = client.read();
// Send back something to the clinet
server.write(inChar);
// Echo input on Serial monitor
Serial.write(inChar);
}
}
Serial.println("Client disconnected.");
client.stop();
}
}
Re: Simple TCP server
Posted:
Tue Jun 13, 2017 2:11 pm
by Shivank
Hi spy king,
Great post!
I want a simple ESP8266 - Laptop connection over wifi. I am using arduino ide to program my esp. Please guide me from where should I start. Suggest link, video or tutorial.
Regards,
Shivank
Re: Simple TCP server
Posted:
Sat Nov 11, 2017 10:12 am
by Manowar
Got a problem with connection to server, putty prints unexpected end of connection.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
// Hardcode WiFi parameters as this isn't going to be moving around.
const char* ssid = "ESP";
const char* password = "";
// Start a TCP Server on port 5045
WiFiServer server(5045);
WiFiClient client;
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_AP);
WiFi.softAP(ssid,password);
// Start the TCP server
server.begin();
}
void loop() {
TCPServer();
}
void TCPServer () {
client = server.available();
if (client) {
if (client.connected()) {
Serial.println("Connected to client");
}
if (client.available() > 0) {
// Send back something to the clinet
server.write(1);
// Echo input on Serial monitor
Serial.write(1);
}
}
}
sometimes got in log chg_A2:-40 but not always. Need some help, don't mind what's a problem.