# Mqtt from ESP to Node-red

**URL:** https://discourse.nodered.org/t/mqtt-from-esp-to-node-red/69041
**Category:** Hardware
**Created:** [14 October 2022 19:53 UTC](https://discourse.nodered.org/t/mqtt-from-esp-to-node-red/69041 "2022-10-14T19:53:02Z")
**Posts on this page:** 6
**Page:** 2

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [16 October 2022 22:07 UTC](https://discourse.nodered.org/t/mqtt-from-esp-to-node-red/69041/21 "2022-10-16T22:07:48Z")

</div>

I also note that you are reading a number of temperature sensors - in the case of the DS18B20 they have a minimal time to send out a reading request - per sensor and then wait for the response - if you have multiple of these (or other similar sensors) this will throw out your timing loops and indeed may not complete before you go back to deepsleep

Craig

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [17 October 2022 05:39 UTC](https://discourse.nodered.org/t/mqtt-from-esp-to-node-red/69041/22 "2022-10-17T05:39:50Z")

</div>

Then take the advice and migrate to ESPHome

---

<div class="post-metadata">

### Author: ![ScheepersJohan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scheepersjohan/32/39556_2.png) [@ScheepersJohan](https://discourse.nodered.org/u/ScheepersJohan)
#### Post date: [18 October 2022 04:47 UTC](https://discourse.nodered.org/t/mqtt-from-esp-to-node-red/69041/23 "2022-10-18T04:47:11Z")

</div>

Can you show the exact your code on the ESP?

With the snippets cant see if you maybe leaving something obviously out.

Edit. Have you checked your network for stability?

---

<div class="post-metadata">

### Author: ![GlennK](https://avatars.discourse-cdn.com/v4/letter/g/ecccb3/32.png) [@GlennK](https://discourse.nodered.org/u/GlennK)
#### Post date: [18 October 2022 19:55 UTC](https://discourse.nodered.org/t/mqtt-from-esp-to-node-red/69041/24 "2022-10-18T19:55:52Z")

</div>

I publish 10 MQTT topics from an ESP8266 to a Raspberry Pi running Mosquitto and then into Node-Red every 2 minutes and then put the ESP into deep sleep mode.

I noticed early on that I was randomly losing some of the last few messages and thought it might have been the load on the Rpi. But, I put a 50ms delay after the last client.publish right before entering the deep sleep mode and haven't had a problem since.

I only put the delay prior to the deep sleep, not after each client.publish. In fact I grab the millis() timer and transmit that as the last topic so I can see how long the entire cycle takes.

---

<div class="post-metadata">

### Author: ![mojgithub](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mojgithub/32/63532_2.png) [@mojgithub](https://discourse.nodered.org/u/mojgithub)
#### Post date: [18 October 2022 21:45 UTC](https://discourse.nodered.org/t/mqtt-from-esp-to-node-red/69041/25 "2022-10-18T21:45:35Z")

</div>

Tnx for all your replies.

I have already deployed my 2 devices(weather station and garden water system) outside in another country and accepted the fact that weather station wont be perfect(getting data every 5min but with few skiping per hour).

@zenofmud setup code runs ok after deepsleep

@krambriw ESPHome? Dont know what it is but i just migrated from Blynk app because they want to charge from next year on or something. Anyway in past few weeks i have migrated to raspberry pi 4 using mosquitto, node-red, influxdb 2, grafana, pivpn. First time using all this stuff. I wont make a mistake again having my data in some cloud or "free" app.

@GlennK Yes, i have added delay before deepsleep from 50milis, 100, 500, 1000 to even 1min.

@craigcurtin But i do get all sensor data. I can see values in my esp serial monitor. I also see confirmation from mqtt library that it was successfuly "sent".

Anyway, once again thx for your help. But sometimes u just need to let it go and deploy/finish the project.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [17 December 2022 21:45 UTC](https://discourse.nodered.org/t/mqtt-from-esp-to-node-red/69041/26 "2022-12-17T21:45:40Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/mqtt-from-esp-to-node-red/69041.md?page=1)
