Ethernet relay connect cloud by TCP or MQTT? which stable?

i have a ethernet relay, STM32 chip,now it's work with TCP socket by private text protocol.

i want to ask , can i install Node-Red on the cloud server, then

1: relay board work as TCP Client connect with cloud server.
2: relay board (i write new code for STM32) use MQTT connect with cloud server.

whicl solution is stable and better?

An STM32 is an embedded microcontroller. Unless you have it in a single board computer capable of running Linux, you will not be able to run Node-RED on it. I doubt it would run an MQTT broker either.

What cloud server, you haven't said, you've only mentioned the STM32.

You need to tell us about the board, not just the processor, nobody can guess what your board is capable of.

Your 2 options aren't really well explained I'm afraid.

  1. A TCP client to do what? Do you mean to act as a router? An embedded microprocessor would make for a poor router.
  2. "MQTT connect", how, what will it do? Do you mean that you want the board to act as an MQTT relay? It is potentially possible to do that as long as you can find a library that will let you connect to 2 brokers at once. Then subscribing to topics on the source side could trigger messages to be send on the target side. If you wanted that to be 2-way, you would then need to subscribe to the target and update the source as well (more code). Really, it would be better to use a proper MQTT Broker which will be able to do that routing for you automatically. Again, you need a full general purpose computer for that (e.g. a Pi)

sorry,more information is:

1: relay board work as TCP Client connect with cloud server.

relay board is a ethernet board, it can work as "TCP Client" mode, if buy a Amazon cloud server, install Node-Red on the server, then set server IP and port for ethernet relay board. When relay board power on, it will auto connect to Amazon cloud server, so that can remote control the relay by Amazon cloud server. I don't want add Pi.

2:relay board (i write new code for STM32) use MQTT connect with cloud server.

I can write MCU code of STM32 , let etherner relay board support MQTT protocol. Let ethernet relay board connect to Node-Red(have installed on Amazon cloud server) by MQTT node.

OK, so the relay board is a local mcu with a relay switch that is controlled directly from a cloud server (AWS based). That is now clearer.

Yes, you can install Node-RED on the cloud server of course.

MQTT is likely to be more stable than a direct TCP connection since it supports reconnections and (somewhat) guaranteed delivery of messages. Of course, that is at the expense of a more complex cloud server configuration since you now need to install, configure and maintain an MQTT broker in addition to Node-RED.

You will also need to pay very careful consideration to the security of both your relays and the cloud server. Make sure that all traffic, including initial connections/handshakes are over strongly encrypted links (TLS), move well-known TCP/IP ports to alternatives to reduce attacks, install and configure an OS-level firewall on the cloud server and also install and configure fail2ban to help prevent brute-force attacks. For TLS use, you will also want to install and configure acme.sh and set up Let's Encrypt.

Poorly secured cloud servers and Internet connected IoT devices are the bane of the internet, please don't add to the problem even if you don't care about your own security.

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