Skip to content

Commit b6830b3

Browse files
author
brentru
committed
remove old simpletests with invalid method signatures, etc
1 parent 61681ef commit b6830b3

File tree

2 files changed

+34
-197
lines changed

2 files changed

+34
-197
lines changed

examples/mqtt/adafruit_io_mqtt_subscribe_publish.py renamed to examples/mqtt/adafruit_io_mqtt_simpletest.py

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010
import neopixel
1111
import busio
1212
from digitalio import DigitalInOut
13-
14-
# Import WiFi configuration
1513
from adafruit_esp32spi import adafruit_esp32spi
1614
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
1715
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
1816

19-
# Import the Adafruit IO MQTT Class
20-
from adafruit_io.adafruit_io import MQTT
17+
from adafruit_minimqtt import MQTT
18+
from adafruit_io.adafruit_io import IO_MQTT
2119

2220
### WiFi ###
2321

@@ -41,7 +39,9 @@
4139
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
4240
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
4341
"""Use below for Most Boards"""
44-
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards
42+
status_light = neopixel.NeoPixel(
43+
board.NEOPIXEL, 1, brightness=0.2
44+
) # Uncomment for Most Boards
4545
"""Uncomment below for ItsyBitsy M4"""
4646
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
4747
# Uncomment below for an externally defined RGB LED
@@ -59,61 +59,59 @@ def connected(client):
5959
# This is a good place to subscribe to feed changes. The client parameter
6060
# passed to this function is the Adafruit IO MQTT client so you can make
6161
# calls against it easily.
62-
print('Connected to Adafruit IO! Listening for DemoFeed changes...')
62+
print("Connected to Adafruit IO! Listening for DemoFeed changes...")
6363
# Subscribe to changes on a feed named DemoFeed.
64-
client.subscribe('DemoFeed')
64+
client.subscribe("DemoFeed")
65+
6566

6667
def disconnected(client):
6768
# Disconnected function will be called when the client disconnects.
68-
print('Disconnected from Adafruit IO!')
69-
sys.exit(1)
69+
print("Disconnected from Adafruit IO!")
70+
7071

7172
def message(client, feed_id, payload):
7273
# Message function will be called when a subscribed feed has a new value.
7374
# The feed_id parameter identifies the feed, and the payload parameter has
7475
# the new value.
75-
print('Feed {0} received new value: {1}'.format(feed_id, payload))
76+
print("Feed {0} received new value: {1}".format(feed_id, payload))
77+
7678

7779
# Connect to WiFi
7880
wifi.connect()
7981

80-
# Create an Adafruit IO MQTT client.
81-
client = MQTT(secrets['aio_user'],
82-
secrets['aio_password'],
83-
wifi,
84-
socket)
82+
# Initialize a new MQTT Client
83+
client = MQTT(
84+
socket=socket,
85+
broker="io.adafruit.com",
86+
username=secrets["aio_user"],
87+
password=secrets["aio_key"],
88+
network_manager=wifi,
89+
)
8590

8691
# Setup the callback functions defined above.
87-
client.on_connect = connected
92+
client.on_connect = connected
8893
client.on_disconnect = disconnected
89-
client.on_message = message
94+
client.on_message = message
9095

91-
# Connect to the Adafruit IO server.
92-
client.connect()
96+
# Initialize an Adafruit IO MQTT Client
97+
io = IO_MQTT(client)
9398

94-
# Now the program needs to use a client loop function to ensure messages are
95-
# sent and received. There are a two options for driving the message loop:
99+
# Connect to Adafruit IO
100+
io.connect()
96101

97-
# You can pump the message loop yourself by periodically calling
98-
# the client loop function. Notice how the loop below changes to call loop
99-
# continuously while still sending a new message every 10 seconds. This is a
100-
# good option if you don't want to or can't have a thread pumping the message
101-
# loop in the background.
102+
# You can call the message loop every X seconds
102103
last = 0
103-
print('Publishing a new message every 10 seconds (press Ctrl-C to quit)...')
104+
print("Publishing a new message every 10 seconds...")
104105
while True:
105106
# Explicitly pump the message loop.
106-
client.loop()
107+
io.loop()
107108
# Send a new message every 10 seconds.
108109
if (time.monotonic() - last) >= 5:
109110
value = randint(0, 100)
110-
print('Publishing {0} to DemoFeed.'.format(value))
111-
client.publish('DemoFeed', value)
111+
print("Publishing {0} to DemoFeed.".format(value))
112+
io.publish("DemoFeed", value)
112113
last = time.monotonic()
113114

114-
# Or you can just call loop_blocking. This will run a message loop
115-
# forever, so your program will not get past the loop_blocking call. This is
116-
# good for simple programs which only listen to events. For more complex programs
117-
# you probably need to have a background thread loop or explicit message loop like
118-
# the two previous examples above.
119-
# client.loop_blocking()
115+
# You can also call loop_blocking if you only want to receive values.
116+
# NOTE: If uncommented, no code below this line will run.
117+
# io.loop_blocking()

examples/mqtt/adafruit_io_mqtt_weather.py

Lines changed: 0 additions & 161 deletions
This file was deleted.

0 commit comments

Comments
 (0)