Comments (20)
Here is a fully async WebSocket to Serial implementation to fit in your sketch
AsyncWebServer server(80);
AsyncWebSocket webSocket("/ws");// url will be ws://esp-ip/ws
void onEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
if(type == WS_EVT_DATA){
//you have received a message from a WebSocket Client
for(size_t i=0; i < len; i++){
Serial.write(data[i]);
}
}
}
void setup(){
//.... your setup before the WebServer stuff
webSocket.onEvent(onEvent);
server.addHandler(&webSocket);
//setup the rest of the server
}
void loop() {
serialEvent();
if (stringComplete) {
String reply = inputString;
inputString = "";
stringComplete = false;
webSocket.textAll(reply);
}
}
from espasyncwebserver.
ok, let's see if I understand correctly :)
- You are sending everything you get over the web socket to the serial
- You read the serial into a string until you reach your termination char
>
and you send that to the web socket - You want to have that same functionality running with the AsyncWebServer
Have you looked at the latest code? It has Async WebSocket built-in :) or maybe that is the trouble you are having?
from espasyncwebserver.
One action you can take to battle large content size is to combine and gzip it. Some cache headers for static content are also good option to use in conjunction.
If you have a static HTML file that includes some css and javascript files also served from the server and no other page uses those files, you are better off just combining the code into a single file and gzipping it. You will save lots of space and gain much speed. Compressing the javascript before including it is also a good idea :) I use https://javascript-minifier.com
If for example you request /index.htm
and /index.htm.gz
exists instead, it will automatically be served to the client with appropriate mime-type and encoding headers.
from espasyncwebserver.
Wow. Thank you so much for the rapid response.
Yes you have it right about what I need to do. And thank you for the gzip suggestion for the page and files. I must say your firmware can already serve my 7 files in under 3 seconds so to improve on that would be amazing.
It will be several hours before I can get back to you and test the code (work commitments). Thank you so much for now.
Here is my project discussion at post #1177 http://www.trainboard.com/highball/index.php?threads/introducing-dcc-a-complete-open-source-dcc-station-and-interface.84800/page-59
My Github files are not up to date.
Indev2
from espasyncwebserver.
Trains! Exciting :)
If you are able to minify, combine and gzip the files, I can promise you under 1 second load time ;)
from espasyncwebserver.
@indev2
Strange we're working on the same thing, I modified te Telnet2Serial sample to have both telnet and ansync websockets working, not best way but works as an example ;-) you can telnet 23 or using html page with async web socket (as @me-no-dev done) or both same time.
But code is at home computer now (f**** onedrive sync bug !!!)
I'll post full sample code with html and js file later!!
from espasyncwebserver.
the included index.htm in the example is actually a WebSocket terminal that you can use to test the data.
from espasyncwebserver.
hey man, thank you so much, I missed that great one, exactly what I wanted to do I left my memories on old fsbrowser that did not had this great console ;-)
shame on me ;-)
from espasyncwebserver.
@me-no-dev
do you have the un-minified version of edit.htm file ? I would like to add text to remind the shortcut keyboard to save edited file ;-)
from espasyncwebserver.
it's mostly this
from espasyncwebserver.
Many thanks for your help. I set things up as you suggested and got it working first time. Turns out I was very close in my own efforts before asking you here, I'd just not got the .textAll function quite right.
For others who may be interested, the above code examples are a working solution if you need to feed your 'Serial in' data on through the webSocket, at least for short messages.
For now the original issue is resolved and this can be closed.
Thanks again me-no-dev, I shall be moving on to implement your other suggestions regarding file compression. You get a big thumbs up from me for your excellent work here ;-)
I shall be bringing my project files up to date with this major update in the next few days.
Kind Regards
indev2
from espasyncwebserver.
thanks for the kind words and please let me know what your final results are :)
from espasyncwebserver.
@me-no-dev
I forked your repo, will do a PR for a nice terminal to serial with websocket example ;-)
from espasyncwebserver.
@hallard note how the current example is made for both platforms and do it the same way even if only for 8266 or the travis build will fail for it :)
from espasyncwebserver.
@me-no-dev you mean talking about example filename?
from espasyncwebserver.
there is a .esp31b.skip
file inside the ESP8266 example and a similar one for the ESP32 to let travis know not to compile against the wrong core
from espasyncwebserver.
ok got it, just this file to avoid build test for the wrong platform, thanks
from espasyncwebserver.
for sure I'm always checking in regularly around here ;-)
from espasyncwebserver.
Hey guys,
works fine terminal connected to Serial Monitor talking websocket with nice terminal jquery ;-)
I'm creating PR
from espasyncwebserver.
Hi Guys,
Project is now stored and available on my github, really thanks for this great and serious lib done by @me-no-dev
https://github.com/hallard/WebSocketToSerial
from espasyncwebserver.
Related Issues (20)
- fragmentation
- ESP8266 goin down when get JSON string. HOT 1
- where i can get request if i mast send JSON to all connected clients by timer ?! no good exapmles no information! HOT 2
- Serving SPIFFS from a subdirectory raises 500 status code on some files HOT 1
- error: cannot bind non-const lvalue reference of type 'ArduinoJson::V704PB2::JsonObject&' to an rvalue of type 'ArduinoJson::V704PB2::detail::enable_if<true, ArduinoJson::V704PB2::JsonObject>::type' {aka 'ArduinoJson::V704PB2::JsonObject'} HOT 1
- abracadabra in serial HOT 1
- after long time 8+ i have spam in serial
- AsyncWebServerRequest Questions HOT 2
- Send content with beginChunkedResponse
- Question: is it possible to replicate AsyncWebSocket with WebServer in arduino-esp32 v3.0.0 ? HOT 4
- AsyncWebServer Questions HOT 6
- Images won't load randomly
- Compiling issues HOT 7
- I Can't make the web explorer to offer to save credentials
- Change bool AsyncStaticWebHandler::canHandle to use exact match instead of String::startsWith(_uri)
- small ddos (press F5) crash: async_tcp ....watchdog got triggered HOT 1
- Compilation Error for Newer ESP32 HOT 3
- possible memory leak at send_p?
- Forwarding Webserver with websockets
- Get new client ID at every refresh :( HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from espasyncwebserver.