emile
September 24, 2019, 10:22am
1
I’m looking at building a mesh network with Xenons for nodes to a gateway that is connected to AWS IoT.
Is it possible to add certificates to the Xenons for communication directly with AWS? I do not think so, but I wanted to raise the question in case I’m no thinking of something.
emile
September 24, 2019, 10:46am
2
Wasn’t thinking of this, but here’s an example in MQTT-TLS of just copying the cert into the .ino
file. I guess that would do it.
#include "MQTT-TLS.h"
void callback(char* topic, byte* payload, unsigned int length);
#define LET_ENCRYPT_CA_PEM \
"-----BEGIN CERTIFICATE----- \r\n" \
"MIIFjTCCA3WgAwIBAgIRANOxciY0IzLc9AUoUSrsnGowDQYJKoZIhvcNAQELBQAw\r\n" \
"TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh\r\n" \
"cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTYxMDA2MTU0MzU1\r\n" \
"WhcNMjExMDA2MTU0MzU1WjBKMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNTGV0J3Mg\r\n" \
"RW5jcnlwdDEjMCEGA1UEAxMaTGV0J3MgRW5jcnlwdCBBdXRob3JpdHkgWDMwggEi\r\n" \
"MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCc0wzwWuUuR7dyXTeDs2hjMOrX\r\n" \
"NSYZJeG9vjXxcJIvt7hLQQWrqZ41CFjssSrEaIcLo+N15Obzp2JxunmBYB/XkZqf\r\n" \
"89B4Z3HIaQ6Vkc/+5pnpYDxIzH7KTXcSJJ1HG1rrueweNwAcnKx7pwXqzkrrvUHl\r\n" \
"Npi5y/1tPJZo3yMqQpAMhnRnyH+lmrhSYRQTP2XpgofL2/oOVvaGifOFP5eGr7Dc\r\n" \
"Gu9rDZUWfcQroGWymQQ2dYBrrErzG5BJeC+ilk8qICUpBMZ0wNAxzY8xOJUWuqgz\r\n" \
"uEPxsR/DMH+ieTETPS02+OP88jNquTkxxa/EjQ0dZBYzqvqEKbbUC8D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FYs1JKY\r\n" \
"2PGDuWx8M6DlS6qQkvHaRUo0FMd8TsSlbF0/v965qGFKhSDeQoMpYnwcmQilRh/0\r\n" \
"ayLThlHLN81gSkJjVrPI0Y8xCVPB4twb1PFUd2fPM3sA1tJ83sZ5v8vgFv2yofKR\r\n" \
"PB0t6JzUA81mSqM3kxl5e+IZwhYAyO0OTg3/fs8HqGTNKd9BqoUwSRBzp06JMg5b\r\n" \
"rUCGwbCUDI0mxadJ3Bz4WxR6fyNpBK2yAinWEsikxqEt\r\n" \
"-----END CERTIFICATE----- "
const char letencryptCaPem[] = LET_ENCRYPT_CA_PEM;
/**
* if want to use IP address,
* byte server[] = { XXX,XXX,XXX,XXX };
* MQTT client(server, 1883, callback);
* want to use domain name,
* MQTT client("www.sample.com", 1883, callback);
* iot.eclipse.org is Eclipse Open MQTT Broker: https://iot.eclipse.org/getting-started
**/
MQTT client("iot.eclipse.org", 8883, callback);
// recieve message
void callback(char* topic, byte* payload, unsigned int length) {
char p[length + 1];
memcpy(p, payload, length);
p[length] = NULL;
String message(p);
if (message.equals("RED"))
RGB.color(255, 0, 0);
else if (message.equals("GREEN"))
RGB.color(0, 255, 0);
else if (message.equals("BLUE"))
RGB.color(0, 0, 255);
else
RGB.color(255, 255, 255);
delay(1000);
}
#define ONE_DAY_MILLIS (24 * 60 * 60 * 1000)
unsigned long lastSync = millis();
void setup() {
if (millis() - lastSync > ONE_DAY_MILLIS) {
Particle.syncTime();
lastSync = millis();
}
RGB.control(true);
// enable tls. set Root CA pem file.
// if you don't use TLS, comment out this line.
client.enableTls(letencryptCaPem, sizeof(letencryptCaPem));
Serial.println("tls enable");
// connect to the server
client.connect("sparkclient");
// publish/subscribe
if (client.isConnected()) {
Serial.println("client connected");
client.publish("outTopic/message", "hello world");
client.subscribe("inTopic/message");
}
}
void loop() {
if (client.isConnected())
client.loop();
delay(200);
}
You won’t be able to do that because the Thread Mesh network does not support TCP to mesh-only nodes. It only supports UDP.
The MQTT-TLS protocol only works over TCP, so it can’t be used on a Xenon mesh node.
Gateway nodes like the Argon (Wi-Fi), Boron (cellular) and Xenon with Ethernet do support TCP.
What you could do is write some gateway code that will run on the Argon or Boron. You would have your Xenons talk with the gateway (Argon or Boron) and then have the gateway perform the TCP-based communications to AWS.
The gateway node would “listen” on the mesh network using the Mesh.subscribe() method, and the Xenons would use the Mesh.publish() to send their data. Note that the Mesh methods are not reliable, and so you might have to implement your own ACK protocol.
Read more here: Current reliability of Mesh.publish messages
If you used this method, the gateway receiving your messages via the Mesh.subscribe() can then publish the information however it wants to.
emile
September 24, 2019, 10:19pm
5
Ah, I didn’t realize it was only UDP. Thanks for the heads up. I guess that answers that!
emile
September 24, 2019, 10:25pm
6
Good call. Thats what I was looking at doing at a macro level.
I was looking at setting up the AWS client on the Xenon for the state of the device via AWS device shadow
. However it looks like Particle.connected()
would return similar results.
I just thought of one other possibility.
You can send UDP to the Internet directly from the Xenon. So you could use CoAP or implement your own UDP protocol.
You can read about UDP to the Internet in this post, under the section called “UDP”: Sending data with mesh devices
There is also a guy who wrote a CoAP gateway in the cloud for interfacing with AWS IoT: https://github.com/AndrewFarley/coap-for-aws-iot
I haven’t tried either yet … but they are on my ToDo list …
1 Like