Skip to content

Commit 6b78887

Browse files
author
Alberto Iannaccone
committed
connect to vernemq
1 parent 29c5299 commit 6b78887

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

examples/utility/Provisioning/Provisioning.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ void setup() {
5555
while (1);
5656
}
5757

58-
ECCX08Cert.setSubjectCommonName(ECCX08.serialNumber());
58+
String thingId = promptAndReadLine("Please enter the thing id: ");
59+
ECCX08Cert.setSubjectCommonName(thingId);
5960

6061
String csr = ECCX08Cert.endCSR();
6162

@@ -68,7 +69,6 @@ void setup() {
6869
Serial.println();
6970
Serial.println(csr);
7071

71-
String thingId = promptAndReadLine("Please enter the thing id: ");
7272
String issueYear = promptAndReadLine("Please enter the issue year of the certificate (2000 - 2031): ");
7373
String issueMonth = promptAndReadLine("Please enter the issue month of the certificate (1 - 12): ");
7474
String issueDay = promptAndReadLine("Please enter the issue day of the certificate (1 - 31): ");

src/ArduinoCloud.cpp

+25-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <utility/ECCX08Cert.h>
55
#include "CloudSerial.h"
66

7-
const static char server[] = "a19g5nbe27wn47.iot.us-east-1.amazonaws.com"; //"xxxxxxxxxxxxxx.iot.xx-xxxx-x.amazonaws.com";
7+
const static char server[] = "mqtts-sa.iot.oniudra.cc";
88

99
const static int keySlot = 0;
1010
const static int compressedCertSlot = 10;
@@ -42,7 +42,7 @@ int ArduinoCloudClass::begin(Client& net)
4242
return 0;
4343
}
4444

45-
ECCX08Cert.setSubjectCommonName(ECCX08.serialNumber());
45+
ECCX08Cert.setSubjectCommonName(_id);
4646
ECCX08Cert.setIssuerCountryName("US");
4747
ECCX08Cert.setIssuerOrganizationName("Arduino LLC US");
4848
ECCX08Cert.setIssuerOrganizationalUnitName("IT");
@@ -52,6 +52,21 @@ int ArduinoCloudClass::begin(Client& net)
5252
return 0;
5353
}
5454

55+
Serial.println("Compressed cert = ");
56+
57+
const byte* certData = ECCX08Cert.bytes();
58+
int certLength = ECCX08Cert.length();
59+
60+
for (int i = 0; i < certLength; i++) {
61+
byte b = certData[i];
62+
63+
if (b < 16) {
64+
Serial.print('0');
65+
}
66+
Serial.print(b, HEX);
67+
}
68+
Serial.println();
69+
5570
if (_bearSslClient) {
5671
delete _bearSslClient;
5772
}
@@ -70,19 +85,19 @@ int ArduinoCloudClass::begin(Client& net)
7085
void ArduinoCloudClass::mqttClientBegin(Client& net)
7186
{
7287
// MQTT topics definition
73-
_stdoutTopic = "$aws/things/" + _id + "/stdout";
74-
_stdinTopic = "$aws/things/" + _id + "/stdin";
75-
_dataTopicIn = "$aws/things/" + _id + "/datain";
76-
_dataTopicOut = "$aws/things/" + _id + "/dataout";
88+
_stdoutTopic = "/a/d/" + _id + "/s/o";
89+
_stdinTopic = "/a/d/" + _id + "/s/i";
90+
_dataTopicIn = "/a/d/" + _id + "/e/i";
91+
_dataTopicOut = "/a/d/" + _id + "/e/o";
7792

7893
// use onMessage as callback for received mqtt messages
7994
_mqttClient.onMessageAdvanced(ArduinoCloudClass::onMessage);
8095
_mqttClient.begin(server, 8883, net);
8196
// Set will for MQTT client: {topic, qos, retain message}
82-
// const char lastMessage[] = "abcb";
83-
// _mqttClient.setWill(_dataTopicOut.c_str(), lastMessage, false, 1);
84-
// // Set MQTT connection options
85-
// _mqttClient.setOptions(mqttOpt.keepAlive, mqttOpt.cleanSession, mqttOpt.timeout);
97+
const char lastMessage[] = "abcb";
98+
_mqttClient.setWill(_dataTopicOut.c_str(), lastMessage, false, 1);
99+
// Set MQTT connection options
100+
_mqttClient.setOptions(mqttOpt.keepAlive, mqttOpt.cleanSession, mqttOpt.timeout);
86101
}
87102

88103
int ArduinoCloudClass::connect()

0 commit comments

Comments
 (0)