-
Notifications
You must be signed in to change notification settings - Fork 132
Web Socket Support #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think it would make more sense if I check for a websocket connection in the end of the state: STATE_REQUEST_FINISHED, right? |
After thinking again about the right approach I think it would be correct if I check in the end of the state "STATE_REQUEST_FINISHED" for the prerequisites of a websocket and set an internal flag (e.g.: HttpsConnection._isWebsocket). In the state "HEADERS_FINISHED" I can invoke the callback of the matching node and do activate the websocket handler. |
Yes your are right. By "in state Regarding the handling on the second core: I would prefer to let the user of the library decide on where to handle the traffic, as the separation might not be ideal for every user and not every ESP32 module supports two cores (as far as I know). Do you have something in mind how to achieve it? |
Until now I did not deeply think about how to implement it. But as you suggested I will identify the websocket initiation in the state "STATE_REQUEST_FINISHED" and then set the state "STATE_WEBSOCKET". In the state "STATE_WEBSOCKET" I will do the websocket initiation handshake and then launch a separate FreeRTOS task (using "xTaskCreatePinnedToCore") which reads from and writes to the created websocket. Here I need to take care about the websocket frame and I will have to handle some opcodes like close, ping, pong, continue and text (or binary). Until now I have never done this before but I would like to try if I can succeed. |
I think that's a feasible way to implement the web sockets initially, but on long term I would make the task separation optional or let the library user do it, as new tasks means to reserve more memory for the task's stack etc. – I think that depending on the use case, waiting a bit longer for a response but having more common memory available might be the better side of this trade-off. However, if you'd like to work on that feature and that's the best option for your scenario, go for it. I might generalize that later on. At the moment I don't have any coding requirements, especially I did not use any coding style guide etc. for myself by now and I doubt that there would be one matching the existing code... |
I think you are right - my use case is quite special and the https server library should be more general. So, I will first implement it using your loop functionality. |
I'm currently implementing support for middleware functions (see #10) because I need them for one project I'm working on. The way I do it is to use the |
I am now starting to implement the websocket functionality but I am already stuck at the very beginning: |
That was a part I changed for #17, because there are differences in the API for checking if there are input bytes remaining depending of the protocol you use (plain sockets vs. ssl sockets). I did not encounter any problem without that call, so I dropped it to make the code less complex. But I can integrate it again, so that you can try if that fixes your problem. Currently I'm working on restructuring the repository so that it can directly be used as an Arduino library (mostly renaming directories and creating example sketches). If you wouldn't mind, I'd like to finish that first and then fix this bug. |
I am not in a hurry. Just inform me when you are ready. |
I added the call to SSL_pending() again. Furthermore, if you run into size limits while parsing the headers, have a look at |
Your correction concerning SSL_pending() works. Thanks for that. |
The examples in the repository only include a very basic code for the wifi handling, to focus on the server itself. So the connection is made once, but not restored if it gets lost. Basically you have something like this in the WiFi.begin(WIFI_SSID, WIFI_PSK);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
} In addition to that, you would have to check for if (WiFi.status() != WL_CONNECTED) {
WiFi.disconnect();
Serial.println("Reconnecting WiFi");
WiFi.begin(WIFI_SSID, WIFI_PSK);
while(WiFi.status() != WL_CONNECTED) {
Serial.println(".");
delay(100);
}
} I'm facing the same problem since recently, but as it occurs for other sketches as well and it correlates with a recent router update, I thought that the update was causing the problem. |
Maybe this is a stupid question: in the constructor for ResourceNode you scan for URL parameters starting with "/*". According to my understanding URL parameters start with "?". Or am I mixing something, e.g. with queries? |
It's maybe a naming issue, as there's no official name for the URL wildcards. |
Unfortunately I am currently running into a strange compilation error:
Where ResourceNode.hpp and ResolvedResource.hpp are not modified by me - so, it should compile like normal. |
If I understand the Sloeber issue correctly, it's caused by Windows file system limitations which makes it hard for me to reproduce, but I experienced similar problems with Eclipse in the past. VSCode works for me as an alternative IDE. Combining it with Platform IO might be a good idea for you as it supports both, Arduino builds and those for plain esp-idf and makes it easy to setup build paths etc. Issue #8 has some info on how to use the lib with Platform IO and ESP32/Arduino as target, most of the refactoring by Thorsten is already part of this repo, and you might use his library.json to complete it. |
Now I synced again against your latest sources. The files ResourceNode.hpp and ResolvedResource.hpp are still the same as in your repository. But I still get the same error message:
But now I see that in eclipse the contents of the file ResolvedResource.hpp has a grey background like when it is excluded from compile by an |
I would expect that only if Did you run Project → Clean and deleted the Otherwise, hovering an |
Running Project → Clean and delete the Release folder did not help. |
I see that I get the error even with an almost empty Websocket.hpp file being included in the main application file. |
I can give it a try. If attaching the files does not work and they are too long to put them inline, you may send them to [email protected]. |
The server should support web sockets (see #9 for reference).
The text was updated successfully, but these errors were encountered: