├── LICENSE ├── README.md └── WebSocketSerialMonitor.ino /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WebSocketSerialMonitor 2 | ESP8266 based serial-to-websockets proxy for OTA debugging 3 | 4 | Using this sketch and an extra ESP8266 module you can monitor the serial output of your ESP8266, Arduino or any other serial outputing device Over-the-Air, in a browser. 5 | 6 | ### Getting started 7 | 8 | - upload this sketch to your proxy ESP8266, the device you will attach to the serial terminals of the device to be monitored. make sure to set serial baud rate to be the same as your monitored device. Any 3rd party libs used are mentioned in the file. 9 | - connect the proxy module to your WiFi. It uses WiFiManager so if it can't connect it will start and access point for you to configure it. 10 | - connect the proxy ground to the monitored device ground and the proxy RX pin to the monitored device TX pin 11 | - open or download (from gh-pages branch) and open http://tzapu.github.io/WebSocketSerialMonitor/ and connect to your proxy module's ip on port 81 12 | 13 | That's it, you should see live serial data streaming from your devices. 14 | 15 | ### Future plans 16 | (if this proves useful to people) 17 | - add control of gpio pins so you can reset monitored module for instance 18 | - enable switching of baud rates on the fly 19 | - make the web page nicer and more app like 20 | - add MDNS for local name resolution 21 | - compress and concatenate files to be served straight from spiffs 22 | - add ability to download console page straight to spiffs on first connect, and update later on 23 | -------------------------------------------------------------------------------- /WebSocketSerialMonitor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WebSocketServer.ino 3 | 4 | Created on: 22.05.2015 5 | 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include //https://github.com/Links2004/arduinoWebSockets/tree/async 12 | #include 13 | 14 | #include 15 | #include 16 | #include //https://github.com/tzapu/WiFiManager 17 | 18 | WebSocketsServer webSocket = WebSocketsServer(81); 19 | 20 | void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght) { 21 | 22 | switch (type) { 23 | case WStype_DISCONNECTED: 24 | Serial.printf("[%u] Disconnected!\n", num); 25 | break; 26 | case WStype_CONNECTED: 27 | { 28 | IPAddress ip = webSocket.remoteIP(num); 29 | Serial.printf("[%u] Connected from %s url: %s\n", num, ip.toString().c_str(), payload); 30 | 31 | // send message to client 32 | webSocket.sendTXT(num, "Connected to Serial on " + WiFi.localIP().toString() + "\n"); 33 | } 34 | break; 35 | case WStype_TEXT: 36 | Serial.printf("[%u] get Text: %s\n", num, payload); 37 | 38 | // send message to client 39 | // webSocket.sendTXT(num, "message here"); 40 | 41 | // send data to all connected clients 42 | // webSocket.broadcastTXT("message here"); 43 | break; 44 | case WStype_BIN: 45 | Serial.printf("[%u] get binary lenght: %u\n", num, lenght); 46 | hexdump(payload, lenght); 47 | 48 | // send message to client 49 | // webSocket.sendBIN(num, payload, lenght); 50 | break; 51 | } 52 | 53 | } 54 | 55 | 56 | String inputString = ""; // a string to hold incoming data 57 | boolean stringComplete = false; // whether the string is complete 58 | 59 | void setup() { 60 | // Serial.begin(921600); 61 | Serial.begin(115200); 62 | 63 | //Serial.setDebugOutput(true); 64 | 65 | Serial.println(); 66 | Serial.println(); 67 | Serial.println(); 68 | 69 | //WiFiManager 70 | //Local intialization. Once its business is done, there is no need to keep it around 71 | WiFiManager wifiManager; 72 | 73 | //reset settings - for testing 74 | //wifiManager.resetSettings(); 75 | 76 | 77 | //tries to connect to last known settings 78 | //if it does not connect it starts an access point with the specified name 79 | //here "AutoConnectAP" with password "password" 80 | //and goes into a blocking loop awaiting configuration 81 | if (!wifiManager.autoConnect("AutoConnectAP", "password")) { 82 | Serial.println("failed to connect, we should reset as see if it connects"); 83 | delay(3000); 84 | ESP.reset(); 85 | delay(5000); 86 | } 87 | 88 | webSocket.begin(); 89 | webSocket.onEvent(webSocketEvent); 90 | 91 | Serial.println("START MIRRORING SERIAL"); 92 | Serial.println(WiFi.localIP()); 93 | 94 | // Serial.setTimeout(500); 95 | inputString.reserve(256); 96 | } 97 | 98 | void serialEvent() { 99 | while (Serial.available()) { 100 | char inChar = (char)Serial.read(); 101 | if (inChar == '\n') { 102 | stringComplete = true; 103 | return; 104 | } else { 105 | inputString += inChar; 106 | } 107 | } 108 | } 109 | 110 | 111 | void loop() { 112 | serialEvent(); 113 | if (stringComplete) { 114 | 115 | String line = inputString; 116 | // clear the string: 117 | inputString = ""; 118 | stringComplete = false; 119 | 120 | //line += '\n'; 121 | webSocket.broadcastTXT(line); 122 | Serial.println(line); 123 | } 124 | webSocket.loop(); 125 | /* 126 | String line = Serial.readStringUntil('\n'); 127 | if (line.length() > 0) { 128 | // add back line ending 129 | line += '\n'; 130 | webSocket.broadcastTXT(line); 131 | Serial.print(line); 132 | } 133 | webSocket.loop(); 134 | */ 135 | } 136 | 137 | --------------------------------------------------------------------------------