• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

“Build a Home Automation System_esp8266_Attempting MQTT connection…failed

Q&A Forum › Category: Home Automation › “Build a Home Automation System_esp8266_Attempting MQTT connection…failed
0 Vote Up Vote Down
Nikolaos Nikolaou asked 5 years ago

Hi,
I have reached page 127 (Build a Home Automation System), in dashboard when i press buttons all work fine in node red but in arduino serial monitor get:

23:47:47.967 -> ………..
23:47:53.783 -> WiFi connected – ESP IP address: 192.168.1.8
23:47:53.783 -> Attempting MQTT connection…failed, rc=-2 try again in 5 seconds
23:48:03.926 -> Attempting MQTT connection…failed, rc=-2 try again in 5 seconds

Ι use macOS High Sierra and pi zero.

5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Hi.
That error means that your board is not able to establish an MQTT connection with the broker.
Can you double-check that you’ve inserted the right IP address of your MQTT server (raspberry pi)?
Regards,
Sara

0 Vote Up Vote Down
Nikolaos Nikolaou answered 5 years ago

Hi,
I connect to pi via ssd with the following IP:
….elos$ sudo ssh pi@192.168.1.8
and in arduino sketch:
const char* mqtt_server = “http://192.168.1.8/”;
Upload the sketch in esp8266 get from arduino IDE the massage:
Executable segment sizes:
IROM : 246364 – code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 27260 / 32768 – code in IRAM (ICACHE_RAM_ATTR, ISRs…)
DATA : 1264 ) – initialized variables (global, static) in RAM/HEAP
RODATA : 1052 ) / 81920 – constants (global, static) in RAM/HEAP
BSS : 25096 ) – zeroed variables (global, static) in RAM/HEAP
Το σχέδιο χρησιμοποιεί 275940 bytes (26%) του χώρου αποθήκευσης του προγράμματος. Το μέγιστο είναι 1044464 bytes.
Οι καθολικές μεταβλητές χρησιμοποιούν 27412 bytes (33%) δυναμικής μνήμης, αφήνοντας 54508 bytes για τοπικές μεταβλητές. Το μέγιστο είναι 81920 bytes.
esptool.py v2.8
Serial port /dev/cu.SLAB_USBtoUART
Connecting….
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: a4:cf:12:c7:8c:bf
Uploading stub…
Running stub…
Stub running…
Configuring flash size…
Auto-detected Flash size: 4MB
Compressed 280096 bytes to 205834…
Wrote 280096 bytes (205834 compressed) at 0x00000000 in 18.2 seconds (effective 123.2 kbit/s)…
Hash of data verified.
Leaving…
Hard resetting via RTS pin…
Βρέθηκε μη έγγυρη βιβλιοθήκη στο /Users/angelos/Documents/Arduino/libraries/hardware: Δεν βρέθηκαν αρχεία κεφαλίδας (.h) στο /Users/angelos/Documents/Arduino/libraries/hardware

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Hi.
You should write your RPi IP address like this:

const char* mqtt_server = “192.168.1.8”;

Try it and tell me if it solves your problem.
Regards,
Sara

0 Vote Up Vote Down
Nikolaos Nikolaou answered 5 years ago

It works now, thanks!!

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Great!
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.