khoih-prog / WebSockets2_Generic

A WebSocket Server and Client library for Arduino, based on RFC6455, for writing modern Websockets applications. Now support ESP8266, ESP32 (including ESP32-S2 Saola, AI-Thinker ESP-12K, WT32_ETH01, etc.), nRF52, SAMD21, SAMD51, SAM DUE, STM32F/L/H/G/WB/MP1, Teensy, RP2040-based, etc. boards, with WiFiNINA, Teensy 4.1 NativeEthernet/QNEthernet, Ethernet W5x00 / ENC28J60 / LAN8742A / LAN8720, ESP8266 / ESP32-AT modules/shields, as well as SINRIC / Alexa / Google Home
GNU General Public License v3.0
81 stars 30 forks source link

Portenta WiFi Websockets tested lately? #61

Closed hpssjellis closed 1 year ago

hpssjellis commented 1 year ago

Hi @khoih-prog any idea if anyone has lately tested the PortentaH7 with this library. I can't seem to get websocket type chat working.

I do use a web based websocket server, but that shouldn't be the issue. If I use 2 Portenta's is there an easily way to test if they are working?

I am using this example folder

https://github.com/khoih-prog/WebSockets2_Generic/tree/master/examples/Generic/Portenta_H7/WiFi

I really just want an SSL websocket client, but should I just be able to test one Portenta as a client and one as the server?

Actually that seems fairly simple. I will test that out.

......

Ok I tested the Portenta server and client. Looked fairly easy to understand. But no connection


Connected to Wifi, IP address: 192.168.137.36
Connecting to WebSockets Server @192.168.137.128
[WS] WebsocketsClient::connect: not _connectionOpen, host = 192.168.137.128 , port = 8080
Not Connected!

Any idea why?

khoih-prog commented 1 year ago

HI @hpssjellis

Sorry I don't have 2 Portenta_H7 to test, but you can help yourself by turning on the _WEBSOCKETS_LOGLEVEL_ level to 4 and figure out what's wrong

I'm testing OK here using PC WS server

Starting Portenta_H7-Client using WiFi on PORTENTA_H7_M7
WebSockets2_Generic v1.13.2
Connecting to SSID: HueNet
Connected to Wifi, IP address: 192.168.2.128
Connecting to WebSockets Server @192.168.2.30
[WS] WebsocketsClient::generateHandshake: base64Authorization = 
[WS] WebsocketsClient::generateHandshake: handshake = GET / HTTP/1.1
Host: 192.168.2.30
Sec-WebSocket-Key: MDEyMzQ1Njc4OWFiY2RlZg==
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
User-Agent: TinyWebsockets Client
Authorization: Basic 
Origin: https://github.com/khoih-prog/Websockets2_Generic

[WS] WebsocketsClient::connect: base64Authorization = 
[WS] WebsocketsClient::generateHandshake: key = Upgrade
[WS] WebsocketsClient::generateHandshake: value = websocket
[WS] WebsocketsClient::generateHandshake: key = Connection
[WS] WebsocketsClient::generateHandshake: value = Upgrade
[WS] WebsocketsClient::generateHandshake: key = Sec-WebSocket-Accept
[WS] WebsocketsClient::generateHandshake: value = BACScCJPNqyz+UBoqMH89VmURoA=
[WS] WebsocketsClient::generateHandshake: key = Origin
[WS] WebsocketsClient::generateHandshake: value = https://github.com/khoih-prog/Websockets2_Generic
Connnection Opened
Connected!
Got Message: Hello to Server from PORTENTA_H7_M7
Got a Ping!
Got a Ping!
Got a Ping!
...

So the issue is normally in the bad Server code or Client-Server mismatch (IP, port, etc.)

Good Luck,

hpssjellis commented 1 year ago

Thanks so much @khoih-prog so frustrating when things aren't working. Level 4 debug makes a lot of sense and using a seperate server is a good idea. I will keep testing. Great to know your code works on the Portenta. Thanks!

hpssjellis commented 1 year ago

At least I understand the issue now. The ws server I am running is secure, your wifi client example is for an insecure websocket. I tried connectSecure but that doesn't seem to solve it. I will try making an insecure websocket server and see how I do.

hpssjellis commented 1 year ago

@khoih-prog you are correct, I tested your server client with 2 Portenta and it works fine. I am a bit confused if they use an in-secure or secure SSL connection. I will mess around with it and see if I can get your server working with an SSL connection. I Any suggestions?

khoih-prog commented 1 year ago

@hpssjellis

To use SSL / WSS, you have to adapt examples, written either for ESP32 or ESP8266 to Portenta

  1. Secured-Esp32-Client
  2. Secured-Esp8266-Client
  3. ESP8266/SecuredTwoWay-Esp8266-Client

AFAIK, Portenta doesn't have built-in Root CA-Certs inside core firmware, you have to do more research on SSL and how to add those CA-Certs into Portenta.

Have a look at my other EthernetWebServer_SSL library for SSL / CA Certs, etc.

I'm sorry I haven't worked on Portenta recently and didn't add SSL-enabled examples to it. Hopefully you'll do it when everything is OK there.