Browse Source

V1 Ready!

- Added ESP32 Example
- Finalized ESP8266 Example
- Improved Webpage
- Now textarea on webpage scrolls to bottom automatically
Ayush Sharma 5 years ago
parent
commit
cac5ecde6a

+ 2 - 0
.gitignore

@@ -1,5 +1,7 @@
 # Prerequisites
 *.d
+.vscode/
+webpage/
 
 # Object files
 *.o

BIN
docs/webserial.PNG


+ 40 - 0
examples/ESP32_Demo/ESP32_Demo.ino

@@ -0,0 +1,40 @@
+#include <Arduino.h>
+#include <WiFi.h>
+#include <AsyncTCP.h>
+#include <ESPAsyncWebServer.h>
+#include <WebSerial.h>
+
+AsyncWebServer server(80);
+
+const char* ssid = ""; // Your WiFi SSID
+const char* password = ""; // Your WiFi Password
+
+
+void recvMsg(uint8_t *data, size_t len){
+  WebSerial.println("Received Data...");
+  String d = "";
+  for(int i=0; i < len; i++){
+    d += char(data[i]);
+  }
+  WebSerial.println(d);
+}
+
+void setup() {
+    Serial.begin(115200);
+    WiFi.mode(WIFI_STA);
+    WiFi.begin(ssid, password);
+    if (WiFi.waitForConnectResult() != WL_CONNECTED) {
+        Serial.printf("WiFi Failed!\n");
+        return;
+    }
+    Serial.print("IP Address: ");
+    Serial.println(WiFi.localIP());
+    
+    WebSerial.begin(&server);
+    WebSerial.msgCallback(recvMsg);
+    server.begin();
+}
+
+void loop() {
+
+}

+ 40 - 0
examples/ESP8266_Demo/ESP8266_Demo.ino

@@ -0,0 +1,40 @@
+#include <Arduino.h>
+#include <ESP8266WiFi.h>
+#include <ESPAsyncTCP.h>
+#include <ESPAsyncWebServer.h>
+#include <WebSerial.h>
+
+AsyncWebServer server(80);
+
+const char* ssid = ""; // Your WiFi SSID
+const char* password = ""; // Your WiFi Password
+
+
+void recvMsg(uint8_t *data, size_t len){
+  WebSerial.println("Received Data...");
+  String d = "";
+  for(int i=0; i < len; i++){
+    d += char(data[i]);
+  }
+  WebSerial.println(d);
+}
+
+void setup() {
+    Serial.begin(115200);
+    WiFi.mode(WIFI_STA);
+    WiFi.begin(ssid, password);
+    if (WiFi.waitForConnectResult() != WL_CONNECTED) {
+        Serial.printf("WiFi Failed!\n");
+        return;
+    }
+    Serial.print("IP Address: ");
+    Serial.println(WiFi.localIP());
+    
+    WebSerial.begin(&server);
+    WebSerial.msgCallback(recvMsg);
+    server.begin();
+}
+
+void loop() {
+
+}

+ 5 - 0
keywords.txt

@@ -0,0 +1,5 @@
+KEYWORD1	WebSerial
+KEYWORD2	begin
+KEYWORD2	print
+KEYWORD2	println
+KEYWORD2	msgCallback

+ 9 - 0
library.properties

@@ -0,0 +1,9 @@
+name=WebSerial
+version=1.0.0
+author=Ayush Sharma
+category=Communication
+maintainer=Ayush Sharma <asrocks5@gmail.com>
+sentence=A Web based Serial Monitor to Debug without and Physical connection.
+paragraph=WebSerial is a webpage based Serial Monitor to log, monitor, or debug your code wirelessly.
+url=https://github.com/ayushsharma82/WebSerial
+architectures=esp8266,esp32

+ 162 - 0
src/WebSerial.h

@@ -0,0 +1,162 @@
+#ifndef WebSerial_h
+#define WebSerial_h
+
+#include "Arduino.h"
+#include "stdlib_noniso.h"
+#include <functional>
+
+#if defined(ESP8266)
+    #define HARDWARE "ESP8266"
+    #include "ESP8266WiFi.h"
+    #include "ESPAsyncTCP.h"
+    #include "ESPAsyncWebServer.h"
+#elif defined(ESP32)
+    #define HARDWARE "ESP32"
+    #include "WiFi.h"
+    #include "AsyncTCP.h"
+    #include "ESPAsyncWebServer.h"
+#endif
+
+#define BUFFER_SIZE 500
+
+#include "webserial_webpage.h"
+
+typedef std::function<void(uint8_t *data, size_t len)> RecvMsgHandler;
+
+
+class WebSerialClass{
+
+public:
+    void begin(AsyncWebServer *server, const char* url = "/webserial"){
+        _server = server;
+        _ws = new AsyncWebSocket("/webserialws");
+
+        _server->on(url, HTTP_GET, [](AsyncWebServerRequest *request){
+            // Send Webpage
+            AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", WEBSERIAL_HTML, WEBSERIAL_HTML_SIZE);
+            response->addHeader("Content-Encoding","gzip");
+            request->send(response);        
+        });
+
+        _ws->onEvent([&](AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) -> void {
+            if(type == WS_EVT_CONNECT){
+                #if defined(DEBUG)
+                    DEBUG_WEB_SERIAL("Client connection received");
+                #endif
+            } else if(type == WS_EVT_DISCONNECT){
+                #if defined(DEBUG)
+                    DEBUG_WEB_SERIAL("Client disconnected");
+                #endif
+            } else if(type == WS_EVT_DATA){
+                #if defined(DEBUG)
+                    DEBUG_WEB_SERIAL("Received Websocket Data");
+                #endif
+                if(_RecvFunc != NULL){
+                    _RecvFunc(data, len);
+                }
+            }
+        });
+
+        _server->addHandler(_ws);
+
+        #if defined(DEBUG)
+            DEBUG_WEB_SERIAL("Attached AsyncWebServer along with Websockets");
+        #endif
+    }
+
+    void msgCallback(RecvMsgHandler _recv){
+        _RecvFunc = _recv;
+    }
+
+    // Print
+
+    void print(String m = ""){
+        _ws->textAll(m);
+    }
+
+    void print(const char *m){
+        _ws->textAll(m);
+    }
+
+    void print(char *m){
+        _ws->textAll(m);
+    }
+
+    void print(int m){
+        _ws->textAll(String(m));
+    }
+
+    void print(uint8_t m){
+        _ws->textAll(String(m));
+    }
+
+    void print(uint16_t m){
+        _ws->textAll(String(m));
+    }
+
+    void print(uint32_t m){
+        _ws->textAll(String(m));
+    }
+
+    void print(double m){
+        _ws->textAll(String(m));
+    }
+
+    void print(float m){
+        _ws->textAll(String(m));
+    }
+
+
+    // Print with New Line
+
+    void println(String m = ""){
+        _ws->textAll(m+"\n");        
+    }
+
+    void println(const char *m){
+        _ws->textAll(String(m)+"\n");
+    }
+
+    void println(char *m){
+        _ws->textAll(String(m)+"\n");
+    }
+
+    void println(int m){
+        _ws->textAll(String(m)+"\n");
+    }
+
+    void println(uint8_t m){
+        _ws->textAll(String(m)+"\n");
+    }
+
+    void println(uint16_t m){
+        _ws->textAll(String(m)+"\n");
+    }
+
+    void println(uint32_t m){
+        _ws->textAll(String(m)+"\n");
+    }
+
+    void println(float m){
+        _ws->textAll(String(m)+"\n");
+    }
+
+    void println(double m){
+        _ws->textAll(String(m)+"\n");
+    }
+
+
+private:
+    AsyncWebServer *_server;
+    AsyncWebSocket *_ws;
+    RecvMsgHandler _RecvFunc = NULL;
+    
+    #if defined(DEBUG)
+        void DEBUG_WEB_SERIAL(const char* message){
+            Serial.println("[WebSerial] "+message);
+        }
+    #endif
+};
+
+WebSerialClass WebSerial;
+#endif

File diff suppressed because it is too large
+ 2 - 0
src/webserial_webpage.h


Some files were not shown because too many files changed in this diff