Skip to content

Thing integration #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c56b9a8
Integrate ArduinoCloudThing
facchinm Feb 16, 2018
9aae39a
Fix .readOnly/.writeOnly compisition
facchinm Feb 22, 2018
6391cc6
Add addProperty API with complete signature
facchinm May 30, 2018
2406990
Initial testing on OTA
facchinm May 30, 2018
be06131
Merge remote-tracking branch 'bcmi/master' into thing_integration
facchinm May 30, 2018
543c75b
Port to fixed ArduinoCloudThing
facchinm May 30, 2018
ba5faf4
Add missing libraries
facchinm Jun 7, 2018
659608d
Fix addProperty macro, again
facchinm Jun 27, 2018
52e179d
Fix reference as value in addProperty signature
facchinm Jun 27, 2018
31d9eea
Call THing.poll with the new API
facchinm Jun 27, 2018
7a75314
TEMP: remove OTA stuff
facchinm Jul 3, 2018
11fe613
Add minDelta API and a bunch of overloaded not clashing calls
facchinm Jul 3, 2018
587ac05
Merge pull request #1 from facchinm/thing_integration
mastrolinux Jul 6, 2018
2c4971f
TEMP: fully remove OTA support
facchinm Aug 21, 2018
0b5fc7f
Remove useless dependency on HTTPClient
facchinm Aug 21, 2018
02a1994
Adapt to String property type
facchinm Aug 21, 2018
2989ad0
Add ability to add Authority Key Identifier to reconstructed SSL publ…
sandeepmistry Jul 24, 2018
9966adb
Set Authority Key Identifier when re-constructing cert
sandeepmistry Jul 24, 2018
1e3b023
Use ECCX08 slot to store Authority Key Identifier, and request in pro…
sandeepmistry Jul 25, 2018
50181e7
Combine certificate serial number and authority key identifier data i…
sandeepmistry Jul 26, 2018
b935975
Handle reconnection inside library
Sid23 Aug 31, 2018
3669b2c
use vernemq instance
Aug 31, 2018
cb8b549
Adapt provisioning to new backend infractructure
Aug 31, 2018
88e9cde
Fix getting started CloudSerial sketch
Aug 31, 2018
1ff100e
Merge branch 'thing_integration' into vernemq
facchinm Aug 31, 2018
82fb168
Split _dataTopic into In and Out
facchinm Aug 31, 2018
646c92a
Thing: use non-composition APIs
facchinm Sep 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 84 additions & 9 deletions examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
#include <WiFi101.h>
#include <WiFi101.h> // change to WiFiNINA.h if you are using the MKR WiFi 1010 or MKR Vidor 4000
#include <ArduinoCloudV2.h>

#include "arduino_secrets.h"

#define TIMEOUT 7000

///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS; // the WiFi radio's status
String cloudSerialBuffer = ""; // the string used to compose network messages from the received characters

WiFiClient wifiClient;

unsigned long getTime() {
return WiFi.getTime();
}

int position;

void onPositionUpdate() {
Serial.print("New position value: ");
Serial.println(position);
}

void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
int timeout = millis() + TIMEOUT;
while (!Serial && (millis() < timeout)) {}

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Expand All @@ -33,42 +42,108 @@ void setup() {
}

// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
int attempts = 0;
while (status != WL_CONNECTED && attempts < 6) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);

// wait 10 seconds for connection:
delay(10000);
attempts++;
}

if (status != WL_CONNECTED) {
Serial.println("Failed to connect to Wifi!");
while (true);
}

// you're connected now, so print out the data:
Serial.print("You're connected to the network");

Serial.println();
Serial.println("Attempting to connect to Arduino Cloud ...");
Serial.println("Attempting to connect to Arduino Cloud");

ArduinoCloud.onGetTime(getTime);
if (!ArduinoCloud.connect()) {

attempts = 0;
while (!ArduinoCloud.connect() && attempts < 10) {
Serial.print(".");
attempts++;
}

if (attempts >= 10) {
Serial.println("Failed to connect to Arduino Cloud!");
while (1);
}

Serial.println("Successfully connected to Arduino Cloud :)");

ArduinoCloud.addProperty(position, READ, 10*SECONDS, onPositionUpdate);

CloudSerial.begin(9600);
CloudSerial.print("I'm ready for blinking!\n");
}

void loop() {
ArduinoCloud.poll();

// check if there is something waiting to be read
if (CloudSerial.available()) {
Serial.write(CloudSerial.read());
char character = CloudSerial.read();
cloudSerialBuffer += character;

// if a \n character has been received, there should be a complete command inside cloudSerialBuffer
if (character == '\n') {
manageString();
}
}
else // if there is nothing to read, it could be that the last command didn't end with a '\n'. Check.
{
manageString();
}

// Just to be able to simulate the board responses through the serial monitor
if (Serial.available()) {
CloudSerial.write(Serial.read());
}
}

void manageString() {
// Don't proceed if the string is empty
if (cloudSerialBuffer.equals("")) return;

// Remove whitespaces
cloudSerialBuffer.trim();

// Make it uppercase;
cloudSerialBuffer.toUpperCase();

if (cloudSerialBuffer.equals("ON")) {
digitalWrite(6, HIGH);
}
if (cloudSerialBuffer.equals("OFF")) {
digitalWrite(6, LOW);
}

sendString(cloudSerialBuffer);

// Reset cloudSerialBuffer
cloudSerialBuffer = "";
}

// sendString sends a string to the Arduino Cloud.
void sendString(String stringToSend) {
// send the characters one at a time
char lastSentChar = 0;
for (int i = 0; i < stringToSend.length(); i++) {
lastSentChar = stringToSend.charAt(i);
CloudSerial.write(lastSentChar);
}

// if the last sent character wasn't a '\n' add it
if (lastSentChar != '\n') {
CloudSerial.write('\n');
}
}
52 changes: 29 additions & 23 deletions examples/utility/Provisioning/Provisioning.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#include <utility/ECCX08TLSConfig.h>

#include <ArduinoBearSSL.h>
#include <utility/ECCX08.h>
#include <ArduinoECCX08.h>

const int keySlot = 0;
const int compressedCertSlot = 10;
const int serialNumberSlot = 11;
const int thingIdSlot = 12;
const bool DEBUG = true;
const int keySlot = 0;
const int compressedCertSlot = 10;
const int serialNumberAndAuthorityKeyIdentifierSlot = 11;
const int thingIdSlot = 12;

void setup() {
Serial.begin(9600);
Expand Down Expand Up @@ -55,7 +56,8 @@ void setup() {
while (1);
}

ECCX08Cert.setSubjectCommonName(ECCX08.serialNumber());
String thingId = promptAndReadLine("Please enter the thing id: ");
ECCX08Cert.setSubjectCommonName(thingId);

String csr = ECCX08Cert.endCSR();

Expand All @@ -68,37 +70,37 @@ void setup() {
Serial.println();
Serial.println(csr);

String thingId = promptAndReadLine("Please enter the thing id: ");
String issueYear = promptAndReadLine("Please enter the issue year of the certificate (2000 - 2031): ");
String issueMonth = promptAndReadLine("Please enter the issue month of the certificate (1 - 12): ");
String issueDay = promptAndReadLine("Please enter the issue day of the certificate (1 - 31): ");
String issueHour = promptAndReadLine("Please enter the issue hour of the certificate (0 - 23): ");
String expireYears = promptAndReadLine("Please enter how many years the certificate is valid for (0 - 31): ");
String serialNumber = promptAndReadLine("Please enter the certificates serial number: ");
String signature = promptAndReadLine("Please enter the certificates signature: ");

serialNumber.toUpperCase();
signature.toUpperCase();
String issueYear = promptAndReadLine("Please enter the issue year of the certificate (2000 - 2031): ");
String issueMonth = promptAndReadLine("Please enter the issue month of the certificate (1 - 12): ");
String issueDay = promptAndReadLine("Please enter the issue day of the certificate (1 - 31): ");
String issueHour = promptAndReadLine("Please enter the issue hour of the certificate (0 - 23): ");
String expireYears = promptAndReadLine("Please enter how many years the certificate is valid for (0 - 31): ");
String serialNumber = promptAndReadLine("Please enter the certificates serial number: ");
String authorityKeyIdentifier = promptAndReadLine("Please enter the certificates authority key identifier: ");
String signature = promptAndReadLine("Please enter the certificates signature: ");

byte thingIdBytes[72];
byte serialNumberBytes[16];
byte authorityKeyIdentifierBytes[20];
byte signatureBytes[64];

thingId.getBytes(thingIdBytes, sizeof(thingIdBytes));
hexStringToBytes(serialNumber, serialNumberBytes, sizeof(serialNumberBytes));
hexStringToBytes(signature, signatureBytes, 64);
hexStringToBytes(authorityKeyIdentifier, authorityKeyIdentifierBytes, sizeof(authorityKeyIdentifierBytes));
hexStringToBytes(signature, signatureBytes, sizeof(signatureBytes));

if (!ECCX08.writeSlot(thingIdSlot, thingIdBytes, sizeof(thingIdBytes))) {
Serial.println("Error storing thing id!");
while (1);
}

if (!ECCX08Cert.beginStorage(compressedCertSlot, serialNumberSlot)) {
if (!ECCX08Cert.beginStorage(compressedCertSlot, serialNumberAndAuthorityKeyIdentifierSlot)) {
Serial.println("Error starting ECCX08 storage!");
while (1);
}

ECCX08Cert.setSignature(signatureBytes);
ECCX08Cert.setAuthorityKeyIdentifier(authorityKeyIdentifierBytes);
ECCX08Cert.setSerialNumber(serialNumberBytes);
ECCX08Cert.setIssueYear(issueYear.toInt());
ECCX08Cert.setIssueMonth(issueMonth.toInt());
Expand All @@ -111,7 +113,7 @@ void setup() {
while (1);
}

if (!ECCX08Cert.beginReconstruction(keySlot, compressedCertSlot, serialNumberSlot)) {
if (!ECCX08Cert.beginReconstruction(keySlot, compressedCertSlot, serialNumberAndAuthorityKeyIdentifierSlot)) {
Serial.println("Error starting ECCX08 cert reconstruction!");
while (1);
}
Expand All @@ -126,6 +128,10 @@ void setup() {
while (1);
}

if (!DEBUG) {
return;
}

Serial.println("Compressed cert = ");

const byte* certData = ECCX08Cert.bytes();
Expand Down Expand Up @@ -175,8 +181,9 @@ String readLine() {
return line;
}

void hexStringToBytes(const String& in, byte out[], int length) {
void hexStringToBytes(String& in, byte out[], int length) {
int inLength = in.length();
in.toUpperCase();
int outLength = 0;

for (int i = 0; i < inLength && outLength < length; i += 2) {
Expand All @@ -186,7 +193,6 @@ void hexStringToBytes(const String& in, byte out[], int length) {
byte highByte = (highChar <= '9') ? (highChar - '0') : (highChar + 10 - 'A');
byte lowByte = (lowChar <= '9') ? (lowChar - '0') : (lowChar + 10 - 'A');

out[outLength++] = (highByte << 4) | lowByte;
out[outLength++] = (highByte << 4) | (lowByte & 0xF);
}
}

Loading