Skip to content

Commit ff90ddb

Browse files
committed
Add comment in example sketches about connecting with SSL/TLS
1 parent 383a2ca commit ff90ddb

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

examples/WiFiAdvancedCallback/WiFiAdvancedCallback.ino

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@
2323
char ssid[] = SECRET_SSID; // your network SSID (name)
2424
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
2525

26+
// To connect with SSL/TLS:
27+
// 1) Change WiFiClient to WiFiSSLClient.
28+
// 2) Change port value from 1883 to 8883.
29+
// 3) Change broker value to a server with a known SSL/TLS root certificate
30+
// flashed in the WiFi module.
31+
2632
WiFiClient wifiClient;
2733
MqttClient mqttClient(wifiClient);
2834

2935
const char broker[] = "test.mosquitto.org";
36+
int port = 1883;
3037
const char willTopic[] = "arduino/will";
3138
const char inTopic[] = "arduino/in";
3239
const char outTopic[] = "arduino/out";
@@ -75,7 +82,7 @@ void setup() {
7582
Serial.print("Attempting to connect to the MQTT broker: ");
7683
Serial.println(broker);
7784

78-
if (!mqttClient.connect(broker, 1883)) {
85+
if (!mqttClient.connect(broker, port)) {
7986
Serial.print("MQTT connection failed! Error code = ");
8087
Serial.println(mqttClient.connectError());
8188

examples/WiFiEcho/WiFiEcho.ino

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@
1919
char ssid[] = SECRET_SSID; // your network SSID (name)
2020
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
2121

22+
// To connect with SSL/TLS:
23+
// 1) Change WiFiClient to WiFiSSLClient.
24+
// 2) Change port value from 1883 to 8883.
25+
// 3) Change broker value to a server with a known SSL/TLS root certificate
26+
// flashed in the WiFi module.
27+
2228
WiFiClient wifiClient;
2329
MqttClient mqttClient(wifiClient);
2430

2531
const char broker[] = "test.mosquitto.org";
32+
int port = 1883;
33+
2634
const char topic[] = "arduino/echo";
2735

2836
const long interval = 1000;
@@ -59,7 +67,7 @@ void setup() {
5967
Serial.print("Attempting to connect to the MQTT broker: ");
6068
Serial.println(broker);
6169

62-
if (!mqttClient.connect(broker, 1883)) {
70+
if (!mqttClient.connect(broker, port)) {
6371
Serial.print("MQTT connection failed! Error code = ");
6472
Serial.println(mqttClient.connectError());
6573

examples/WiFiEchoCallback/WiFiEchoCallback.ino

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@
2020
char ssid[] = SECRET_SSID; // your network SSID (name)
2121
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
2222

23+
// To connect with SSL/TLS:
24+
// 1) Change WiFiClient to WiFiSSLClient.
25+
// 2) Change port value from 1883 to 8883.
26+
// 3) Change broker value to a server with a known SSL/TLS root certificate
27+
// flashed in the WiFi module.
28+
2329
WiFiClient wifiClient;
2430
MqttClient mqttClient(wifiClient);
2531

2632
const char broker[] = "test.mosquitto.org";
33+
int port = 1883;
2734
const char topic[] = "arduino/echo";
2835

2936
const long interval = 1000;
@@ -60,7 +67,7 @@ void setup() {
6067
Serial.print("Attempting to connect to the MQTT broker: ");
6168
Serial.println(broker);
6269

63-
if (!mqttClient.connect(broker, 1883)) {
70+
if (!mqttClient.connect(broker, port)) {
6471
Serial.print("MQTT connection failed! Error code = ");
6572
Serial.println(mqttClient.connectError());
6673

examples/WiFiSimpleReceive/WiFiSimpleReceive.ino

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@
1818
char ssid[] = SECRET_SSID; // your network SSID (name)
1919
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
2020

21+
// To connect with SSL/TLS:
22+
// 1) Change WiFiClient to WiFiSSLClient.
23+
// 2) Change port value from 1883 to 8883.
24+
// 3) Change broker value to a server with a known SSL/TLS root certificate
25+
// flashed in the WiFi module.
26+
2127
WiFiClient wifiClient;
2228
MqttClient mqttClient(wifiClient);
2329

2430
const char broker[] = "test.mosquitto.org";
31+
int port = 1883;
2532
const char topic[] = "arduino/simple";
2633

2734
void setup() {
@@ -53,7 +60,7 @@ void setup() {
5360
Serial.print("Attempting to connect to the MQTT broker: ");
5461
Serial.println(broker);
5562

56-
if (!mqttClient.connect(broker, 1883)) {
63+
if (!mqttClient.connect(broker, port)) {
5764
Serial.print("MQTT connection failed! Error code = ");
5865
Serial.println(mqttClient.connectError());
5966

examples/WiFiSimpleReceiveCallback/WiFiSimpleReceiveCallback.ino

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@
1919
char ssid[] = SECRET_SSID; // your network SSID (name)
2020
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
2121

22+
// To connect with SSL/TLS:
23+
// 1) Change WiFiClient to WiFiSSLClient.
24+
// 2) Change port value from 1883 to 8883.
25+
// 3) Change broker value to a server with a known SSL/TLS root certificate
26+
// flashed in the WiFi module.
27+
2228
WiFiClient wifiClient;
2329
MqttClient mqttClient(wifiClient);
2430

2531
const char broker[] = "test.mosquitto.org";
32+
int port = 1883;
2633
const char topic[] = "arduino/simple";
2734

2835
void setup() {
@@ -54,7 +61,7 @@ void setup() {
5461
Serial.print("Attempting to connect to the MQTT broker: ");
5562
Serial.println(broker);
5663

57-
if (!mqttClient.connect(broker, 1883)) {
64+
if (!mqttClient.connect(broker, port)) {
5865
Serial.print("MQTT connection failed! Error code = ");
5966
Serial.println(mqttClient.connectError());
6067

examples/WiFiSimpleSender/WiFiSimpleSender.ino

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@
1818
char ssid[] = SECRET_SSID; // your network SSID (name)
1919
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
2020

21+
// To connect with SSL/TLS:
22+
// 1) Change WiFiClient to WiFiSSLClient.
23+
// 2) Change port value from 1883 to 8883.
24+
// 3) Change broker value to a server with a known SSL/TLS root certificate
25+
// flashed in the WiFi module.
26+
2127
WiFiClient wifiClient;
2228
MqttClient mqttClient(wifiClient);
2329

2430
const char broker[] = "test.mosquitto.org";
31+
int port = 1883;
2532
const char topic[] = "arduino/simple";
2633

2734
const long interval = 1000;
@@ -58,7 +65,7 @@ void setup() {
5865
Serial.print("Attempting to connect to the MQTT broker: ");
5966
Serial.println(broker);
6067

61-
if (!mqttClient.connect(broker, 1883)) {
68+
if (!mqttClient.connect(broker, port)) {
6269
Serial.print("MQTT connection failed! Error code = ");
6370
Serial.println(mqttClient.connectError());
6471

0 commit comments

Comments
 (0)