ESPEasy and NodeRed

Hello,
I have 2 projects running, which send their data from a ESP8266 via MQTT to Node-Red and from there it is sent to an Influx-DB. Later I can use this data for Grafana to visualize. The problem is, that all that is 2 years ago since installing. At the time I wrote my own code via Arduino-Software and PubSubClient.h and it works fine since then.

Now I installed a new small PV-plant in my garden and want to track the produced energy with a energymeter with S0-Connection. This time I used ESPEasy to get and send the data on the ESP8266. For testing I used a BME280-sensor. My problem is, that I do net get the data to Node-Red.

The following works:
ESPEasy on a ESP8266
sending data to broker.hivemq.com (for testing)

If I try to send the data to my own server (VServer, not local), I do not know where the data get lost.
Main problem is probably, that Node-Red-Frontend loses connection to the server all the time. Does anyone have a solution for that? At the moment I do not even see debug-messages for the other nodes, which work.

Is there also another option to show me incoming messages directly on mosquitto?

Best regards
Stefan

Is there a reason to use an Internet based MQTT Broker? Generally, it is much easer - and safer - to use a local broker. You can run Mosquitto along with Node-RED and many other things on a standard Pi so no reason not to.

I agree with @TotallyInformation you sohould use a local mqtt broker. I've been using a PiZero W as my MQTT broker with Mosquitto installed. It'sfairly easy to install - (here is one set of instructions: Install Mosquitto Broker Raspberry Pi | Random Nerd Tutorials)

The big question wi will the ESPEasy device be close enouth to your WiFi to conect up.

You should also install MQTT Explorer on one of yout devices it is very helpful for looking at MQTT related things

If you want to learn more about MQTT then see this tutorial MQTT Essentials - All Core Concepts explained

Hey, of course it is easier, but this was not the question. The big advantage is, that I can access the data from everywhere and not only from the same Wifi. Also I can bundle sensors from several places and do not need a separate Raspberry for each different Wifi, where there is a sensor.

Mosquitto, Node-red and so on are just installed on a webserver instead of a Raspberry Pi, otherwise there is not so much difference.

1 Like

could you draw a block diagran showing the path a sensor reading will take to get to the influx db. Include all the components it will go thru like your local WiFi device (since that is what the ESP8266 will be origianally talking to.)

As Said, if you install MQTT Explorer, you can connect it to broker.hivemq.com to make sure the data is getting there.

image
image

Hello, attached the 2 scenarions (real ans test with hivemq). At HiveMQ my data are received, so the local ESP8266 seems not to be the problem). When I switch the controller on the ESP8266 back to my server I do not see the data anywhere. I also need to develop a function to bring the data to a format I can write into the database. But in the first Step I just need to check if the data arrives at my Server. Here is where I struggle. I wrote it into a file in Node-Red, but there I do not see any data. Not sure if that was correct.


It just does not show any debug messages in Node-Red - also not for the measurements that actually work.

Sorry, some infos on the sketches are in german.

For a test I would create a small test flow with an inject node connected to an mqtt-out node and an mqtt-in node connected to a debug node. Use a topic that is different from the topic your sensors are using and run the test. Does a message come thru?

What version of NR, Node.js and mosquitto are you running on your Pi? You can open a terminal window and run

node-red -?
node -v
mosquitto -h

Have you configured Mosquitto to allow access from other devices? If not, then create a file called /etc/mosquitto/conf.d/mossy.conf (the name does not matter, provided it is in that folder with extension .conf)
In there put

listener 1883
allow_anonymous true 

I also add this which provides human readable timestamps in the mosquitto log

log_timestamp true
log_timestamp_format %Y-%m-%d %H:%M:%S

Then restart node-red. [edit] restart mosquitto, not node red.

Also I suggest installing the very useful tool mqttExplorer in a PC on the network. Then you can easily see what topics are being published to a broker.

Hello, good idea.
image
Debug window shows nothing

I tried also inject node connected to mqtt out (broker.hivemq.com). This message arrives there.

Versions are not really the latest, but for the other ESPs it works. I didnt want to upgrade so that I dont destroy what runs so far xD:
Node-RED v1.2.6
v12.22.12
MQTT v3.1.1/v3.1

can you do a

sudo cat /etc/mosquitto/mosquitto.conf

and look to see

listener 1883
allow_anonymous true

exists in the output. If it doesn't then run

sudo nano /etc/mosquitto/mosquitto.conf

and add those two lines to the end of the file. Then press CTRL-X to exit and save the file. Press Y and Enter . Next run
sudo systemctl restart mosquitto
and then run the test flow again.

I think you may need to review your webserver for unwanted "guests". You don't appear to have configured secure connections.

Without TLS secured connections and logins throughout, any old internet observer could get onto your system.

Oh, now it seems to work. I forgot to enter my credentials for the broker this time. Now it is transfered through to hivemq with the test node. I'll give it a try if I can update the nodes.

That is not necessary if he/she has followed my advice of a couple of posts ago.