Giter Club home page Giter Club logo

Comments (20)

me-no-dev avatar me-no-dev commented on July 17, 2024 1

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.

me-no-dev avatar me-no-dev commented on July 17, 2024

ok, let's see if I understand correctly :)

  1. You are sending everything you get over the web socket to the serial
  2. You read the serial into a string until you reach your termination char > and you send that to the web socket
  3. 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.

me-no-dev avatar me-no-dev commented on July 17, 2024

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.

indev2 avatar indev2 commented on July 17, 2024

@me-no-dev

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.

me-no-dev avatar me-no-dev commented on July 17, 2024

Trains! Exciting :)
If you are able to minify, combine and gzip the files, I can promise you under 1 second load time ;)

from espasyncwebserver.

hallard avatar hallard commented on July 17, 2024

@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.

me-no-dev avatar me-no-dev commented on July 17, 2024

the included index.htm in the example is actually a WebSocket terminal that you can use to test the data.

from espasyncwebserver.

hallard avatar hallard commented on July 17, 2024

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.

hallard avatar hallard commented on July 17, 2024

@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.

me-no-dev avatar me-no-dev commented on July 17, 2024

it's mostly this

from espasyncwebserver.

indev2 avatar indev2 commented on July 17, 2024

@me-no-dev

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.

me-no-dev avatar me-no-dev commented on July 17, 2024

thanks for the kind words and please let me know what your final results are :)

from espasyncwebserver.

hallard avatar hallard commented on July 17, 2024

@me-no-dev
I forked your repo, will do a PR for a nice terminal to serial with websocket example ;-)

from espasyncwebserver.

me-no-dev avatar me-no-dev commented on July 17, 2024

@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.

hallard avatar hallard commented on July 17, 2024

@me-no-dev you mean talking about example filename?

from espasyncwebserver.

me-no-dev avatar me-no-dev commented on July 17, 2024

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.

hallard avatar hallard commented on July 17, 2024

ok got it, just this file to avoid build test for the wrong platform, thanks

from espasyncwebserver.

indev2 avatar indev2 commented on July 17, 2024

@me-no-dev

for sure I'm always checking in regularly around here ;-)

from espasyncwebserver.

hallard avatar hallard commented on July 17, 2024

Hey guys,
works fine terminal connected to Serial Monitor talking websocket with nice terminal jquery ;-)
image

I'm creating PR

from espasyncwebserver.

hallard avatar hallard commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.