Skip to content

Commit 38398be

Browse files
brentrubrentru
authored andcommitted
linting!
1 parent dd766c8 commit 38398be

2 files changed

Lines changed: 19 additions & 23 deletions

File tree

PyPortal_GCP_IOT_Planter/code.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@
88
"""
99
import time
1010
import json
11-
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
1211
import board
1312
import busio
14-
import digitalio
1513
import gcp_gfx_helper
1614
import neopixel
1715
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
16+
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
1817
from adafruit_gc_iot_core import MQTT_API, Cloud_Core
1918
from adafruit_minimqtt import MQTT
2019
from adafruit_seesaw.seesaw import Seesaw
21-
from digitalio import DigitalInOut
20+
import digitalio
2221

2322
# Delay before reading the sensors, in minutes
24-
# TODO: switch to 10min
25-
SENSOR_DELAY = 1
23+
SENSOR_DELAY = 10
2624

2725
# Get wifi details and more from a secrets.py file
2826
try:
@@ -32,15 +30,20 @@
3230
raise
3331

3432
# PyPortal ESP32 Setup
35-
esp32_cs = DigitalInOut(board.ESP_CS)
36-
esp32_ready = DigitalInOut(board.ESP_BUSY)
37-
esp32_reset = DigitalInOut(board.ESP_RESET)
33+
esp32_cs = digitalio.DigitalInOut(board.ESP_CS)
34+
esp32_ready = digitalio.DigitalInOut(board.ESP_BUSY)
35+
esp32_reset = digitalio.DigitalInOut(board.ESP_RESET)
3836
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
3937
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
4038
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
4139
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(
4240
esp, secrets, status_light)
4341

42+
# Connect to WiFi
43+
print("Connecting to WiFi...")
44+
wifi.connect()
45+
print("Connected!")
46+
4447
# Soil Sensor Setup
4548
i2c_bus = busio.I2C(board.SCL, board.SDA)
4649
ss = Seesaw(i2c_bus, addr=0x36)
@@ -54,15 +57,9 @@
5457
gfx = gcp_gfx_helper.Google_GFX()
5558
print("Graphics loaded!")
5659

57-
# Connect to WiFi
58-
print("Connecting to WiFi...")
59-
wifi.connect()
60-
print("Connected!")
6160

6261
# Define callback methods which are called when events occur
6362
# pylint: disable=unused-argument, redefined-outer-name
64-
65-
6663
def connect(client, userdata, flags, rc):
6764
# This function will be called when the client is connected
6865
# successfully to the broker.
@@ -96,12 +93,12 @@ def publish(client, userdata, topic, pid):
9693
def message(client, topic, msg):
9794
# This method is called when the client receives data from a topic.
9895
try:
99-
# Attempt to load a JSON command
96+
# Attempt to decode a JSON command
10097
msg_dict = json.loads(msg)
10198
# Handle water-pump commands
10299
if msg_dict['pump_time']:
103100
handle_pump(msg_dict)
104-
except:
101+
except TypeError:
105102
# Non-JSON command, print normally
106103
print("Message from {}: {}".format(topic, msg))
107104

@@ -135,16 +132,16 @@ def handle_pump(command):
135132
# Initialize Google Cloud IoT Core interface
136133
google_iot = Cloud_Core(esp, secrets)
137134

138-
# Optional JSON-Web-Token (JWT) Generation
139-
# print("Generating JWT...")
140-
# jwt = google_iot.generate_jwt()
141-
# print("Your JWT is: ", jwt)
135+
# JSON-Web-Token (JWT) Generation
136+
print("Generating JWT...")
137+
jwt = google_iot.generate_jwt()
138+
print("Your JWT is: ", jwt)
142139

143140
# Set up a new MiniMQTT Client
144141
client = MQTT(socket,
145142
broker=google_iot.broker,
146143
username=google_iot.username,
147-
password=secrets['jwt'],
144+
password=jwt,
148145
client_id=google_iot.cid,
149146
network_manager=wifi)
150147

PyPortal_GCP_IOT_Planter/gcp_gfx_helper.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""
2-
GFX Helper for PyPortal Azure IoT Plant Monitor
2+
GFX Helper for PyPortal GCP IoT Plant Monitor
33
"""
44
import board
55
import displayio
66
import terminalio
7-
from adafruit_bitmap_font import bitmap_font
87
from adafruit_display_text.label import Label
98

109
# the current working directory (where this file is)

0 commit comments

Comments
 (0)