-
Notifications
You must be signed in to change notification settings - Fork 50
Remove secrets usage #245
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
Merged
Merged
Remove secrets usage #245
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
67f971f
Remove secrets usage
justmobilize ce1a94d
PR comments
justmobilize 8a6253d
Missing import
justmobilize 538c2eb
Update ruff-pre-commit, reorder format after fix, and enable error again
tyeth ddebed1
Drop rule E999 (now included for free)
tyeth 054a4d0
Reorder and add rule F821 Undefined Name
tyeth 8875467
Enable preview features in ruff
tyeth fb2b101
Ignore class length but keep rule active + remove error
tyeth a9ce58d
format noqa line
tyeth 29e12f6
ruff ignores
justmobilize File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,14 @@ | |
|
||
import adafruit_minimqtt.adafruit_minimqtt as MQTT | ||
|
||
### WiFi ### | ||
# Get WiFi details and MQTT keys, ensure these are setup in settings.toml | ||
ssid = getenv("CIRCUITPY_WIFI_SSID") | ||
password = getenv("CIRCUITPY_WIFI_PASSWORD") | ||
broker = getenv("broker") | ||
username = getenv("username") | ||
paswword = getenv("paswword") | ||
Comment on lines
+16
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getenv not defined There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
# 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 | ||
### WiFi ### | ||
|
||
# If you are using a board with pre-defined ESP32 Pins: | ||
esp32_cs = DigitalInOut(board.ESP_CS) | ||
|
@@ -32,17 +32,17 @@ | |
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 | ||
status_pixel = 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) | ||
# status_pixel = 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) | ||
# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) | ||
wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) | ||
|
||
### Topic Setup ### | ||
|
||
|
@@ -109,9 +109,9 @@ def publish(client, userdata, topic, pid): | |
|
||
# Set up a MiniMQTT Client | ||
client = MQTT.MQTT( | ||
broker=secrets["broker"], | ||
username=secrets["user"], | ||
password=secrets["pass"], | ||
broker=broker, | ||
username=username, | ||
password=password, | ||
socket_pool=pool, | ||
ssl_context=ssl_context, | ||
) | ||
|
@@ -123,17 +123,17 @@ def publish(client, userdata, topic, pid): | |
client.on_unsubscribe = unsubscribe | ||
client.on_publish = publish | ||
|
||
print("Attempting to connect to %s" % client.broker) | ||
print(f"Attempting to connect to {client.broker}") | ||
client.connect() | ||
|
||
print("Subscribing to %s" % mqtt_topic) | ||
print(f"Subscribing to {mqtt_topic}") | ||
client.subscribe(mqtt_topic) | ||
|
||
print("Publishing to %s" % mqtt_topic) | ||
print(f"Publishing to {mqtt_topic}") | ||
client.publish(mqtt_topic, "Hello Broker!") | ||
|
||
print("Unsubscribing from %s" % mqtt_topic) | ||
print(f"Unsubscribing from {mqtt_topic}") | ||
client.unsubscribe(mqtt_topic) | ||
|
||
print("Disconnecting from %s" % client.broker) | ||
print(f"Disconnecting from {client.broker}") | ||
client.disconnect() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we stick with broker env var lookup and fall back to io.adafruit.com using the second parameter / default value, as this example isn't really IO related (just a good test server if the user already has an account). Similarly here: https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/pull/245/files#diff-afdace9507c758aee40533c5ef2f1cacbfe152f00f601e2fc07571931dfa63f8R16 which is
examples/esp32spi/minimqtt_certificate_esp32spi.py
line 16.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tyeth , so do:
in this one?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, something like that. think i spotted "broker" in a few other places too (just glancing at the connect lines)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will find all of these and make sure they are updated correctly. Will hold until I get other answers to do the work