From 5b9f3835b9f27d84357838d3996b1e09fc144490 Mon Sep 17 00:00:00 2001 From: luc lebosse Date: Fri, 17 Apr 2015 23:02:28 +0800 Subject: [PATCH] Add backbone for Web interface and Data Interface Web Server listen on port 80 Data Bridge listen on port 8888 may need to allow configuration of this port in settings - TBD --- esp8266/datainterface.cpp | 32 ++++++++++++++++++++++++++++++++ esp8266/datainterface.h | 39 +++++++++++++++++++++++++++++++++++++++ esp8266/esp8266.ino | 30 ++++++++++++++++++++++++------ esp8266/webinterface.cpp | 32 ++++++++++++++++++++++++++++++++ esp8266/webinterface.h | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 esp8266/datainterface.cpp create mode 100644 esp8266/datainterface.h create mode 100644 esp8266/webinterface.cpp create mode 100644 esp8266/webinterface.h diff --git a/esp8266/datainterface.cpp b/esp8266/datainterface.cpp new file mode 100644 index 00000000..dadf2b09 --- /dev/null +++ b/esp8266/datainterface.cpp @@ -0,0 +1,32 @@ +/* + 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 +#include +#include + +DATAINTERFACE_CLASS::DATAINTERFACE_CLASS (int port):WebServer(port) +{ +} + +DATAINTERFACE_CLASS data_interface(8888); + diff --git a/esp8266/datainterface.h b/esp8266/datainterface.h new file mode 100644 index 00000000..cf97a234 --- /dev/null +++ b/esp8266/datainterface.h @@ -0,0 +1,39 @@ +/* + 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 +#include +#include +#include + +class DATAINTERFACE_CLASS +{ + public: + DATAINTERFACE_CLASS (int port = 8888); + ESP8266WebServer WebServer; + private: + +}; + +extern DATAINTERFACE_CLASS data_interface; + +#endif diff --git a/esp8266/esp8266.ino b/esp8266/esp8266.ino index 9638e208..56edc648 100644 --- a/esp8266/esp8266.ino +++ b/esp8266/esp8266.ino @@ -14,12 +14,13 @@ You should have received a copy of the GNU General Public License along with Repetier-Firmware. If not, see . - This firmware is using the arduino IDE modified to support ESP8266: + This firmware is using the standard arduino IDE with module to support ESP8266: + https://github.com/sandeepmistry/esp8266-Arduino based on : https://github.com/esp8266/Arduino Latest version of the code and documentation can be found here : https://github.com/luc-github/ESP8266 - + Main author: luc lebosse */ @@ -33,8 +34,14 @@ //includes: why EEPROM.h need to be there ??? #include #include "config.h" -#include "ESP8266WiFi.h" #include "wifi.h" +#include "webinterface.h" +#include "datainterface.h" +#include +#include +#include + + void setup() { // init : delay(8000); @@ -69,12 +76,23 @@ void setup() { Serial.begin(baud_rate); //setup wifi according settings wifi_config.Setup(); + delay(1000); + //define interfaces + //TODO move this to class + web_interface.WebServer.on("/", [](){web_interface.WebServer.send(200, "text/plain", "this works as well - port 80");}); + data_interface.WebServer.on("/", [](){data_interface.WebServer.send(200, "text/plain", "this works as well - port 8888");}); + //start interfaces + web_interface.WebServer.begin(); + data_interface.WebServer.begin(); + CONFIG::print_config(); } //main loop void loop() { - - delay (1000); - CONFIG::print_config(); +//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(); + } diff --git a/esp8266/webinterface.cpp b/esp8266/webinterface.cpp new file mode 100644 index 00000000..1c1314a3 --- /dev/null +++ b/esp8266/webinterface.cpp @@ -0,0 +1,32 @@ +/* + webinterface.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 "webinterface.h" +#include +#include +#include + +WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port) +{ +} + +WEBINTERFACE_CLASS web_interface(80); + diff --git a/esp8266/webinterface.h b/esp8266/webinterface.h new file mode 100644 index 00000000..ebfd740b --- /dev/null +++ b/esp8266/webinterface.h @@ -0,0 +1,39 @@ +/* + webinterface.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 WEBINTERFACE_h +#define WEBINTERFACE_h +#include +#include +#include +#include + +class WEBINTERFACE_CLASS +{ + public: + WEBINTERFACE_CLASS (int port = 82); + ESP8266WebServer WebServer; + private: + +}; + +extern WEBINTERFACE_CLASS web_interface; + +#endif