forked from universam1/iSpindel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit to provide secureMQTT with X.509 certs as an option in sender …
…class (universam1#451) * Commit to provide secureMQTT with X.509 certs as an option in sender This is pre-cursor work to AWS IoT Core integration option that required secure connection. The main features here are: 1) Creation of a method, SenderClass::SendSecureMQTT which is a copy of SendMQTT class with parameters for secure connections 2) Modification of SenderClass::MQTTConnect to select WifiClient or WifiClientSecure object based on input parameters 3) Due to memory constraint I had to reduce JSON buffer to 256 from 1024 in sender.h. This seems to be sufficient from checks I did on ArduinoJSON test site for the standard messages we send. I chose this approach to avoid changes to other areas of the code. I will submit a seperate pull request with changes to Globals, iSpindel.cpp and WifiManager to enable AWS as a connection option * Commit to provide secureMQTT with X.509 certs as an option in sender This is pre-cursor work to AWS IoT Core integration option that required secure connection. The main features here are: 1) Creation of a method, SenderClass::SendSecureMQTT which is a copy of SendMQTT class with parameters for secure connections 2) Modification of SenderClass::MQTTConnect to select WifiClient or WifiClientSecure object based on input parameters 3) Due to memory constraint I had to reduce JSON buffer to 256 from 1024 in sender.h. This seems to be sufficient from checks I did on ArduinoJSON test site for the standard messages we send. I chose this approach to avoid changes to other areas of the code. I will submit a seperate pull request with changes to Globals, iSpindel.cpp and WifiManager to enable AWS as a connection option * Successful connection to AWS MQTT using secrets.h You need to cut and paste the relevant cert and key data into secrets.h MQTT publish reformatted to support AWS Thing Shadow JSON format * add secrets.h to gitignore * Clean Up UI as requested by universam1 * Remove AWS from core UI and add readme_aws
- Loading branch information
Showing
8 changed files
with
160 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ iSpindel/__vm/ | |
.cproject | ||
.project | ||
.settings | ||
pio/src/secrets.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*AWS IoT Conectivity* | ||
ADVANCED USERS ONLY | ||
|
||
Recently we have started to add support for AWS IOT Core using the Secure MQTT option. | ||
|
||
This option currently requires you to manually input your keys and certs into the secrets.h file, compile and upload yourself. | ||
We are looking to add the ability to upload a certificate in future. | ||
|
||
0. Configure AWS IoT core including creating your thing, certificates, policies and download your certs and keys | ||
1. Download the Repo | ||
2. Edit secrets.h to supply AWS Root Cert, Device Private Cert, Device Private Key | ||
3. Compile and upload to your iSpindel | ||
4. Configure using the config menu as normal with the AWSIOTMQTT option | ||
|
||
Note: Secure MQTT (required by AWS) using a lot more battery as the device has to be on longer during each send. It needs to sync to an NTP server and establish and encrypted connection - both of which require processing time and hence battery use on the ESP8266. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ All rights reserverd by S.Lang <[email protected]> | |
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino | ||
#include <FS.h> //this needs to be first | ||
#include "tinyexpr.h" | ||
#include "secrets.h" //AWS - Currently a file for Keys, Certs, etc - Need to make this a captured variable for iSpindle | ||
|
||
#include "Sender.h" | ||
// !DEBUG 1 | ||
|
@@ -360,6 +361,8 @@ bool startConfiguration() | |
WiFiManagerParameter custom_tempscale("tempscale", "tempscale", | ||
String(my_tempscale).c_str(), | ||
5, TYPE_HIDDEN, WFM_NO_LABEL); | ||
WiFiManagerParameter custom_warning1("warning1","WARNING! Secure MQTT has a big impact on battery usage.<BR> <BR>For AWS:<UL><LI>Name must be Thingname</LI><LI>Server must be Endpoint</LI><LI>Port must be 8883</LI><LI>Path/URI is Publish Topic</LI></UL>", | ||
"<<<<< >>>>>",TKIDSIZE); | ||
|
||
wifiManager.addParameter(&custom_name); | ||
wifiManager.addParameter(&custom_sleep); | ||
|
@@ -375,6 +378,7 @@ bool startConfiguration() | |
wifiManager.addParameter(&api_list); | ||
wifiManager.addParameter(&custom_api); | ||
|
||
wifiManager.addParameter(&custom_warning1); | ||
wifiManager.addParameter(&custom_token); | ||
wifiManager.addParameter(&custom_server); | ||
wifiManager.addParameter(&custom_port); | ||
|
@@ -559,6 +563,22 @@ bool uploadData(uint8_t service) | |
} | ||
#endif | ||
|
||
#ifdef API_AWSIOTMQTT //AWS | ||
if (service == DTAWSIOTMQTT) | ||
{ | ||
sender.add("name", my_name); | ||
sender.add("tilt", Tilt); | ||
sender.add("temperature", scaleTemperature(Temperatur)); | ||
sender.add("battery", Volt); | ||
sender.add("gravity", Gravity); | ||
sender.add("interval", my_sleeptime); | ||
sender.add("RSSI", WiFi.RSSI()); | ||
CONSOLELN("Calling AWSIOTMQTT Sender"); | ||
return sender.sendSecureMQTT(AWS_CERT_CA, AWS_CERT_CRT, AWS_CERT_PRIVATE, my_server, my_port, my_name, my_uri); | ||
//AWS - NOTE - Need to replace secrets.h with the relevant parameters | ||
} | ||
#endif | ||
|
||
#ifdef API_MQTT | ||
if (service == DTMQTT) | ||
{ | ||
|
@@ -1105,6 +1125,7 @@ bool isSafeMode(float _volt) | |
bool connectBackupCredentials() | ||
{ | ||
WiFi.disconnect(); | ||
WiFi.mode(WIFI_STA); //suggestion that MQTT connection failures can happen if WIFI mode isn't STA. | ||
WiFi.begin(my_ssid.c_str(), my_psk.c_str()); | ||
CONSOLELN(F("Rescued Wifi credentials")); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <pgmspace.h> | ||
|
||
// Amazon Root CA 1 | ||
char AWS_CERT_CA[] PROGMEM = R"EOF( | ||
-----BEGIN CERTIFICATE----- | ||
MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF | ||
.... | ||
rqXRfboQnoZsG4q5WTP468SQvvG5 | ||
-----END CERTIFICATE----- | ||
)EOF"; | ||
|
||
// Device Certificate | ||
char AWS_CERT_CRT[] PROGMEM = R"EOF( | ||
-----BEGIN CERTIFICATE----- | ||
MIIDWjCCAkKgAwIBAgIVAJWkLwCw4/J6kFdfGOc6Iy7oUdblMA0GCSqGSIb3DQEB | ||
... | ||
lO/ftnkLAtFdfdEYNRt4Pwnzz5dMzIy4BFjxIc9TEWUlQfYts+MKeXJZPN1R6Q== | ||
-----END CERTIFICATE----- | ||
)EOF"; | ||
|
||
// Device Private Key | ||
char AWS_CERT_PRIVATE[] PROGMEM = R"KEY( | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEpQIBAAKCAQEAzSJSdu9I/rp7x2SoIDwor+fANnwc77OY58I6Ayd74abqUP0x | ||
... | ||
yWtqFU/uV4LPITfESKnVUUYK39kPRwvuxtDN0pq/mHfD5xnzkLMNPCk= | ||
-----END RSA PRIVATE KEY----- | ||
)KEY"; |