6262wifi = 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
6671esp .set_certificate (DEVICE_CERT )
6772
7782i2c_bus = busio .I2C (board .SCL , board .SDA )
7883ss = 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
8887def 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}\n RC: {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
9698def 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-
102103def 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-
107107def 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-
112111def 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-
117115def 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
123120client = 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