Send data using WLAN from Serial control node (ttyUSB0) from Raspberry Pi Zero W to a Raspberry Pi 4B

Hi all,

currently I use the serial control node (ttyUSB0) of a Raspberry Pi 4B (1) to read data from a directly connected heating device and showing this data in a Node-RED dashboard.

However, since the rpi4B (1) is actually supposed to be placed elsewhere, I would like to move this tasks to another device, such as the Raspberry Pi Zero W (2), which will then transmit the data to the rpi4B (1) via WLAN.

I have the following questions for anyone who is interested in this topic or already familiar with it:

Will Node-RED and the functions I need for the described use case above (using serial node & sending data using WLAN) run on the rPi0W (2)?

Which Pi OS do I need to install onto the rPi0W?
Which type (32bit or 64bit)?
(I guess 32bit is ok...)

Which network node do I need on the rPi0W (2) to send the data using WLAN to the other device rpi4B (1) which will then be connected directly (wired) to the router?

Any other suggestions or tips?

Thank you very much and kind regards
Thomas

They should do.

You have to use 32bit if it is an original model or 64bit if it is the 2nd generation.

It probably doesn't really matter that much. Personally, I would direct everything via an MQTT broker running on the rpi4 since that is a much more flexible approach though obviously it does require an additional service to be running but the Mosquitto broker is so efficient, very unlikely you will notice the overheads even with high message loads.

I guess if you already have a rpi0w, it makes some sense to use it. However, a lot of us would recommend using an ESP32 for things like this. It is generally much easier to manage and is very reliable. Again, connect the ESP32 over Wi-Fi to post to MQTT for the easiest and most flexible setup.

@TotallyInformation

First of all: Thank you very very much for your quick and detailed answer!!!

While Googling this topic, I also came across the ESP32.
In my case, because of the USB interface, I’d probably have to go with the ESP32-S2?

And is it really true that I could program this device using Visual Studio - which I already use for simple Windows and Office programs - and the Arduino IDE extension?

And last question:
On which forum can I get the same excellent support (for then setting up this (reading data from an USB port and sending it using MQTT) in Visual Studio) as I do on this forum?

Thank you and again kind regards
Thomas

So are you sure your heating device has a USB interface and not serial ??

Depending on what sort of protocol it is running - your best bet would be to look at one of the pre-rolled firmwares rather than doing it yourself. the most flexilbe would be ESPHome for what you are trying to achieve.

Craig

Hard to know without knowing the device you are trying to connect.

Oh, I don't know, I hate VS. :smiley:

As Craig says, I would use ESPHome where you rarely need to dip into C/C++ programming, though one of the nice things of ESPHome is that you can dip into it if you need/want to. Mostly you use configuration using YAML which you can easily do with VSCode.

There is nowhere with the excellent support you can get here! :rofl:

ESPHome has its own forum which isn't too bad. It also has a very wide range of existing device support that you might be able to use.

ESP devices are VERY widely used so there is a lot of information and help available in various places. I you are using it with Node-RED, you may well get some help here as well. :wink:

Let us know what device you are using for input and maybe we can help further.

[quote="nosered1966, post:3, topic:101125"]
And is it really true that I could program this device using Visual Studio
[/quote]

I have done it once using VS Codium, but by far prefer the Arduino IDE for ease of use.

To reiterate though, actual programming of ESP's is rarely needed these days unless you want something super specific. There are excellent firmwares such as ESPHome that do all the hard bits for you.

Ah, I was talking about actually programming the device using VSC and my preference of Arduino IDE. I am experimenting with ESPHome.

@craigcurtin
Thank you for helping!

Well, the heating device is already "under my control" (I probably can't control anything on this old thing - I can only read data. It's kind of a hobby...) using these nodes:

It is an 20 years old Viessmann Vitodens 200 gas condensing boiler with an Optolink interface, connected using a Optolink cable with an USB A plug plugged into my rpi4B.

ESPHome:
I didn't know it but it looks interesting...

I have one more serious question: In this age of “CyberSecurity”, should I be concerned about adding a Chinese processor to my home network?

The ESP32-S2 and ESP32-C3-Super-Mini are brilliant devices. They have WiFi and Bluetooth built-in. You'll have a lot of fun using them. I use many of them around the house/garage/garden/greenhouse to sense temperature/humidity/pressure and report the readings to Node-RED. For the last couple of years I've flashed them with Micro-Python and "rolled" my own code.

Honestly, in this day-and-age, that is the least of your worries!!

But no, not in this case, it is too simple a device to worry about. Especially with the widely used, open source firmware.

However, because you already have a USB output connector, while this is easier for the Pi, not quite so easy for the ESP. If you were simply using the minimal serial wires (RX, TX, Gnd?), you could wire that direct to the ESP which, I vaguely remember does have suitable input connections? Dave would likely know better than I since I only use the raw dev boards (no USB inputs) with simple sensors and then dump everything out to MQTT. I do have some more complex ESP based devices such as some M5Stack devices. But even so, I've never used the USB on any of them except for programming the firmware I'm afraid so I don't know how possible/easy it is - might be super easy, might not.

If you can sort out the connectivity, the rest is pretty easy. Even if you need some custom code (likely given your explanation), that is easy enough with the Arduino IDE and the MQTT Arduino library.

But actually even easier with ESPHome since that allows you to create small C++ breakouts within the YAML config for truly custom functions. And ESPHome takes care of all of the MQTT, Wi-Fi connectivity, over-the-air programming for you.

Of course, if you are a Python person, then, as Dave say's you could also use Micro Python instead.


Oh, and of course, I should have pointed out that your home is most certainly jam-packed FULL of Chinese microprocessors! If you have any kind of low-cost electronics in the house, they will be mostly Chinese.

If you have any Chinese camera's or other low-cost commercial IoT devices, those are the ones to worry about. Or indeed, low-cost Chinese networking equipment of any kind. Children's "AI enhanced" toys are the latest appalling cases.

@TotallyInformation & @dynamicdave

Hello again :waving_hand:
One of the best things of Node-RED is this Forum and the "Forum-Software" (what is the name or the technical term for this?) because it is so easy to use!!!

And thank you very much for your recent replies!!!

I now bought a ESP32-S2-DevKitC-1 (because it has two connectors and probably I can use one of them as virtual serial port for my existing USB serial cable...).

On this device ESPEasy is now running and I can control a LED and read data from a GY21 Temp & Humidity sensor. :trophy:

ESPHome does not support this device, but I didn't realise that until afterwards but I'm assuming that won't be a problem.

My next question is as follows:

As far as MQTT is concerned, there seem to be two options for my rPi4B and Node-RED:

  • Install 'externally' (outside of Node-RED) Mosquitto as MQTT broker
  • Install an MQTT Broker within Node-RED like Mosca/Aedes (node-red-contrib-aedes)

What do you think is the best choice?

Thank you and kind regards
Thomas

With due respect to the authors of Aedes broker, I wouldn't ever recommend it except as a last resort. As I understand it, it is node.js based and quite heavy on resources.

Mosquitto is written in C and is extremely efficient and low resource usage. It will certainly been your best choice.

Can I just check your set-up to make sure I understand the connections.

  1. The GY21 has an I2C I/F so I assume you have it connected to the ESP32-DevKit ?
  2. You say you can control an LED and read data from GY21, so I assume you have Node-RED running somewhere on your network?
  3. I assume you have got MQTT working on the ESP32-DevKit using ESPEasy?

I would stick with installing the Mosquitto Broker on one of your Raspberry Pis and/or PCs and run it as a local broker on your network. If you want to share your GY21 readings with other people and maybe see their readings then you could make use of a remote broker. There are various ways to accomplish this - but for now, I'd start off with a local private arrangement.

Yes, it is connected to the ESP32-DevKit.

Yes and no.
I have Node-RED running in my network on a rpi4B.
The LED and the GY21 is hardwired with the ESP32-Devkit and the LED is "controlled" only using a rule (switching GPIO1 ON/OFF with two timers) on the ESP32-Devkit.

No and yes :wink:
No, MQTT is not yet running on the ESP32 but it works on the rpi4B (Mosquitto), tested using 2 SSHs.
Yes, I will try to do this as next step to become MQTT running between these two devices...

And then I want to read the data, using the ESP32-DevKit, from the heating device using the USB serial adapter and send this data to my rpi4b.

Here is the whole setup:

Thank you and kind regards
Thomas

Is it my understanding that you are going to install MQTT on the ESP32 as well?

If so, you only need ONE MQTT Broker on the Network, all devices using MQTT use this single Broker for delivering and retrieving MQTT messages by using the Topic as the 'label/address' of the message.

IMHO, the RPi is the place for the Broker and can be installed on the RPi 4B with no problems.

Thanks for the feedback. I think I need to explain a few things about MQTT.

People normally install an MQTT Broker on their Raspberry Pi - popular choice is Mosquitto.
This is normally done using the command line in your RPi via SSH.

The MQTT-In and MQTT-Out nodes that appear in Node-RED are simple clients that "talk"... publish and subscribe to/from your MQTT Broker (e.g. Mosquitto) where ever that is located.


Although the MQTT Broker is normally installed on the same RPi that is running Node-RED - it doesn't have to be. If you have more than one RPi on your network, it could be on a different Pi.

It's a long time since I used ESPEasy - but I seem to remember you could set it up in the ESPEasy web interface:

Controllers → Add Controller

Select:

Home Assistant (openHAB) MQTT (C005)

Despite the name, this is the generic MQTT controller most people use.

Please note: You are NOT installing a MQTT Broker on the ESP32, just a simple client.

@mudwalker

Thank you!
But this I already understood: I have installed Mosquitto (Broker and Client) only onto the rpi4B.

Hello Dave,
thank you again!

I followed your instructions and I can already receive the data from my ESP23 on my rpi4B. However, I can only see it in the rpi4B SSH terminal, not in Node-RED (see screenshots). I’ve tried a few things, but unfortunately I haven’t managed to figure out why I can’t receive the data in Node-RED.
Do you have any ideas?

Tab Security and Messages is blank / not used.
Same on ESP32.

Thank you!!!