MQTT with Arduino Nano + NodeRed

Continuing the discussion from Arduino i2c Firmata:

Is there any way to connect Arduino NANO boards to handle I/O + Analog (+ I2C ?) through NodeRed?
Important:

NANO has ONLY a USB port!

... so most of the MQTT libraries based on Wi-Fi chips will not work.

Has anyone done this before?
I'm not looking for theories, but a real example please.

Hello,

I think there are two ways that i can think of straight away but i think you will like neither and they both involve ditching firmata and pre processing data on the arduino :see_no_evil:
You could convert all the input data from analog and i2c on the arduino and send the processed data to nodered over serial and plug the arduino straight into the machine running nodered.
The problem with the nano is that it not just doesn’t have wifi but also no seperate power jack but you can power it by attaching a power supply directly to vin and ground pins. That way you could attach a esp of some kind over serial and use its wifi and mqtt. Thats the second way.
But than why not just get something like a wemos d1 mini and forget about the arduino.
Which is exactly what most people here tend to do for remote sensors and so on.
That way you wouldn’t even have to write any C code but could just use something like esp easy or tasmota.
The thing is the esp s are so cheap and readily available that at least to me it just doesn’t make it worth the hassle to use any of my old arduinos without onboard wifi. They sit safely in a box somewhere on a shelf.

Johannes

1 Like

YES, this is exactly the thing I'm looking for!

  • with minimal C, only "forwarding" RAW data from/to all ports and reconnecting if connection lost.
  • doing whatever possible at NodeRed side.

My question is:

  • HOW to do that?

Currently I'm investigating this:

And This:

Well you will have to write some logic in c as you wouldn’t just send raw data but pre process it on the arcuino and also when connecting several sensors and actors to one nano you will also have to think how are you gonna structure those messages and so on...
Which brings me back to the esps and ready made firmware available for them. No code you have to write at all and and all the structure for communication over mqtt build in and well documented as well as configurable with a graphic user interface running on the esp itself.
It saves so many headaches if your not keen on diving into writing c code yourself and want to focus purely on the nodered side.

Indeed, I agree with all that JGKK has said.

One thing I would add is that if you do just use the Nano and then plug it in via USB - then just serial is the way to go. no need for MQTT. You can just Serial.println("some data"); from the arduino code and then receive it with a serial in node in Node-RED running on the device it is plugged into -no need to wrap you head around networking and MQTT.

Of course if you DO want networking then yes you will need other boards to plug into to provide that, and then more complex code etc.

1 Like

I need a solution

without Wi-fi

please. Using shielded cables only! (USB + SFTP Ethernet + Alarm cables).
( I do not wish to loose 10 years of work again in 10 sec because of 1 dry-lightning . )

MQTT is a great universal communication standard.
It would put every device into one platform.
I see this as IoT future of all things bounded into one single interface.

There are Ethernet shields for the arduino nano but you will have to write c code I’m afraid.

So what is wrong with the serial connection to the node-red machine and then on to MQTT?

If you want to use MQTT direct from an arduino or similar device then you will need a network connection, if not wifi then you need ethernet.

How did lightning manage to destroy ten years worth of both on-site and off-site backups?

1 Like

Protecting against lightning strikes depends on good building maintenance and grounding. Anything that is even remotely connected to mains is susceptible to power spikes unless protected.

Unless you've got really crazy dangerous building mains wiring, while a strike will likely damage or destroy mains connected electronics, unlikely to impact SD-Cards or SSD's all that badly I would think (unless melted!)

Backups will not, of course, be impacted because at least one of them (you do have at least 2 of course) will be off-site in a protected data centre (cloud for those of us doing things on the cheap).

Central processing like your Pi and PC should be connected to mains via at least surge protection anyway. A PC UPS is even better.

Shielded USB cables are not going to help you in any way against lightning strikes. Nor will shielded ethernet if your mains isn't grounded properly and filtered through an anti-surge protector.

Wi-Fi will be impacted by local interference of course but any decent modern Wi-Fi AP will cope with that and the amount of data being sent by your IoT devices is generally tiny anyway. Since sensors will be sending another reading in a minute, it really doesn't matter if some messages get mangled.


If you really insist on going the Arduino route, you will end up spending much more on cables and routing them through walls than buying some cheap ESP's and USB Power Supplies.

I did suffer lightning damage a few years ago, it came in via the phone line apparently and took out the ADSL filter, router and a laptop that was connected to it via ethernet. If the laptop had been on WiFi then it would have been ok.

< OFF >

  1. I'm talking about DRY-lightning. Not the usual one "coming through the outlet".
    Please do not mix those two!
    Everything was perfectly grounded. 2000W Sinus wave online UPS did nothing, because:

  2. The surge was picket up by ALL non-shielded wires. They naturally act as antennas.

  3. The strongest surge + burning started from the Wi-Fi router !!! Obviously.
    All the hardware burned connected to it directly or indirectly.
    (PC, switch, phone-centre, house-control system, door-phones, etc. worth $10.000 = 10y work)

So whatever device has an antenna >> it will burn.

I have no idea what you are talking about. Who said anything about "backups"? (Are you mixing the topics maybe?)
I have 2 LAN + 2 offline (uplugged HDD) backups. One is in the vault surrounded by concrete in an iron box. Maybe a huge explosion + long burning could hurt it. But a lightning could not.

Everthing is already wired and connected. I just need a software to make it work!

please stop

talking about lightnings, but rather about stable USB communication with NodeRed.

Actually the more and more I think about it, I will have to realise:

  • there is no other way.

So I will start a new topic about "SAFEST Serial communication between Arduino + NodeRed."
(This topic is doomed anyway...)

So given the nano only has a usb port, what is it plugged into on the other end of the cable?

If it's plugged into a PC of some sort, then that can act as a network bridge and as Dave suggested, if the nano isn't on the network directly, then you'd be better off just writing over serial without the MQTT overhead and then bridge it to MQTT from the machine it's plugged into.

No need to start a new topic when we're still trying to understand your requirements in this one (ignoring the brief detour into lightening...)

< OFF >
OK, thank!
... still, it would be great if some answers or part of an answer could be GREYED (as off-topic).

serial has nothing to do with MQTT, sooooo a new topic will come.

As was said above. Write C code for your arduino that parses the values of the attached sensors and sends already formated data out over serial. You can than use the serial node in nodered. This is a limited approach as you will have to work with symlinks when you connect multiple arduinos to the same machine running nodered and is not scalable very well. The other option is to get ethernet-shield for your arduinos and connect them to the network this way than you could use one of the available mqtt clients and send the also formatted data over mqtt to nodered. There a few tutorials online on how to do mqtt with an arduino that is connected to a network via an ethernet-shield.

1 Like

The question is about Comms between nano and Node-RED. Whether that is serial or MQTT is all part of the discussion in this topic. Please dont start a new topic.

OK, in this case I re-form my question:

What's the most stable and universal way to connect to an Arduino Nano via USB?

By "stable" I mean:

  • it should handle Xon/Xoff buffer overflow control
  • parity check
  • auto reconnection
  • port releasing

I have 25+ years of experience with serial com. and I've learned without these things it's causing many troubles. And there are many cases even on this forum too to show I'm right, like here:

I'd like to avoid cases like that.

It sounds like you are the ideal guy to add some enhancements to the serial node.

Well, I would gladly do it ! ... if it would be possible to do in Pascal language, which I'm good at. I've just started to learn JavaScript basics a few weeks ago. :frowning: