MQTTError: Incorrect protocol version

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.
Locked
User avatar
rozenswag
 
Posts: 2
Joined: Wed Jun 23, 2021 12:03 pm

MQTTError: Incorrect protocol version

Post by rozenswag »

getting this error when running script that outputs temperature data to adafruit io. can you help me understand what might be going wrong?

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 3452, in _thread_main
self.loop_forever(retry_first_connection=True)
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1779, in loop_forever
rc = self.loop(timeout, max_packets)
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1181, in loop
rc = self.loop_read(max_packets)
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1574, in loop_read
return self._loop_rc_handle(rc)
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 2227, in _loop_rc_handle
self._do_on_disconnect(rc, properties)
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 3360, in _do_on_disconnect
self.on_disconnect(self, self._userdata, rc)
File "/usr/local/lib/python3.7/dist-packages/Adafruit_IO/mqtt_client.py", line 101, in _mqtt_disconnect
raise MQTTError(rc)
Adafruit_IO.errors.MQTTError: Incorrect protocol version

User avatar
eherrada
 
Posts: 161
Joined: Thu Jan 04, 2018 4:59 pm

Re: MQTTError: Incorrect protocol version

Post by eherrada »

Hey, can you post the script you're using (make sure not to include your Adafruit IO Key)?

User avatar
rozenswag
 
Posts: 2
Joined: Wed Jun 23, 2021 12:03 pm

Re: MQTTError: Incorrect protocol version

Post by rozenswag »

Code: Select all

import os
import glob
import time
import sys
from Adafruit_IO import *

#source: circuitbasics.com/raspberry-pi-ds18b20-temperature-sensor-tutorial

#these tow lines mount the device:
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
 
base_dir = '/sys/bus/w1/devices/'
device_path = glob.glob(base_dir + '28*')[0] #get file path of sensor
rom = device_path.split('/')[-1] #get rom name

# Set to your Adafruit IO key.
ADAFRUIT_IO_KEY = 'xxxxx'
# Set to your Adafruit IO username.
ADAFRUIT_IO_USERNAME = 'xxx'

# Create an MQTT client instance.
client = MQTTClient(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)


# Connect to the Adafruit IO server.
client.connect()
# Now the program needs to use a client loop function to ensure messages are
# sent and received.  There are a few options for driving the message loop,
# depending on what your program needs to do.

# The first option is to run a thread in the background so you can continue
# doing things in your program.
client.loop_background()
# Now send new values every tim seconds.
tim=60

def read_temp_raw():
    with open(device_path +'/w1_slave','r') as f:
        valid, temp = f.readlines()
    return valid, temp
 
def read_temp():
    valid, temp = read_temp_raw()

    while 'YES' not in valid:
        time.sleep(0.2)
        valid, temp = read_temp_raw()

    pos = temp.index('t=')
    if pos != -1:
        #read the temperature .
        temp_string = temp[pos+2:]
        temp_c = float(temp_string)/1000.0 
        temp_f = temp_c * (9.0 / 5.0) + 32.0
        return temp_f
 
while True:

    tempval = read_temp()
    print("Current temperature : ",tempval)
    print("Current time : ",time.strftime("%H:%M:%S"))
    client.publish('temp', tempval)
    time.sleep(tim)


Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”