Websocket Client doesnt reconnect to Websocket Server

Hello together my name is Mo,

im totally new in Node Red. So please excuse me when i response with stupid questions :slight_smile:

I have a websocket server running on a esp32 and a node red websocket client on a pi. the connection is working well, but if i restart the esp then the client (node red) doesnt reconnect automatically. To reconnect the client, i have to restart the flows.
Is there a way to reconnect it automatically?

Thank you and nice greetz
Mo

Most people are putting ESP comms via MQTT which is designed for this kind of thing and is generally a lot more robust than a websocket connection.

I've not used NR's websocket to connect this way so I don't really know if it handles retries.

1 Like

Hey Julian,
thank you for your fast reply. I have tried MQTT already but i dont get a Connection to the Server. Websocket Server is already on the ESP. Thats why i choose this way. The problem with the MQTT could be the softAP Mode of the ESP or the Websocket Server.

I'm not an expert on ESP32, but: what prevents you from connecting mqtt over websockets?.
Based on your comments, I am guessing you're doing websockets over http, and this is why you need to reestablish the handshake.
Mqtt should be the transport used, as @TotallyInformation has already suggested.

1 Like

Hey Lu4t,

yes im using websocket over http. I didnt try mqtt over websockets.
Do you have some example?

Sorry, I don't understand why you aren't using MQTT directly. If there isn't a route to your normal MQTT broker, stand up another broker on the same device as Node-RED.

1 Like

Hey Julian,

i have an existing project on my ESP. There is a Webserver and Websocket Server implemented. MQTT i have tried at the beginning, but i cant get a connection to the broker. With only a example Project from the MQTT library (ESP), the connection to the broker was okay. But not with my existing project. I have to mention that the ESP is configuerd as an AccesssPoint and the Pi as a Wifi Client. Thats why i choose this way. If you would help me to get a connection with MQTT, i would be happy :slight_smile: sorry for my bad english grammar

EDIT: My MQTT broker and Node Red is running on the same device (PI). Theyy are working well. I have tried them with an MQTT Explorer from my Notebook

OK, that is likely the issue I guess, you'd have to look in detail at how the network is behaving to understand what is happening.

I truth though, I would have thought that it would be better ot use the Pi as the AP not the ESP since the Pi has a lot more umph and more capabilities.

1 Like

You are right, but in the beginnig i did not plan to connect the ESP with my network. To catch some values.

I think i have to go this way. maybe i have to reduce library by library!?
to find out the reason.

I would have thought that it is more likely a networking issue than a library one.

1 Like

Hey Julian,

i get a Connection between the MQTT Broker and the ESP. I have just configured the ESP as WiFiClient. I try to check why? I add a reconnect function and via Serial Connecton i can observe, if it is configured as an AP the WiFIClient dont get a Connection Feedback and dont connect the MQTT Client.

Thank you for your support.

Well the AP setting for ESP is generally only meant to handle an initial setup, it isn't meant to be a full-on WiFi provision - the ESP's aren't powerful enough for that really and they certainly aren't designed for that.

If you really wanted to have something that would work without a "proper" Wi-Fi in place, I would recommend using the ESPnow networking. Add another ESP with a serial connection to the Pi so that you can get data in/out and use that instead of MQTT between the ESPs and the Pi. ESPnow is a mesh network on the same frequencies as Wi-Fi.

Or just use the Pi as the AP if network coverage isn't an issue.

1 Like

Hey Julian,

I´ve heard about it. But i dont spend time to read about.
This sounds good for my next Project. There are 3 ESP´s.

For this issue i will do that.

Thank You again!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.