im totally new in Node Red. So please excuse me when i response with stupid questions
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?
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.
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.
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 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.
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.
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.