telnet server do not send all data incomming from uart
Posted: Sat Sep 30, 2017 2:26 am
hello
I'm looking for stable uart-wifi bridge and ip stuck on arduino looks ok, but i have problem with long string.
esp setup like AP and another client on esp connect to him.
Connection is stable, but i have problem with received data from server.
When string is short (e.g 20 chars), is it ok.
But when i like to send little longer strings and ended "new line" e.g:
"SET BT PAIR 44:78:3e:5b:09:8d e6b99798dee8dd66c7f0be1098013c88
SET BT PAIR 44:78:3e:5b:09:85 e6b99798dee8dd66c7f0be1098013c88
SET BT PAIR 44:78:3e:5b:09:87 e6b99798dee8dd66c7f0be1098013c88'
on client i got only:
SET BT PAIR 44:78:3e:5b:09:8d e6b99798dee8dd66c7f0be1098013c88
SET BT PAIR 44:78
and cut.
All string has on end \n\r and i see next data on new line, but not all..
What can i do wih this?
code:
#include <ESP8266WiFi.h>
//how many clients should be able to telnet to this ESP8266
#define MAX_SRV_CLIENTS 3
const char* ssid = ".........";
const char* password = "......";
WiFiServer server(23);
WiFiClient serverClients[MAX_SRV_CLIENTS];
void setup() {
Serial1.begin(115200);
delay(1000);
Serial.begin(115200);
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
// start telnet server
server.begin();
server.setNoDelay(true);
}
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();
Serial1.print("New client: "); Serial1.print(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);
}
}
}
}
I'm looking for stable uart-wifi bridge and ip stuck on arduino looks ok, but i have problem with long string.
esp setup like AP and another client on esp connect to him.
Connection is stable, but i have problem with received data from server.
When string is short (e.g 20 chars), is it ok.
But when i like to send little longer strings and ended "new line" e.g:
"SET BT PAIR 44:78:3e:5b:09:8d e6b99798dee8dd66c7f0be1098013c88
SET BT PAIR 44:78:3e:5b:09:85 e6b99798dee8dd66c7f0be1098013c88
SET BT PAIR 44:78:3e:5b:09:87 e6b99798dee8dd66c7f0be1098013c88'
on client i got only:
SET BT PAIR 44:78:3e:5b:09:8d e6b99798dee8dd66c7f0be1098013c88
SET BT PAIR 44:78
and cut.
All string has on end \n\r and i see next data on new line, but not all..
What can i do wih this?
code:
#include <ESP8266WiFi.h>
//how many clients should be able to telnet to this ESP8266
#define MAX_SRV_CLIENTS 3
const char* ssid = ".........";
const char* password = "......";
WiFiServer server(23);
WiFiClient serverClients[MAX_SRV_CLIENTS];
void setup() {
Serial1.begin(115200);
delay(1000);
Serial.begin(115200);
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
// start telnet server
server.begin();
server.setNoDelay(true);
}
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();
Serial1.print("New client: "); Serial1.print(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);
}
}
}
}