Skip to content

circuitphyton 5.x and version 3.1.0 #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bangell opened this issue Jun 18, 2020 · 5 comments
Closed

circuitphyton 5.x and version 3.1.0 #40

bangell opened this issue Jun 18, 2020 · 5 comments
Assignees

Comments

@bangell
Copy link

bangell commented Jun 18, 2020

I am getting an issue when i update my minimqtt library that i haven't had in the past. the .mpy file gives this error
AttributeError: 'module' object has no attribute 'set_socket'

import adafruit_minimqtt as MQTT
MQTT.set_socket(socket, esp) <-----

if i grab the .py file from GitHub, it works as it should. Do I need to do anything using .mpy file?

@bangell bangell changed the title circuitry 5.x and version 3.1.0 circuitphyton 5.x and version 3.1.0 Jun 18, 2020
@brentru
Copy link
Member

brentru commented Jun 19, 2020

@bangell What code.py are you running - could you copy and paste it below?

@bangell
Copy link
Author

bangell commented Jun 19, 2020

@brentru, i am using the example minimqtt_adafruitio_wifi.py

Adafruit MiniMQTT Pub/Sub Example

Written by Tony DiCola for Adafruit Industries

Modified by Brent Rubell for Adafruit Industries

import time
import board
import busio
from digitalio import DigitalInOut
import neopixel
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
import adafruit_esp32spi.adafruit_esp32spi_socket as socket

import adafruit_minimqtt as MQTT

WiFi

Get wifi details and more from a secrets.py file

try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise

If you are using a board with pre-defined ESP32 Pins:

esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)

If you have an externally connected ESP32:

esp32_cs = DigitalInOut(board.D9)

esp32_ready = DigitalInOut(board.D10)

esp32_reset = DigitalInOut(board.D5)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
"""Use below for Most Boards"""
status_light = neopixel.NeoPixel(
board.NEOPIXEL, 1, brightness=0.2
) # Uncomment for Most Boards
"""Uncomment below for ItsyBitsy M4"""

status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)

Uncomment below for an externally defined RGB LED

import adafruit_rgbled

from adafruit_esp32spi import PWMOut

RED_LED = PWMOut.PWMOut(esp, 26)

GREEN_LED = PWMOut.PWMOut(esp, 27)

BLUE_LED = PWMOut.PWMOut(esp, 25)

status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)

wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)

Feeds

Setup a feed named 'photocell' for publishing to a feed

photocell_feed = secrets["aio_username"] + "/feeds/photocell"

photocell_feed = "/feeds/photocell"

Setup a feed named 'onoff' for subscribing to changes

#onoff_feed = secrets["aio_username"] + "/feeds/onoff"
onoff_feed = "/feeds/onoff"

Code

Define callback methods which are called when events occur

pylint: disable=unused-argument, redefined-outer-name

def connected(client, userdata, flags, rc):
# This function will be called when the client is connected
# successfully to the broker.
print("Connected to Adafruit IO! Listening for topic changes on %s" % onoff_feed)
# Subscribe to all changes on the onoff_feed.
client.subscribe(onoff_feed)

def disconnected(client, userdata, rc):
# This method is called when the client is disconnected
print("Disconnected from Adafruit IO!")

def message(client, topic, message):
# This method is called when a topic the client is subscribed to
# has a new message.
print("New message on topic {0}: {1}".format(topic, message))

Connect to WiFi

print("Connecting to WiFi...")
wifi.connect()
print("Connected!")

Initialize MQTT interface with the esp interface

MQTT.set_socket(socket, esp)

Set up a MiniMQTT Client

mqtt_client = MQTT.MQTT(
broker="io.adafruit.com",
username=secrets["aio_username"],
password=secrets["aio_key"],
)

Setup the callback methods above

mqtt_client.on_connect = connected
mqtt_client.on_disconnect = disconnected
mqtt_client.on_message = message

Connect the client to the MQTT broker.

print("Connecting to Adafruit IO...")
mqtt_client.connect()

photocell_val = 0
while True:
# Poll the message queue
mqtt_client.loop()

# Send a new message
print("Sending photocell value: %d..." % photocell_val)
mqtt_client.publish(photocell_feed, photocell_val)
print("Sent!")
photocell_val += 1
time.sleep(5)

@caternuson
Copy link

Looks like the code was refactored into a subfolder which will change the imports currently being used in the examples:


and also guides?

Adafruit CircuitPython 5.3.0 on 2020-04-29; Adafruit PyPortal with samd51j20
>>> import adafruit_minimqtt as MQTT
>>> dir(MQTT)
['__class__', '__file__', '__name__', '__path__']
>>> 

related:
https://forums.adafruit.com/viewtopic.php?f=58&t=166556

@brentru
Copy link
Member

brentru commented Jun 22, 2020

@caternuson I'm going to update examples to import correctly and check against existing learn guides today.

@brentru brentru self-assigned this Jun 22, 2020
@brentru
Copy link
Member

brentru commented Jun 22, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants