1
1
// This example uses an Arduino/Genuino Zero together with
2
- // a WiFi101 Shield or a MKR1000 to connect to shiftr.io .
2
+ // a WiFi101 Shield or a MKR1000 to connect to AWS IOT .
3
3
//
4
4
// IMPORTANT: This example uses the new WiFi101 library.
5
5
//
6
6
// IMPORTANT: You need to install/update the SSL certificates first:
7
7
// https://github.com/arduino-libraries/WiFi101-FirmwareUpdater#to-update-ssl-certificates
8
8
//
9
- // You can check on your device after a successful
10
- // connection here: https://shiftr.io/try.
11
9
//
12
10
// by Gilberto Conti
13
11
// https://github.com/256dpi/arduino-mqtt
16
14
#include < MQTTClient.h>
17
15
#include < ArduinoBearSSL.h>
18
16
19
- const char ssid[] = " ssid" ;
20
- const char pass[] = " pass" ;
17
+ // ssid and pass are the wifi settings
18
+ const char ssid[] = " XXX" ;
19
+ const char pass[] = " XXX" ;
21
20
21
+ // server is the url of aws IOT
22
22
const char server[] = " xxxxxxxxxxxxxx.iot.xx-xxxx-x.amazonaws.com" ;
23
23
24
+ // id is the ThingName in aws IOT
25
+ const char id[] = " XXX"
26
+
24
27
// Get the cert data by:
25
28
// 1) Creating a CSR using the ArduinoBearSSL -> Tools -> ECC508CSR example for key slot 0
26
29
// 2) Creating a new thing and uploading the CSR for it
27
30
// 3) Downloading the public key for the thing in AWS IoT
28
31
// 4) Convert the base64 encoded cert to binary
29
32
const byte cert[] = {
30
- // ...
33
+ // ...
31
34
};
32
35
33
36
WiFiClient wifiClient;
@@ -65,15 +68,14 @@ void connect() {
65
68
}
66
69
67
70
Serial.print (" \n connecting..." );
68
- while (!client.connect (" arduino " )) {
71
+ while (!client.connect (id )) {
69
72
Serial.print (" ." );
70
73
delay (1000 );
71
74
}
72
75
73
76
Serial.println (" \n connected!" );
74
77
75
- client.subscribe (" /hello" );
76
- // client.unsubscribe("/hello");
78
+ client.subscribe (" $aws/things/" + id + " /test" );
77
79
}
78
80
79
81
void loop () {
@@ -86,10 +88,10 @@ void loop() {
86
88
// publish a message roughly every second.
87
89
if (millis () - lastMillis > 1000 ) {
88
90
lastMillis = millis ();
89
- client.publish (" /hello " , " world" );
91
+ client.publish (" $aws/things/ " + id + " /status " , " hello world" );
90
92
}
91
93
}
92
94
93
95
void messageReceived (String &topic, String &payload) {
94
96
Serial.println (" incoming: " + topic + " - " + payload);
95
- }
97
+ }
0 commit comments