🎄⛄❄️🎁 It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! 🎄⛄❄️🎁
0

I am getting the red bar / MQTT connection error in my brows
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

I am getting the red bar / MQTT connection error in my brows

by HomeFYP on Thu Oct 31, 2019 1:05 am

Hello guys,

I am doing a home automation project using the esp32 board as a publisher and also a subscriber and the broker is using Adafruit.io.
The code does the esp32 board to publish the on and off signal to the feed to turn on and turn off the toggle on the dashboard (relay-1)
When running the code, I get the red bar on my adafruit.io dashboard.
The libraries I used that not inside micropython library:
1) MQTT2 link - https://github.com/pycom/pycom-librarie ... tt/mqtt.py
2) its bundle link - https://github.com/pycom/pycom-librarie ... mples/mqtt
3) Main2 is for connecting Wifi

Question
1) Why this happens?
2) How to solve it?

Below of those are the code and the result in the shell.

This is the code
Code: Select all | TOGGLE FULL SIZE
from MQTT2 import MQTTClient
from machine import Pin
import machine
import time
import Main2
from machine import UART
import os
uart = UART(2, 115200)
os.dupterm(uart)
def settimeout(duration):
    pass
def sub_cb(topic, msg):
   print(msg)
wlan = Main2.get_connection()
if wlan is None:
    print("Could not initialize the network connection.")
pass
client = MQTTClient("oktehn", "io.adafruit.com",user="{Username}", password=
                    "Io_key", port=1883)
client.settimeout = settimeout
client.connect()

while True:
        print("Sending ON")
        client.publish(topic="{Username}∕feeds∕relay-1", msg="ON")
        time.sleep(1)
        print("Sending OFF")
        client.publish(topic="{Username}∕feeds∕relay-1", msg="OFF")
        time.sleep(1)from MQTT2 import MQTTClient
from machine import Pin
import machine
import time
import Main2
from machine import UART
import os
uart = UART(2, 115200)
os.dupterm(uart)
def settimeout(duration):
    pass
def sub_cb(topic, msg):
   print(msg)
wlan = Main2.get_connection()
if wlan is None:
    print("Could not initialize the network connection.")
pass
client = MQTTClient("oktehn", "io.adafruit.com",user="{Username}", password=
                    "Io_key", port=1883)
client.settimeout = settimeout
client.connect()

while True:
        print("Sending ON")
        client.publish(topic="{Username}∕feeds∕relay-1", msg="ON")
        time.sleep(1)
        print("Sending OFF")
        client.publish(topic="{Username}∕feeds∕relay-1", msg="OFF")
        time.sleep(1)

Shell:
Code: Select all | TOGGLE FULL SIZE
Sending ON
Sending OFF
Sending ON
Sending OFF
Traceback (most recent call last):
  File "boot.py", line 34, in <module>
  File "MQTT2.py", line 126, in publish
OSError: [Errno 104] ECONNRESET
MicroPython v1.11-240-g519746cae on 2019-08-25; ESP32 module (spiram) with ESP32
Type "help()" for more information.


#micropython
#thonny ide

Thanks in advance.
Attachments
Screenshot (613)_LI.jpg
Screenshot (613)_LI.jpg (868.9 KiB) Viewed 164 times

HomeFYP
 
Posts: 3
Joined: Tue Oct 22, 2019 8:48 am

Re: I am getting the red bar / MQTT connection error in my b

by brubell on Thu Oct 31, 2019 3:30 pm

Do you have permission to publish to {Username}/feeds/relay-1 with {Username}?

If so...

Code: Select all | TOGGLE FULL SIZE
client = MQTTClient("oktehn", "io.adafruit.com",user="{Username}", password=
                    "Io_key", port=1883)

Adafruit IO will generate a new client identifier per-connection, try removing it ("oktehn"):


Also, try initializing your MQTTClient like this...
Code: Select all | TOGGLE FULL SIZE
client = MQTTClient( server=ADAFRUIT_IO_URL,
                    user=ADAFRUIT_USERNAME,
                    password=ADAFRUIT_IO_KEY,
                    ssl=False)

brubell
 
Posts: 609
Joined: Fri Jul 17, 2015 10:33 pm

Re: I am getting the red bar / MQTT connection error in my b

by HomeFYP on Fri Nov 01, 2019 1:04 am

Hi @brubell,

Tq for replying to my post.

What is the permission that you mention? It is a shared feed or set my feed as public.

So the client id is not necessary, ok noted.

Thank you.

HomeFYP
 
Posts: 3
Joined: Tue Oct 22, 2019 8:48 am

Re: I am getting the red bar / MQTT connection error in my b

by HomeFYP on Sun Nov 03, 2019 11:30 pm

Hi guys,

is it the library of MQTT that I used is wrong?
1) MQTT2 link -https://github.com/pycom/pycom-librarie%20...%20tt/mqtt.py

What is the library that I can use to connect Adafruit IO?
This?
https://github.com/adafruit/Adafruit_IO_Python

If it is this,
then,
I got this when I used the mqtt_client.py in this link https://github.com/adafruit/Adafruit_IO_Python/blob/master/Adafruit_IO/mqtt_client.py
Code: Select all | TOGGLE FULL SIZE
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
ImportError: no module named 'paho'

where can I get the library?

thanks in advance.

HomeFYP
 
Posts: 3
Joined: Tue Oct 22, 2019 8:48 am

Re: I am getting the red bar / MQTT connection error in my b

by brubell on Fri Nov 08, 2019 5:43 pm

The Adafruit IO Python library uses the Eclipse Paho MQTT client (https://pypi.org/project/paho-mqtt/).

You'll want to install it by executing the following command in a terminal:
Code: Select all | TOGGLE FULL SIZE
pip install paho-mqtt

brubell
 
Posts: 609
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.