Skip to content

Commit c6103d0

Browse files
matteosupposandeepmistry
authored andcommitted
Fix example to connect to aws
1 parent c1beb29 commit c6103d0

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

examples/WiFi101_AWS_IoT/WiFi101_AWS_IoT.ino

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// 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.
33
//
44
// IMPORTANT: This example uses the new WiFi101 library.
55
//
66
// IMPORTANT: You need to install/update the SSL certificates first:
77
// https://github.com/arduino-libraries/WiFi101-FirmwareUpdater#to-update-ssl-certificates
88
//
9-
// You can check on your device after a successful
10-
// connection here: https://shiftr.io/try.
119
//
1210
// by Gilberto Conti
1311
// https://github.com/256dpi/arduino-mqtt
@@ -16,18 +14,23 @@
1614
#include <MQTTClient.h>
1715
#include <ArduinoBearSSL.h>
1816

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";
2120

21+
// server is the url of aws IOT
2222
const char server[] = "xxxxxxxxxxxxxx.iot.xx-xxxx-x.amazonaws.com";
2323

24+
// id is the ThingName in aws IOT
25+
const char id[] = "XXX"
26+
2427
// Get the cert data by:
2528
// 1) Creating a CSR using the ArduinoBearSSL -> Tools -> ECC508CSR example for key slot 0
2629
// 2) Creating a new thing and uploading the CSR for it
2730
// 3) Downloading the public key for the thing in AWS IoT
2831
// 4) Convert the base64 encoded cert to binary
2932
const byte cert[] = {
30-
// ...
33+
// ...
3134
};
3235

3336
WiFiClient wifiClient;
@@ -65,15 +68,14 @@ void connect() {
6568
}
6669

6770
Serial.print("\nconnecting...");
68-
while (!client.connect("arduino")) {
71+
while (!client.connect(id)) {
6972
Serial.print(".");
7073
delay(1000);
7174
}
7275

7376
Serial.println("\nconnected!");
7477

75-
client.subscribe("/hello");
76-
// client.unsubscribe("/hello");
78+
client.subscribe("$aws/things/" + id + "/test");
7779
}
7880

7981
void loop() {
@@ -86,10 +88,10 @@ void loop() {
8688
// publish a message roughly every second.
8789
if (millis() - lastMillis > 1000) {
8890
lastMillis = millis();
89-
client.publish("/hello", "world");
91+
client.publish("$aws/things/" + id + "/status", "hello world");
9092
}
9193
}
9294

9395
void messageReceived(String &topic, String &payload) {
9496
Serial.println("incoming: " + topic + " - " + payload);
95-
}
97+
}

0 commit comments

Comments
 (0)