- Sat Dec 12, 2015 3:06 pm
#36284
The code below is in 2 chunks.. 1st .arduino 1de 1.6.5 for the esp8266 and 2nd Processing
It sends 100 18 char packets and takes over 10 secs to do it......180 chars per sec or 1800 baud
I must be doing something wrong for it to be this slow.
Anyone have advice?
[code]
/*
WiFiTelnetToSerial - Example Transparent UART to Telnet Server for esp8266
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
This file is part of the ESP8266WiFi library for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <ESP8266WiFi.h>
//#include <WiFi.h>
//how many clients should be able to telnet to this ESP8266
extern "C" {
#include "user_interface.h"
}
#define MAX_SRV_CLIENTS 1
const char* ssid = "xxxxxxxx";
const char* password = "xxxxxxx";
WiFiServer server(23);
WiFiClient serverClients[MAX_SRV_CLIENTS];
uint16_t posts=0;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
// WiFi.sta.setip(ip="33.42.0.20",netmask="255.255.255.0",gateway="33.42.0.254")
Serial.print("\nConnecting to "); Serial1.println(ssid);
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);
while(1) delay(500);
}
//start UART and the server
server.begin();
server.setNoDelay(true);
Serial.print("Ready! Use 'telnet ");
Serial.print(WiFi.localIP());
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: "); Serial1.print(i);
continue;
}
}
//no free/disconnected spot so reject
WiFiClient serverClient = server.available();
serverClient.stop();
}
posts++;
size_t len = 18;
char sbuf[18]="abcdefghijklmno\n\r";
char tbuf[18]="100 sent \n\r";
for(i = 0; i < MAX_SRV_CLIENTS; i++)
{
if (serverClients[i] && serverClients[i].connected())
{
if (posts<100)
{
serverClients[i].write((char*) &sbuf, len);
//// needs the datastructure and its length (char*) defines the pointer's type for idexing
//// and &sbuf is the address
}
else
{
serverClients[i].write((char*) &tbuf, len);
//// needs the datastructure and its length (char*) defines the pointer's type for idexing
//// and &sbuf is the address
}
}
}
if( posts==100)
{posts=0;
delay(5000);
}
}[/code]
[code]import processing.net.*;
Client myClient;
String dataIn;
void setup() {
size(300, 300);
background(0); // black background
textSize(30);
// Connect to the local machine at port 21 Telnet.
// This example will not run if you haven't
// previously started a server on this port.
myClient = new Client(this, "33.42.0.109", 23);
}
void draw()
{
//// somewhat like loop it will keep us alive allowing the isr on client event interrupt to do the work
}
// ClientEvent message is generated when the server
// sends data to an existing client.
void clientEvent(Client myClient)
{
while (myClient.available() > 0)
{
dataIn = myClient.readString();
print (dataIn);
}
}[/code]