From c56b9a81ae5277d217df0215f0810b1582d2941b Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 16 Feb 2018 17:37:28 +0100 Subject: [PATCH 01/11] Integrate ArduinoCloudThing I really dislike that I had to expose the Thing object but otherwise the addProperty() call would become terrible. I added a line on Cloud_blink example to show the composition of functions on properties. It can be safely removed in the next iteration. --- .../MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino | 9 +++++++++ src/ArduinoCloud.cpp | 16 ++++++++++++++++ src/ArduinoCloudV2.h | 5 +++++ 3 files changed, 30 insertions(+) diff --git a/examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino b/examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino index 5724c4d30..3700f52c4 100644 --- a/examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino +++ b/examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino @@ -15,6 +15,13 @@ 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); @@ -59,6 +66,8 @@ void setup() { Serial.println("Successfully connected to Arduino Cloud :)"); + ArduinoCloud.Thing.addProperty(position, READ).publishEvery(10*SECONDS).onUpdate(onPositionUpdate); + CloudSerial.begin(9600); } diff --git a/src/ArduinoCloud.cpp b/src/ArduinoCloud.cpp index fd3bbbaf5..86125fcfc 100644 --- a/src/ArduinoCloud.cpp +++ b/src/ArduinoCloud.cpp @@ -55,8 +55,11 @@ int ArduinoCloudClass::begin(Client& net, const String& id) _id = id; + Thing.begin(); + _stdoutTopic = "$aws/things/" + _id + "/stdout"; _stdinTopic = "$aws/things/" + _id + "/stdin"; + _dataTopic = "$aws/things/" + _id + "/data"; return 1; } @@ -75,6 +78,11 @@ int ArduinoCloudClass::connect() void ArduinoCloudClass::poll() { _mqttClient.loop(); + uint8_t data[1024]; + int length = Thing.poll(data); + if (length) { + writeProperties(data, length); + } } void ArduinoCloudClass::onGetTime(unsigned long(*callback)(void)) @@ -87,6 +95,11 @@ int ArduinoCloudClass::connected() return _mqttClient.connected(); } +int ArduinoCloudClass::writeProperties(const byte data[], int length) +{ + return _mqttClient.publish(_dataTopic.c_str(), (const char*)data, length); +} + int ArduinoCloudClass::writeStdout(const byte data[], int length) { return _mqttClient.publish(_stdoutTopic.c_str(), (const char*)data, length); @@ -102,6 +115,9 @@ void ArduinoCloudClass::handleMessage(char topic[], char bytes[], int length) if (_stdinTopic == topic) { CloudSerial.appendStdin((uint8_t*)bytes, length); } + if (_dataTopic == topic) { + Thing.decode((uint8_t*)bytes, length); + } } ArduinoCloudClass ArduinoCloud; diff --git a/src/ArduinoCloudV2.h b/src/ArduinoCloudV2.h index 4c8f59157..a7d8808d8 100644 --- a/src/ArduinoCloudV2.h +++ b/src/ArduinoCloudV2.h @@ -3,6 +3,7 @@ #include #include +#include #include "CloudSerial.h" @@ -22,9 +23,12 @@ class ArduinoCloudClass { int connected(); + ArduinoCloudThing Thing; + protected: friend class CloudSerialClass; int writeStdout(const byte data[], int length); + int writeProperties(const byte data[], int length); private: static void onMessage(MQTTClient *client, char topic[], char bytes[], int length); @@ -38,6 +42,7 @@ class ArduinoCloudClass { String _stdinTopic; String _stdoutTopic; + String _dataTopic; }; From 9aae39a4334b67c348d697fd52835445ff960c23 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 22 Feb 2018 16:03:55 +0100 Subject: [PATCH 02/11] Fix .readOnly/.writeOnly compisition --- examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino | 2 +- src/ArduinoCloud.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino b/examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino index 3700f52c4..731c14866 100644 --- a/examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino +++ b/examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino @@ -66,7 +66,7 @@ void setup() { Serial.println("Successfully connected to Arduino Cloud :)"); - ArduinoCloud.Thing.addProperty(position, READ).publishEvery(10*SECONDS).onUpdate(onPositionUpdate); + ArduinoCloud.Thing.addProperty(position).publishEvery(10*SECONDS).onUpdate(onPositionUpdate).readOnly(); CloudSerial.begin(9600); } diff --git a/src/ArduinoCloud.cpp b/src/ArduinoCloud.cpp index 86125fcfc..4da16ae59 100644 --- a/src/ArduinoCloud.cpp +++ b/src/ArduinoCloud.cpp @@ -71,6 +71,7 @@ int ArduinoCloudClass::connect() } _mqttClient.subscribe(_stdinTopic); + _mqttClient.subscribe(_dataTopic); return 1; } From 6391cc6daaefe7f62931a0c1adfcf51b0c1dbe0d Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 30 May 2018 15:51:40 +0200 Subject: [PATCH 03/11] Add addProperty API with complete signature --- examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino | 2 +- src/ArduinoCloudV2.h | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino b/examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino index 731c14866..f57e64862 100644 --- a/examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino +++ b/examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino @@ -66,7 +66,7 @@ void setup() { Serial.println("Successfully connected to Arduino Cloud :)"); - ArduinoCloud.Thing.addProperty(position).publishEvery(10*SECONDS).onUpdate(onPositionUpdate).readOnly(); + ArduinoCloud.addProperty(position, READ, 10*SECONDS, onPositionUpdate); CloudSerial.begin(9600); } diff --git a/src/ArduinoCloudV2.h b/src/ArduinoCloudV2.h index a7d8808d8..75ae03d2c 100644 --- a/src/ArduinoCloudV2.h +++ b/src/ArduinoCloudV2.h @@ -23,7 +23,12 @@ class ArduinoCloudClass { int connected(); - ArduinoCloudThing Thing; + #define addPropertyMacro(prop) addPropertyReal(prop, #prop) + #undef addProperty + + template void addProperty(T property, permissionType _permission = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL) { + Thing.addPropertyMacro(property).publishEvery(seconds).setPermission(_permission).onUpdate(fn); + } protected: friend class CloudSerialClass; @@ -37,6 +42,7 @@ class ArduinoCloudClass { private: String _id; + ArduinoCloudThing Thing; BearSSLClient* _bearSslClient; MQTTClient _mqttClient; From 2406990bbd4bf87e3555a6f2f04cf72abb66471c Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 30 May 2018 15:51:53 +0200 Subject: [PATCH 04/11] Initial testing on OTA --- src/ArduinoCloud.cpp | 26 ++++++++++++++++++++++++++ src/ArduinoCloudV2.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/src/ArduinoCloud.cpp b/src/ArduinoCloud.cpp index 4da16ae59..07f4adb1d 100644 --- a/src/ArduinoCloud.cpp +++ b/src/ArduinoCloud.cpp @@ -4,6 +4,8 @@ #include #include "CloudSerial.h" +#include "SerialFlashStorage.h" +//#include "SFU.h" const static char server[] = "a19g5nbe27wn47.iot.eu-west-1.amazonaws.com"; //"xxxxxxxxxxxxxx.iot.xx-xxxx-x.amazonaws.com"; @@ -13,6 +15,7 @@ const static int serialNumberSlot = 11; ArduinoCloudClass::ArduinoCloudClass() : _bearSslClient(NULL), + _otaClient(NULL), _mqttClient(256) { } @@ -22,6 +25,9 @@ ArduinoCloudClass::~ArduinoCloudClass() if (_bearSslClient) { delete _bearSslClient; } + if (_otaClient) { + delete _otaClient; + } } int ArduinoCloudClass::begin(Client& net, const String& id) @@ -57,9 +63,12 @@ int ArduinoCloudClass::begin(Client& net, const String& id) Thing.begin(); + _otaClient = new HttpClient(net, server, 80); + _stdoutTopic = "$aws/things/" + _id + "/stdout"; _stdinTopic = "$aws/things/" + _id + "/stdin"; _dataTopic = "$aws/things/" + _id + "/data"; + _otaTopic = "$aws/things/" + _id + "/upload"; return 1; } @@ -72,6 +81,7 @@ int ArduinoCloudClass::connect() _mqttClient.subscribe(_stdinTopic); _mqttClient.subscribe(_dataTopic); + _mqttClient.subscribe(_otaTopic); return 1; } @@ -119,6 +129,22 @@ void ArduinoCloudClass::handleMessage(char topic[], char bytes[], int length) if (_dataTopic == topic) { Thing.decode((uint8_t*)bytes, length); } + if (_otaTopic == topic) { + + String url = String(bytes); + + _otaClient->get(url); + + SerialFlashStorage.open(_otaClient->contentLength()); + uint8_t buf[1024]; + while (_otaClient->available()) { + int size = _otaClient->available() >= 1024 ? 1024 : _otaClient->available(); + _otaClient->read(buf, size); + SerialFlashStorage.write((uint8_t*)buf, size); + } + SerialFlashStorage.close(); + SerialFlashStorage.apply(); + } } ArduinoCloudClass ArduinoCloud; diff --git a/src/ArduinoCloudV2.h b/src/ArduinoCloudV2.h index 75ae03d2c..b29114bbc 100644 --- a/src/ArduinoCloudV2.h +++ b/src/ArduinoCloudV2.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "CloudSerial.h" @@ -45,10 +46,12 @@ class ArduinoCloudClass { ArduinoCloudThing Thing; BearSSLClient* _bearSslClient; MQTTClient _mqttClient; + HttpClient* _otaClient; String _stdinTopic; String _stdoutTopic; String _dataTopic; + String _otaTopic; }; From 543c75b5c15a69c2cbdba8336dd81bf65a06fb61 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 30 May 2018 18:36:54 +0200 Subject: [PATCH 05/11] Port to fixed ArduinoCloudThing --- src/ArduinoCloud.cpp | 2 -- src/ArduinoCloudV2.h | 7 ++----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/ArduinoCloud.cpp b/src/ArduinoCloud.cpp index 2e90323aa..b379b0bb1 100644 --- a/src/ArduinoCloud.cpp +++ b/src/ArduinoCloud.cpp @@ -67,8 +67,6 @@ int ArduinoCloudClass::begin(Client& net) _mqttClient.onMessageAdvanced(ArduinoCloudClass::onMessage); _mqttClient.begin(server, 8883, *_bearSslClient); - _id = id; - Thing.begin(); _otaClient = new HttpClient(net, server, 80); diff --git a/src/ArduinoCloudV2.h b/src/ArduinoCloudV2.h index 6f7517a49..65f166df4 100644 --- a/src/ArduinoCloudV2.h +++ b/src/ArduinoCloudV2.h @@ -24,11 +24,8 @@ class ArduinoCloudClass { int connected(); - #define addPropertyMacro(prop) addPropertyReal(prop, #prop) - #undef addProperty - template void addProperty(T property, permissionType _permission = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL) { - Thing.addPropertyMacro(property).publishEvery(seconds).setPermission(_permission).onUpdate(fn); + Thing.addProperty(property).publishEvery(seconds).setPermission(_permission).onUpdate(fn); } protected: @@ -45,8 +42,8 @@ class ArduinoCloudClass { String _id; ArduinoCloudThing Thing; BearSSLClient* _bearSslClient; - MQTTClient _mqttClient; HttpClient* _otaClient; + MQTTClient _mqttClient; String _stdinTopic; String _stdoutTopic; From ba5faf40ad8c66aa9c58fef8f8d2f0d48afe19aa Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 7 Jun 2018 18:37:22 +0200 Subject: [PATCH 06/11] Add missing libraries --- src/ArduinoCloud.cpp | 2 +- src/OTAStorage.h | 35 +++++++++++++++++++ src/SerialFlashStorage.cpp | 69 ++++++++++++++++++++++++++++++++++++++ src/SerialFlashStorage.h | 43 ++++++++++++++++++++++++ 4 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 src/OTAStorage.h create mode 100644 src/SerialFlashStorage.cpp create mode 100644 src/SerialFlashStorage.h diff --git a/src/ArduinoCloud.cpp b/src/ArduinoCloud.cpp index b379b0bb1..c01f9344b 100644 --- a/src/ArduinoCloud.cpp +++ b/src/ArduinoCloud.cpp @@ -5,7 +5,7 @@ #include "CloudSerial.h" #include "SerialFlashStorage.h" -//#include "SFU.h" +#include "SFU.h" const static char server[] = "a19g5nbe27wn47.iot.us-east-1.amazonaws.com"; //"xxxxxxxxxxxxxx.iot.xx-xxxx-x.amazonaws.com"; diff --git a/src/OTAStorage.h b/src/OTAStorage.h new file mode 100644 index 000000000..0f96e2b3f --- /dev/null +++ b/src/OTAStorage.h @@ -0,0 +1,35 @@ +/* + Copyright (c) 2017 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _OTA_STORAGE_H_INCLUDED +#define _OTA_STORAGE_H_INCLUDED + +class OTAStorage { +public: + virtual int open(int length) = 0; + virtual size_t write(uint8_t* data, size_t size) = 0; + virtual void close() = 0; + virtual void clear() = 0; + virtual void apply() = 0; + + virtual long maxSize() { + return ((256 * 1024) - 0x2000); + } +}; + +#endif diff --git a/src/SerialFlashStorage.cpp b/src/SerialFlashStorage.cpp new file mode 100644 index 000000000..432b7c7b6 --- /dev/null +++ b/src/SerialFlashStorage.cpp @@ -0,0 +1,69 @@ +/* + Copyright (c) 2017 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "SerialFlashStorage.h" + +#define UPDATE_FILE "UPDATE.BIN" + +int SerialFlashStorageClass::open(int contentLength) +{ + if (!SerialFlash.begin(SERIAL_FLASH_CS)) { + return 0; + } + + while (!SerialFlash.ready()) {} + + if (SerialFlash.exists(UPDATE_FILE)) { + SerialFlash.remove(UPDATE_FILE); + } + + if (SerialFlash.create(UPDATE_FILE, contentLength)) { + _file = SerialFlash.open(UPDATE_FILE); + } + + if (!_file) { + return 0; + } + + return 1; +} + +size_t SerialFlashStorageClass::write(uint8_t *data, size_t size) +{ + while (!SerialFlash.ready()) {} + int ret = _file.write(data, size); + return ret; +} + +void SerialFlashStorageClass::close() +{ + _file.close(); +} + +void SerialFlashStorageClass::clear() +{ + SerialFlash.remove(UPDATE_FILE); +} + +void SerialFlashStorageClass::apply() +{ + // just reset, SDU copies the data to flash + NVIC_SystemReset(); +} + +SerialFlashStorageClass SerialFlashStorage; diff --git a/src/SerialFlashStorage.h b/src/SerialFlashStorage.h new file mode 100644 index 000000000..4409969f5 --- /dev/null +++ b/src/SerialFlashStorage.h @@ -0,0 +1,43 @@ +/* + Copyright (c) 2017 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _SERIALFLASH_STORAGE_H_INCLUDED +#define _SERIALFLASH_STORAGE_H_INCLUDED + +#include + +#include "OTAStorage.h" + +#define SERIAL_FLASH_BUFFER_SIZE 64 +#define SERIAL_FLASH_CS 5 + +class SerialFlashStorageClass : public OTAStorage { +public: + virtual int open(int length); + virtual size_t write(uint8_t* data, size_t size); + virtual void close(); + virtual void clear(); + virtual void apply(); + +private: + SerialFlashFile _file; +}; + +extern SerialFlashStorageClass SerialFlashStorage; + +#endif From 659608d897d25547605ec17075e12d275134f5f9 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 27 Jun 2018 23:56:39 +0200 Subject: [PATCH 07/11] Fix addProperty macro, again --- src/ArduinoCloudV2.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ArduinoCloudV2.h b/src/ArduinoCloudV2.h index 65f166df4..03c8d99be 100644 --- a/src/ArduinoCloudV2.h +++ b/src/ArduinoCloudV2.h @@ -24,8 +24,10 @@ class ArduinoCloudClass { int connected(); - template void addProperty(T property, permissionType _permission = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL) { - Thing.addProperty(property).publishEvery(seconds).setPermission(_permission).onUpdate(fn); + #define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__) + + template void addPropertyReal(T property, String name, permissionType _permission = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL) { + Thing.addPropertyReal(property, name).publishEvery(seconds).setPermission(_permission).onUpdate(fn); } protected: From 52e179d2b4dfbf1bfac0c83f1cdfa76a62e49e46 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 28 Jun 2018 00:46:15 +0200 Subject: [PATCH 08/11] Fix reference as value in addProperty signature --- src/ArduinoCloud.cpp | 4 ++-- src/ArduinoCloudV2.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ArduinoCloud.cpp b/src/ArduinoCloud.cpp index c01f9344b..f45cf9ade 100644 --- a/src/ArduinoCloud.cpp +++ b/src/ArduinoCloud.cpp @@ -97,8 +97,8 @@ void ArduinoCloudClass::poll() _mqttClient.loop(); uint8_t data[1024]; int length = Thing.poll(data); - if (length) { - writeProperties(data, length); + if (length > 0) { + writeProperties(data, length); } } diff --git a/src/ArduinoCloudV2.h b/src/ArduinoCloudV2.h index 03c8d99be..4f08a6cec 100644 --- a/src/ArduinoCloudV2.h +++ b/src/ArduinoCloudV2.h @@ -26,7 +26,7 @@ class ArduinoCloudClass { #define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__) - template void addPropertyReal(T property, String name, permissionType _permission = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL) { + template void addPropertyReal(T& property, String name, permissionType _permission = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL) { Thing.addPropertyReal(property, name).publishEvery(seconds).setPermission(_permission).onUpdate(fn); } From 31d9eea5e6290a611f4c6d2de112f6a48f5838c6 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 28 Jun 2018 00:59:01 +0200 Subject: [PATCH 09/11] Call THing.poll with the new API --- src/ArduinoCloud.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArduinoCloud.cpp b/src/ArduinoCloud.cpp index f45cf9ade..2076d44db 100644 --- a/src/ArduinoCloud.cpp +++ b/src/ArduinoCloud.cpp @@ -96,7 +96,7 @@ void ArduinoCloudClass::poll() { _mqttClient.loop(); uint8_t data[1024]; - int length = Thing.poll(data); + int length = Thing.poll(data, sizeof(data)); if (length > 0) { writeProperties(data, length); } From 7a75314a6b0731681b18440121cd8d27ed05b306 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 3 Jul 2018 11:55:58 +0200 Subject: [PATCH 10/11] TEMP: remove OTA stuff --- src/ArduinoCloud.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/ArduinoCloud.cpp b/src/ArduinoCloud.cpp index 2076d44db..9a0b598d2 100644 --- a/src/ArduinoCloud.cpp +++ b/src/ArduinoCloud.cpp @@ -4,8 +4,6 @@ #include #include "CloudSerial.h" -#include "SerialFlashStorage.h" -#include "SFU.h" const static char server[] = "a19g5nbe27wn47.iot.us-east-1.amazonaws.com"; //"xxxxxxxxxxxxxx.iot.xx-xxxx-x.amazonaws.com"; @@ -16,7 +14,6 @@ const static int thingIdSlot = 12; ArduinoCloudClass::ArduinoCloudClass() : _bearSslClient(NULL), - _otaClient(NULL), _mqttClient(256) { } @@ -26,9 +23,6 @@ ArduinoCloudClass::~ArduinoCloudClass() if (_bearSslClient) { delete _bearSslClient; } - if (_otaClient) { - delete _otaClient; - } } int ArduinoCloudClass::begin(Client& net) @@ -69,12 +63,9 @@ int ArduinoCloudClass::begin(Client& net) Thing.begin(); - _otaClient = new HttpClient(net, server, 80); - _stdoutTopic = "$aws/things/" + _id + "/stdout"; _stdinTopic = "$aws/things/" + _id + "/stdin"; _dataTopic = "$aws/things/" + _id + "/data"; - _otaTopic = "$aws/things/" + _id + "/upload"; return 1; } @@ -87,7 +78,6 @@ int ArduinoCloudClass::connect() _mqttClient.subscribe(_stdinTopic); _mqttClient.subscribe(_dataTopic); - _mqttClient.subscribe(_otaTopic); return 1; } @@ -135,22 +125,6 @@ void ArduinoCloudClass::handleMessage(char topic[], char bytes[], int length) if (_dataTopic == topic) { Thing.decode((uint8_t*)bytes, length); } - if (_otaTopic == topic) { - - String url = String(bytes); - - _otaClient->get(url); - - SerialFlashStorage.open(_otaClient->contentLength()); - uint8_t buf[1024]; - while (_otaClient->available()) { - int size = _otaClient->available() >= 1024 ? 1024 : _otaClient->available(); - _otaClient->read(buf, size); - SerialFlashStorage.write((uint8_t*)buf, size); - } - SerialFlashStorage.close(); - SerialFlashStorage.apply(); - } } ArduinoCloudClass ArduinoCloud; From 11fe6138400df991c9b9dfd43aee09b09fc316d2 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 3 Jul 2018 11:56:29 +0200 Subject: [PATCH 11/11] Add minDelta API and a bunch of overloaded not clashing calls --- src/ArduinoCloudV2.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ArduinoCloudV2.h b/src/ArduinoCloudV2.h index 4f08a6cec..5f1f71479 100644 --- a/src/ArduinoCloudV2.h +++ b/src/ArduinoCloudV2.h @@ -26,8 +26,16 @@ class ArduinoCloudClass { #define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__) - template void addPropertyReal(T& property, String name, permissionType _permission = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL) { - Thing.addPropertyReal(property, name).publishEvery(seconds).setPermission(_permission).onUpdate(fn); + template void addPropertyReal(T& property, String name, permissionType _permission = READWRITE, long seconds = ON_CHANGE, T minDelta = 0, void(*fn)(void) = NULL) { + Thing.addPropertyReal(property, name).publishEvery(seconds).setPermission(_permission).onUpdate(fn).minimumDelta(&minDelta); + } + + template void addPropertyReal(T& property, String name, permissionType _permission = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, T minDelta = 0) { + Thing.addPropertyReal(property, name).publishEvery(seconds).setPermission(_permission).onUpdate(fn).minimumDelta(&minDelta); + } + + template void addPropertyReal(T& property, String name, permissionType _permission = READWRITE, void(*fn)(void) = NULL, long seconds = ON_CHANGE, T minDelta = 0) { + Thing.addPropertyReal(property, name).publishEvery(seconds).setPermission(_permission).onUpdate(fn).minimumDelta(&minDelta); } protected: