skaarj1989 / mWebSockets

WebSockets for microcontrollers
https://skaarj1989.github.io/mWebSockets/autobahn-testsuite/servers/
MIT License
104 stars 22 forks source link

WiFiEsp(AT) support #54

Closed guilhermeaiolfi closed 2 years ago

guilhermeaiolfi commented 2 years ago

Hi,

I just want to start the discussion about using your library with WiFiEspAT. I think that's the simplest way of using it for new fellows in the arduino world like me. None of the websocket libraries have compatibility with WiFiEsp or WiFiEspAT, I think that would be a big plus.

After somedays of learning arduino/C/mWebSocket /WiFiEspAT I was able to make it work. So it is definitely possible. The problem is that it is very unstable and it doesn't seems to be related to the communication with the ESP8266.

Depending on where and how many printf() I had in the code, the behavior changed. And it is always in the mWebSocket side. In one of those case in the WebSocket.cpp code:

if (header.length + offset >= kBufferMaxSize)
      return close(CloseCode::MESSAGE_TOO_BIG, true);

That was returning true for header.length = 5, offset = 0 and kBufferMaxSize = 256. Sometimes the arduino was simply halting in the middle of the code. But like I said, sometimes it works. I don't have any other board to test, but every other sketch works fine and consistently.

Anyhow, an interface with AT commands is something that you would be willing to support and do you have any idea what would be cause of those random behaviors?

skaarj1989 commented 2 years ago

@guilhermeaiolfi Looks like WiFiEspAT requires AT firmware version >= 1.7 so I tried to upgrade my ESP-01 module to 2.2.1.0 using ESP8266 Flash Downloader, unfortunately it fails at 96%, (burning the stock one succeeded).

UPDATE: Finally managed to upload firmware

Where did you get firmware? And which flasher do you use?

guilhermeaiolfi commented 2 years ago

Hi,

I had no luck with the ESP8266 Flash Downloader. But the ESPtool worked great. The images I tried were the ones linked in the wifiespat's readme. The most stable being the 1.7.4.

But I have good news, I manage to get a Mega 2560 + WiFi and after playing with it a little bit I was able to make mWebSocket work. The other good news is that it wasn't so many changes needed. I'll prepare a pull request sometime this week if you are interested.

lucademian commented 2 years ago

@guilhermeaiolfi I'd definitely appreciate if you shared, I'm currently trying to get working on the 2560 + WiFi and having trouble.

guilhermeaiolfi commented 2 years ago

@lucademian I haven't had the time to prepare a PR yet. But I've sent my changes to a public repo just to get you started: https://github.com/guilhermeaiolfi/mwebsockets

See that I disabled support for other platforms while working on it. But as you'll see, there are very few changes necessary. I hope it helps you for the time being.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.