AP mode and Telnet problem
Posted: Sat Sep 30, 2017 3:55 pm
Hi,
Using the Arduino iDE and ESP8266 libraries, I tried to put the ESP8266 in AP mode and later to recieve and send data vía telnet, I merged the examples WifiAccessPoint and WiFiTelnetToSerial.
When a device connects to the ESP8266 via telnet appears on Serial New client: 0, but if the device sends data it will not show on serial in the ESP, and if the ESP sends something the device will not show it.
The two bare examples works for me.
What I am doing wrong?
Thanks.
Using the Arduino iDE and ESP8266 libraries, I tried to put the ESP8266 in AP mode and later to recieve and send data vía telnet, I merged the examples WifiAccessPoint and WiFiTelnetToSerial.
When a device connects to the ESP8266 via telnet appears on Serial New client: 0, but if the device sends data it will not show on serial in the ESP, and if the ESP sends something the device will not show it.
The two bare examples works for me.
What I am doing wrong?
Thanks.
Code: Select all
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
//how many clients should be able to telnet to this ESP8266
#define MAX_SRV_CLIENTS
const char *ssid = "ESPap";
const char *password = "thereisnospoon";
WiFiServer server(23);
WiFiClient serverClients[MAX_SRV_CLIENTS];
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.print("Configuring access point...");
WiFi.softAP(ssid);
server.begin();
server.setNoDelay(true);
Serial.print("Ready! Use 'telnet ");
Serial.print(WiFi.softAPIP());
Serial.println(" 23' to connect");
}
void loop() {
uint8_t i;
//check if there are any new clients
if (server.hasClient()){
for(i = 0; i < MAX_SRV_CLIENTS; i++){
//find free/disconnected spot
if (!serverClients[i] || !serverClients[i].connected()){
if(serverClients[i]) serverClients[i].stop();
serverClients[i] = server.available();
Serial.print("New client: "); Serial.println(i);
continue;
}
}
//no free/disconnected spot so reject
WiFiClient serverClient = server.available();
serverClient.stop();
}
//check clients for data
for(i = 0; i < MAX_SRV_CLIENTS; i++){
if (serverClients[i] && serverClients[i].connected()){
if(serverClients[i].available()){
//get data from the telnet client and push it to the UART
while(serverClients[i].available()) Serial.write(serverClients[i].read());
}
}
}
//check UART for data
if(Serial.available()){
size_t len = Serial.available();
uint8_t sbuf[len];
Serial.readBytes(sbuf, len);
//push UART data to all connected telnet clients
for(i = 0; i < MAX_SRV_CLIENTS; i++){
if (serverClients[i] && serverClients[i].connected()){
serverClients[i].write(sbuf, len);
delay(1);
}
}
}
}