Hi, I’m new to particle and using an Argon with the firmware 1.5.2.
I need to connect my Argon to my AWS IoT Core preferable over MQTT with TLS, I tried to use the MQTT-TLS library but failed as i can’t get a connection to the server. I checked my certificates and key in MQTT.fx, there they work just fine.
I also tried to use the example1 but failed there too.
My code:
#include <Grove_Temperature_And_Humidity_Sensor.h>
#include <MQTT-TLS.h>
#include <certificates.h>
void callback(char* topic, byte* payload, unsigned int length);
MQTT client("a17c5omik6yjsa-ats.iot.eu-central-1.amazonaws.com", 8883, callback);
const char amazonIoTRootCAPem[] = AMAZON_IOT_ROOT_CA_PEM;
const char clientKeyCrtPem[] = CLIENT_KEY_CRT_PEM;
const char clientKeyPem[] = CLIENT_KEY_PEM;
DHT temp(D2);
String tempString;
void callback(char* topic, byte* payload, unsigned int length) {
char p[length + 1];
memcpy(p, payload, length);
p[length] = NULL;
String message(p);
}
// setup() runs once, when the device is first turned on.
void setup() {
// Put initialization like pinMode and begin functions here.
//Start the Temp/Hum sensor
temp.begin();
// Enable TLS on the MQTT client
client.enableTls(amazonIoTRootCAPem, sizeof(amazonIoTRootCAPem),
clientKeyCrtPem, sizeof(clientKeyCrtPem),
clientKeyPem, sizeof(clientKeyPem));
client.connect("TempHum_Sensor1");
Particle.publish("co", String(client.connect("adfahsdf")),PRIVATE);
client.publish("TempHum_Sensor/test", "hallo");
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
// The core of your code will likely live here.
tempString = String(temp.getTempCelcius());
//Particle.publish("temperature", tempString, PRIVATE);
if (client.isConnected()){
Serial.println("connected");
Particle.publish("connected", "conn",PRIVATE);
client.loop();
client.publish("TempHum_Sensor/test", "hii");
} else {
Particle.publish("connected", "not", PRIVATE);
}
delay(10000);
}
I think the problem might be the certificate part as I’m not sure about the formatting, I formatted everything to match the formatting of the examples.
Here is the code of my certificates.h file:
#define AMAZON_IOT_ROOT_CA_PEM \
"-----BEGIN CERTIFICATE----- \r\n" \
"MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF\r\n" \
"ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\r\n" \
"b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL\r\n" \
"MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv\r\n" \
.....
"5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy\r\n" \
"rqXRfboQnoZsG4q5WTP468SQvvG5\r\n" \
"-----END CERTIFICATE----- "
#define CLIENT_KEY_CRT_PEM \
"-----BEGIN CERTIFICATE----- \r\n" \
"MIIDWTCCAkGgAwIBAgIUN94dGYvsTJoeQvwxz6JgJcdOWjUwDQYJKoZIhvcNAQEL\r\n" \
"BQAwTTFLMEkGA1UECwxCQW1hem9uIFdlYiBTZXJ2aWNlcyBPPUFtYXpvbi5jb20g\r\n" \
....
"IdGvOolrrjKBhaGyutj4VsS3LZU8hraii+rQyfD5pJ7M8qQ+0ODV37b8Nb9Y\r\n" \
"-----END CERTIFICATE-----\r\n"
#define CLIENT_KEY_PEM \
"-----BEGIN RSA PRIVATE KEY----- \r\n" \
"MIIEowIBAAKCAQEA2dS+/HsIGCN6d0tz+BZQ8eNj18OiyjNBzevQEdJ4tRKcfXgk\r\n" \
"GkoDy/PPEjVQyuhd/2wLhp2zJX26ZnNPjyr4wy+UtdXPIElMwTYLI1Hf7s60+2o7\r\n" \
....
"JnrlUw37EZMHI6EFF8AaVHRGshoOge8X9Xg8WJelwTkTZo38lZzU\r\n" \
"-----END RSA PRIVATE KEY-----\r\n"\
Do you have any idea why it doesn’t work?
Thanks!