mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-15 15:56:05 +08:00
Add bridge support based on WifiTelnetToSerial
Remove useless datainterface files
This commit is contained in:
parent
72b4d5df71
commit
9a88756b20
@ -1,40 +0,0 @@
|
||||
/*
|
||||
datainterface.cpp - esp8266 configuration class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
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 "config.h"
|
||||
#include "datainterface.h"
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
//cannot put it in class then cast it as std::function<void(void)> so put outside
|
||||
void handle_data_interface_root()
|
||||
{
|
||||
data_interface.WebServer.send(200, "text/html", "hello from esp8266 from port 8888 ");
|
||||
}
|
||||
|
||||
DATAINTERFACE_CLASS::DATAINTERFACE_CLASS (int port):WebServer(port)
|
||||
{
|
||||
//init what will handle "/"
|
||||
WebServer.on("/",HTTP_GET, handle_data_interface_root);
|
||||
}
|
||||
|
||||
DATAINTERFACE_CLASS data_interface(8888);
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
datainterface.h - esp8266 configuration class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#ifndef DATAINTERFACE_h
|
||||
#define DATAINTERFACE_h
|
||||
#include <Arduino.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
class DATAINTERFACE_CLASS
|
||||
{
|
||||
public:
|
||||
DATAINTERFACE_CLASS (int port = 8888);
|
||||
ESP8266WebServer WebServer;
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
extern DATAINTERFACE_CLASS data_interface;
|
||||
|
||||
#endif
|
@ -32,7 +32,6 @@
|
||||
#include "config.h"
|
||||
#include "wifi.h"
|
||||
#include "webinterface.h"
|
||||
#include "datainterface.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
@ -42,6 +41,9 @@
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#define MAX_SRV_CLIENTS 1
|
||||
WiFiServer server(8888);
|
||||
WiFiClient serverClients[MAX_SRV_CLIENTS];
|
||||
|
||||
void setup() {
|
||||
// init :
|
||||
@ -76,7 +78,8 @@ void setup() {
|
||||
delay(1000);
|
||||
//start interfaces
|
||||
web_interface.WebServer.begin();
|
||||
data_interface.WebServer.begin();
|
||||
server.begin();
|
||||
server.setNoDelay(true);
|
||||
}
|
||||
|
||||
|
||||
@ -89,5 +92,41 @@ void loop() {
|
||||
//web requests
|
||||
web_interface.WebServer.handleClient();
|
||||
//TODO use a method to handle serial also in class and call it instead of this one
|
||||
data_interface.WebServer.handleClient();
|
||||
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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user