• 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

Sketch will not connect to MQTT

Q&A Forum › Category: Home Automation › Sketch will not connect to MQTT
0 Vote Up Vote Down
merkelck asked 6 years ago

I finally got code to work for the pushbutton/toggle switch. My problem now is that I can not make the sketch connect to my MQTT server. The system is complete on NodeRed and the dashboard involving two flashed sonoff switches.

But I am making some mistake in the “void reconnect” function. The switch runs the led just like I want it to but I can not get the MQTT server to connect.

The button code and the flow are pastebin:

  • https://pastebin.com/sNGAU4JG
  • https://pastebin.com/9TSu8Dv4

I have looked over this so much but I just can not come up with the solution. The primary reason is that I don’t have enough basic skills to understand the errors. I was able to get the dashboard to function from the internet and my phone but I can’t make the MQTT connect.

The basic mqtt_esp8266 sketch work great but there something about the topics that have me stumped. The current topics that may be in the flow have been changed around so many times that I have lost track of them. My basic idea was to be able to use a handheld remote to turn a sonoff on with one click and off with another. That part of the sketch works as I want it..

Thank you

1 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

Just do double-check:

  • Do you see any error in your Arduino IDE serial monitor? Does it print any message? Please post what you see
  • Remove line 94 and 95: https://pastebin.com/sNGAU4JG Your ESP8266 cannot be subscribed to the same topic that is publishing the messages. Otherwise, it publishes a message and receives it causing a loop

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

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 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.