Skip to content

Commit c8aa84c

Browse files
brentrubrentru
authored andcommitted
fix width
1 parent 9807caf commit c8aa84c

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

PyPortal_AWS_IOT_Planter/aws_gfx_helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, is_celsius=False):
4343

4444
print('Setting up labels...')
4545
header_group = displayio.Group(scale=3)
46-
header_label = Label(font, text="AWS IoT\n Planter")
46+
header_label = Label(font, text=" AWS IoT\n Planter")
4747
header_label.x = (self.display.width // 2) // 22
4848
header_label.y = 15
4949
header_group.append(header_label)
@@ -78,7 +78,7 @@ def __init__(self, is_celsius=False):
7878
# AWS Status
7979
status_group = displayio.Group()
8080
self.aws_status_label = Label(font, text="Connecting to AWS IoT...")
81-
self.aws_status_label.x = self.display.width//4
81+
self.aws_status_label.x = int(self.display.width//3.5)
8282
self.aws_status_label.y = 200
8383
status_group.append(self.aws_status_label)
8484
self._text_group.append(status_group)
@@ -146,4 +146,4 @@ def set_icon(self, filename):
146146

147147
self._icon_group.append(self._icon_sprite)
148148
self.display.refresh_soon()
149-
self.display.wait_for_frame()
149+
self.display.wait_for_frame()

PyPortal_AWS_IOT_Planter/code.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(
6363
esp, secrets, status_light)
6464

65+
# Initialize the graphics helper
66+
print("Loading AWS IoT Graphics...")
67+
gfx = aws_gfx_helper.AWS_GFX()
68+
print("Graphics loaded!")
69+
6570
# Set AWS Device Certificate
6671
esp.set_certificate(DEVICE_CERT)
6772

@@ -77,48 +82,40 @@
7782
i2c_bus = busio.I2C(board.SCL, board.SDA)
7883
ss = Seesaw(i2c_bus, addr=0x36)
7984

80-
# Initialize the graphics helper
81-
print("Loading AWS IoT Graphics...")
82-
gfx = aws_gfx_helper.AWS_GFX()
83-
print("Graphics loaded!")
84-
85-
8685
# Define callback methods which are called when events occur
8786
# pylint: disable=unused-argument, redefined-outer-name
8887
def connect(client, userdata, flags, rc):
8988
# This function will be called when the client is connected
9089
# successfully to the broker.
9190
print('Connected to AWS IoT!')
9291
print('Flags: {0}\nRC: {1}'.format(flags, rc))
93-
# TODO: Subscribe to shadow topics!
92+
93+
# Subscribe client to all shadow updates
94+
print("Subscribing to shadow updates...")
95+
aws_iot.shadow_subscribe()
9496

9597

9698
def disconnect(client, userdata, rc):
9799
# This method is called when the client disconnects
98100
# from the broker.
99101
print('Disconnected from AWS IoT!')
100102

101-
102103
def subscribe(client, userdata, topic, granted_qos):
103104
# This method is called when the client subscribes to a new topic.
104105
print('Subscribed to {0} with QOS level {1}'.format(topic, granted_qos))
105106

106-
107107
def unsubscribe(client, userdata, topic, pid):
108108
# This method is called when the client unsubscribes from a topic.
109109
print('Unsubscribed from {0} with PID {1}'.format(topic, pid))
110110

111-
112111
def publish(client, userdata, topic, pid):
113112
# This method is called when the client publishes data to a topic.
114113
print('Published to {0} with PID {1}'.format(topic, pid))
115114

116-
117115
def message(client, topic, msg):
118116
# This method is called when the client receives data from a topic.
119117
print("Message from {}: {}".format(topic, msg))
120118

121-
122119
# Set up a new MiniMQTT Client
123120
client = MQTT(socket,
124121
broker = secrets['broker'],
@@ -146,7 +143,7 @@ def message(client, topic, msg):
146143
try:
147144
gfx.show_aws_status('Listening for msgs...')
148145
now = time.monotonic()
149-
if now - initial > (1 * 60):
146+
if now - initial > (0.5 * 60):
150147
# read moisture level
151148
moisture = ss.moisture_read()
152149
print("Moisture Level: ", moisture)
@@ -172,4 +169,4 @@ def message(client, topic, msg):
172169
except (ValueError, RuntimeError) as e:
173170
print("Failed to get data, retrying", e)
174171
wifi.reset()
175-
continue
172+

0 commit comments

Comments
 (0)