• 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

disconnected mqtt

Q&A Forum › Category: ESP32 › disconnected mqtt
0 Vote Up Vote Down
Fadhli Azinnuddin asked 2 years ago

i am try on module 5 at basic example i have problem publish and subscribe between raspberry pi as broker and esp 32.. after i upload code :
#include <WiFi.h>
extern “C” {
#include “freertos/FreeRTOS.h”
#include “freertos/timers.h”
}
#include <AsyncMqttClient.h>
#define WIFI_SSID “iPhone”
#define WIFI_PASSWORD “Jiancok717273”
#define MQTT_HOST IPAddress(169, 254, 204, 97) //MQTT BROKER IP ADDRESS
#define MQTT_PORT 1883
#define BROKER_USER “fadhli”
#define BROKER_PASS “1234”
i have problem with mqtt not connected or disconnected mqtt..
you can see at link https://drive.google.com/file/d/1cajO3nBT2V2YEAh7UOtffCycyW-kHQds/view?usp=sharing
 
21:05:12.609 -> Connecting to Wi-Fi…
21:05:12.609 -> [WiFi-event] event: 0
21:05:12.695 -> [WiFi-event] event: 2
21:05:14.776 -> E (4573) wifi:Association refused temporarily, comeback time 200 mSec
21:05:14.973 -> E (4778) wifi:Association refused temporarily, comeback time 200 mSec
21:05:15.200 -> E (4983) wifi:Association refused temporarily, comeback time 200 mSec
21:05:15.409 -> E (5188) wifi:Association refused temporarily, comeback time 200 mSec
21:05:15.615 -> [WiFi-event] event: 4
21:05:15.662 -> [WiFi-event] event: 7
21:05:15.662 -> WiFi connected
21:05:15.662 -> IP address:
21:05:15.662 -> 172.20.10.6
21:05:15.662 -> Connecting to MQTT…
21:05:22.574 -> Publishing on topic counter at QoS 1, packetId: 0Publishing on topic counter at QoS 1, packetId: 0Publishing on topic counter at QoS 1, packetId: 0Disconnected from MQTT.
21:05:48.417 -> Connecting to MQTT…

20 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
Is the Raspberry Pi also connected to your phone? It needs to be on the same network of the ESP32…
Regards,
Sara

0 Vote Up Vote Down
Fadhli Azinnuddin answered 2 years ago

Yups.. my raspberry pi and esp32 with on the same network wifi.. and with mqtt brokrer ip address same with browser node red.. 
Maybe i have problem with wifi network on the phone sara ?
I am must change to modem for wifi ?
I think.. i see at arduino serial monitor wifi connected and no problem.. just problem with mqtt disconnected

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

Hi again.
I’m not sure what’s causing the issue.
What Wi-Fi network are you using? Is it the Wi-Fi provided by your phone?
#define WIFI_SSID “iPhone”
In this previous line, you need to insert the SSID of the network you’re connecting to, not your phone.
 
I hope this helps. It is better to use a modem for wifi.
 
Regards,
Sara
 

0 Vote Up Vote Down
Fadhli Azinnuddin answered 2 years ago

Yes i am use hotspot at my iphone.. and ssid at my iphone is iphone..
If i am change to modem wifi.. how to change ssid at my raspberry.. because i am use ssid iphone for default ssid at my raspberry pi

0 Vote Up Vote Down
Fadhli Azinnuddin answered 2 years ago

In this previous line, you need to insert the SSID of the network you’re connecting to, not your phone.
Whats your mean at previous line ?

0 Vote Up Vote Down
Fadhli Azinnuddin answered 2 years ago

I think same with my case before.. i am cannot acces raspberry pi node red from my phone browser, maybe i must use modem wifi than my hotspot in my phone.. right sara ?

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

Hi.
I think it is better to connect everything to your router. I’m not sure if it is a good idea to use the hotspot on your iphone. I have used iphone before for hotspot to get data on my phone, and it was constantly dsiconnecting if I was inactive. So, I imagine the same can happen with the ESP32 and Raspberry Pi.
 
In the ESP32, you just need to insert the SSID and password of the router in your code.
 
To change that on the Raspberry Pi,  I recommend taking a look at the following tutorial to change the SSID and password of your primary primary network:

  • https://www.thedigitalpictureframe.com/three-ways-to-change-your-wifi-password-and-ssid-on-a-headless-raspberry-pi-locally-and-remotely/

I hope this helps.
Regards,
Sara

0 Vote Up Vote Down
Fadhli Azinnuddin answered 2 years ago

I am already buy wifi router but my problem same.. raspberry pi and esp 32 still cannot connecting to communication.. maybe if i follow module 9.. my problem is solved.. right sara ? Because on module 9 the most important i have access internet and can access anywhere 

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

Hi.
No. In that scenario, the ESP32 still needs to connect with the Raspberry Pi via the same network.
What is exactly the issue that you’re having at the moment? At which step are you getting stuck?
 
To access anywhere and don’t have that problem with the connection between the Pi and the ESP32, you would need to follow Module 10. In that scenario, you won’t need a Raspberry Pi, and you would create a cloud server. In this scenario, you need to pay for hosting and a domain name.
 
Regards,
Sara

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

Just one more question, are you running the Raspberry Pi headless or with desktop mode?

0 Vote Up Vote Down
Fadhli Azinnuddin answered 2 years ago

Yess i am use same network on the my router on raspberry pi and esp 32 with use sane router, same ssid and password..
But at my case mqqt still disconnected ( disconnectes from mqtt )
 
Like this :
21:05:15.615 -> [WiFi-event] event: 4
21:05:15.662 -> [WiFi-event] event: 7
21:05:15.662 -> WiFi connected
21:05:15.662 -> IP address:
21:05:15.662 -> 172.20.10.6
21:05:15.662 -> Connecting to MQTT…
21:05:22.574 -> Publishing on topic counter at QoS 1, packetId: 0Publishing on topic counter at QoS 1, packetId: 0Publishing on topic counter at QoS 1, packetId: 0Disconnected from MQTT.
21:05:48.417 -> Connecting to MQTT…
 
Why always disconnected from mqqt.. i am use same router (ssid  and paswrd wifi ) on my raspberry pi and esp 32
 
I am running raspberry pi at desktop mode use ssh conection

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

Hi.
What do you mean by “I am running raspberry pi at desktop mode use ssh connection”.
Do you have a monitor connected to your Pi?
 
I’m not sure why it is always connecting and disconnecting. But, does it connect successfully afterward?
 
Regards,
Sara

0 Vote Up Vote Down
Fadhli Azinnuddin answered 2 years ago

I am use my laptop for the desktop of my raspberry with putty ( ssh connection )
Wifi is connected but.. mqtt always fail to connect.. after connection and then disconnecting..
if i follow module 9 with broker raspberry pi but for internet can anywhere, right sara ?
i think if i follow module 9 can help me for my problem..
 
I am confuse at my case.. esp 32 and raspberry pi with similar router ssid and password but why alwayas fail for connected with mqtt broker
 
 

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

Hi.
I’m not sure what might be causing the issue, maybe it is a problem with the wi-fi connection… but it is very difficult to troubleshoot. Do you get the messages on Node-RED?
Regards,
Sara

0 Vote Up Vote Down
Fadhli Azinnuddin answered 2 years ago

no..  i  have not get messages on node red..
this mqtt broker test on raspberry pi on mode linux :
https://drive.google.com/file/d/1w9ZVV18vz1dV23Dc4Y-ECvCASVpiCRwj/view?usp=sharing
and this on arduino ide :
https://drive.google.com/file/d/1aS0rJEcibXXyFLOAjsdoQoaMHkkfxzIc/view?usp=sharing
 
maybe module 9 problem solved my case sara ? because not only local network
 
 

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

Hi again.
Is your Pi connected to an ethernet cable or is it using just Wi-Fi?
As I mentioned previously, if you have issues with the network, you need to follow Module 10 and not Module 9.
In Module 10, you don’t need the Raspberry Pi. Everything is done in the cloud. Then, as long as the ESP32 can connect to the internet, everything will work.
Regards,
Sara

0 Vote Up Vote Down
Fadhli Azinnuddin answered 2 years ago

Yes, my PI connected to an ethernet cable and wifi sara
How about module 9? 
on module 9 i am still use PI as mqtt broker but network can acces at anywhere, right sara ?

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

Don’t use your Raspberry Pi on an ethernet cable. 
Please use it just via wireless.
I had some other readers having issues with connections because the Pi was using wireless and ethernet cable at the same time.
 
With Module 9 you can access from anywhere, but if you have issues on your network, the ESP32 won’t connect to the Raspberry Pi.
 
Regards,
Sara

0 Vote Up Vote Down
Fadhli Azinnuddin answered 2 years ago

Oke thanks sara santos.. your solution solved.. thank you very much 🙂

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

Great!
I’m glad we found the issue.
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

  • [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.