• 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

ESP32 Ethernet web server with 4 AJAX buttons that control 4 relays and publish to MQTT topic

Q&A Forum › Category: ESP32 › ESP32 Ethernet web server with 4 AJAX buttons that control 4 relays and publish to MQTT topic
0 Vote Up Vote Down
Vitalie Dani asked 6 years ago

How to MQTT on ESP32 with Ethernet 8720 ?

 

Question Tags: ESP32 ETHERNET MQTT
14 Answers
0 Vote Up Vote Down
Vitalie Dani answered 6 years ago

Need the MQTT that will work on ESP32 ETHERNET

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

Can you post a link to that Ethernet module? I’ve never used it…

0 Vote Up Vote Down
Vitalie Dani answered 6 years ago

Hello, thx for reply.
First of all, i want to say that You did GREAT JOB with this project- RANDOMNERD TUTORIALS!!!

0 Vote Up Vote Down
Vitalie Dani answered 6 years ago

I combined you2 examples- password protected webserver and MQTT Project- MQTT CLIENT ESP32 #1
All works GREAT except that WEB SERVER USE ETHERNET BUT THE MQTT USE WIFI- AND I CANNOT MAKE IT WORK BOTH ON ETHERNET
Need your help to make MQTT working on ethernet
Thank You

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

I understand now. Thanks for providing all the details Vitalie. Unfortunately I don’t have one of those boards myself, so I can’t actually test anything or ensure that it works.

As you’ve mentioned it’s quite easy to setup a web server with Ethernet: https://forum.arduino.cc/index.php?topic=626891.0

However, I don’t think the MQTT library works with Ethernet… I think this library will only support Ethernet on Arduino shields: https://github.com/knolleary/pubsubclient

Can you ask the board seller, if they know MQTT Ethernet integration for that board?

Thanks!

0 Vote Up Vote Down
Vitalie Dani answered 6 years ago

Thank You for reply.  think need to make few changes to MQTT library to make it working on Ethernet- like W5100 works great with pubsubclient

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

You might try to run this examples that uses Ethernet: https://github.com/knolleary/pubsubclient/blob/master/examples/mqtt_basic/mqtt_basic.ino
I’m not sure, but it might work with small changes in the initialization 

0 Vote Up Vote Down
Vitalie Dani answered 6 years ago

i make changes to your project- “MQTT CLIENT ESP32 #1” to be working on ETHERNET!!!! So its possible. I just want to HELP ME TO COMBINE YOUR 2 PROJECTS- “PASSWORD PROTECTED ESP32 WEBSERVER & EDITED BY ME ( that WORKS MQTT ON ETHERNET- YOUR PROJECT-) “MQTT CLENT ESP32 #1
Need your help to COMBINE THAT 2 PROJECTS

0 Vote Up Vote Down
Vitalie Dani answered 6 years ago

Rui, In few words- what i need- to add mqtt publish/subscribe to buttons from the project “PASSWORD PROTECTED ESP32 WEBSERVER” to can PUBLISH and SUBSCRIBE buttons to MQTT topic messages- EVEN ON WIFI, i will make changes myself to make it working on Ethernet- BUT WILL BE VERY HELPFULL IF YOU JUST COMBINE YOUR 2 PROJECTS THAT I WAS DESCRIBED ABOVE ( OR add to project “Password Protected esp32 webserver”- an option to Publish and Subscribe to MQTT TOPIC

Please NEED YOUR HELP!!!

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

Hello again, thank you for the detailed explanation. As I’ve mentioned before unfortunately I don’t have that exact board and I can’t do custom coding due to time constraints.

When you tried to combine the code, is it compiling? Are you receiving any errors? What’s exactly not working?

If you provide error messages, I might be able to help you make it work!

Thanks for your patience.

0 Vote Up Vote Down
Vitalie Dani answered 6 years ago

Hello. Thank You for reply. I have not combined, i take your project “PASSWORD PROTECTED ESP32 WEBSERVER” and added MQTT publish/subscribe and i made few changes to library to can use it by ETHERNET. All is working!!!
What i want to ask you- TO ADD AJAX TO YOUR GREAT PROJECT “PASSWORD PROTECTED ESP32 WEBSERVER”- mean the buttons to change status when pins 26  27 change his statuses, also if the 26 27 was changed by MQTT or url- from browser- THE BUTTONS TO CHANGE STATUS TOO- IN ANY WORDS TO ADD AJAX TO THAT 2 BUTTONS. Will waiting for your quick help!!!

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

That’s a bit tricky to setup… It should possible to do it, but even though MQTT is a two way communication, it can interact directly with your JavaScript variables in your web page.
You could use AJAX to change the button state when pressed on the web server, but I don’t know/have examples on how to update the button with Ajax upon changing the state with an MQTT publish…

0 Vote Up Vote Down
Vitalie Dani answered 6 years ago

The best way – is to monitor 26 27 pins. When pin change status (low to high or high to low)- doesent matter from what source- mqtt url webpage button press- the web servers button- change status too

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

Yes, but it’s hard to push that information to the ESP static web page. You will need to constantly request the current state of your GPIO using AJAX to know if has changed state or not… It’s possible to do it, but I’m not sure if your web server will be reliable with so many requests

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.