6
6
#include < ArduinoJson.h>
7
7
#include " WiFi.h"
8
8
9
- // The MQTT topics that this device should publish/subscribe
10
9
#define AWS_IOT_PUBLISH_TOPIC " esp32/pub"
11
10
#define AWS_IOT_SUBSCRIBE_TOPIC " esp32/sub"
12
11
@@ -37,16 +36,14 @@ void connectAWS()
37
36
}
38
37
39
38
Serial.println (" Connecting AWS" );
40
- // Configure WiFiClientSecure to use the AWS IoT device credentials
39
+
41
40
net.setCACert (AWS_CERT_CA);
42
41
net.setCertificate (AWS_CERT_CRT);
43
42
net.setPrivateKey (AWS_CERT_PRIVATE);
44
43
45
44
Serial.println (" Connecting to Endpoint" );
46
- // Connect to the MQTT broker on the AWS endpoint we defined earlier
47
45
client.setServer (AWS_IOT_ENDPOINT, 8883 );
48
46
49
- // Create a message handler
50
47
client.setCallback (messageHandler);
51
48
52
49
Serial.print (" Connecting to AWS IOT" );
@@ -62,7 +59,6 @@ void connectAWS()
62
59
}
63
60
64
61
Serial.print (" Subscribing to the topic" );
65
- // Subscribe to a topic
66
62
client.subscribe (AWS_IOT_SUBSCRIBE_TOPIC);
67
63
68
64
Serial.println (" AWS IoT Connected!" );
@@ -72,9 +68,8 @@ void publishMessage()
72
68
{
73
69
StaticJsonDocument<200 > doc;
74
70
doc[" time" ] = millis ();
75
- doc[" sensor_a0" ] = analogRead (0 );
76
71
char jsonBuffer[512 ];
77
- serializeJson (doc, jsonBuffer); // print to client
72
+ serializeJson (doc, jsonBuffer);
78
73
79
74
client.publish (AWS_IOT_PUBLISH_TOPIC, jsonBuffer);
80
75
Serial.println (" published" );
0 commit comments