Skip to content

Commit

Permalink
Merge pull request #156 from arduino-libraries/enable-ota-gsm-all-the…
Browse files Browse the repository at this point in the history
…-time

Automatically configure SSU/OTA logic for MKR GSM 1400
  • Loading branch information
aentinger authored Jul 7, 2020
2 parents a62b28c + 85e7ef7 commit bfc2ff9
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 34 deletions.
62 changes: 55 additions & 7 deletions .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ jobs:

env:
# libraries to install for all boards
UNIVERSAL_LIBRARIES: '"Arduino_ConnectionHandler" "Arduino_DebugUtils" "ArduinoMqttClient"'
UNIVERSAL_LIBRARIES: |
# Install the ArduinoIoTCloud library from the repository
- source-path: ./
- source-url: https://github.com/arduino-libraries/Arduino_ConnectionHandler.git
version: latest
- name: Arduino_DebugUtils
- name: ArduinoMqttClient
# sketch paths to compile (recursive) for all boards
UNIVERSAL_SKETCH_PATHS: '"examples/ArduinoIoTCloud-Advanced" "examples/ArduinoIoTCloud-Basic" "examples/utility/ArduinoIoTCloud_Travis_CI"'

Expand All @@ -33,34 +39,73 @@ jobs:
{"fqbn": "arduino:samd:mkrwan1300", "type": "wan"},
{"fqbn": "arduino:samd:mkrgsm1400", "type": "gsm"},
{"fqbn": "arduino:samd:mkrnb1500", "type": "nb"},
{"fqbn": '"esp8266:esp8266:huzzah" "https://arduino.esp8266.com/stable/package_esp8266com_index.json"', "type": "esp8266"}
{"fqbn": "esp8266:esp8266:huzzah", "type": "esp8266"}
]

# make board type-specific customizations to the matrix jobs
include:
# WiFi boards
- board:
type: "wifi"
libraries: '"ArduinoECCX08" "RTCZero" "WiFi101" "WiFiNINA" "Arduino_MKRMEM"'
platforms: |
# Install Arduino SAMD Boards via Boards Manager for the toolchain
- name: arduino:samd
# Overwrite the Arduino SAMD Boards release version with version from the tip of the master branch
- source-url: https://github.com/arduino/ArduinoCore-samd/archive/master.zip
name: arduino:samd
libraries: |
- name: ArduinoECCX08
- name: RTCZero
- name: WiFi101
- name: WiFiNINA
- name: Arduino_MKRMEM
sketch-paths: '"examples/utility/Provisioning" "examples/utility/WiFi_Cloud_Blink"'
# LoRaWAN boards
- board:
type: "wan"
libraries: '"ArduinoECCX08" "RTCZero" "MKRWAN"'
platforms: |
- name: arduino:samd
- source-url: https://github.com/arduino/ArduinoCore-samd/archive/master.zip
name: arduino:samd
libraries: |
- name: ArduinoECCX08
- name: RTCZero
- name: MKRWAN
sketch-paths:
# GSM boards
- board:
type: "gsm"
libraries: '"ArduinoECCX08" "RTCZero" "MKRGSM" "Arduino_MKRMEM"'
platforms: |
- name: arduino:samd
- source-url: https://github.com/arduino/ArduinoCore-samd/archive/master.zip
name: arduino:samd
libraries: |
- name: ArduinoECCX08
- name: RTCZero
# Use the version of MKRGSM from the tip of its repository's default branch
- source-url: https://github.com/arduino-libraries/MKRGSM.git
- name: Arduino_MKRMEM
sketch-paths: '"examples/utility/Provisioning" "examples/utility/GSM_Cloud_Blink"'
# NB boards
- board:
type: "nb"
libraries: '"ArduinoECCX08" "RTCZero" "MKRNB" "Arduino_MKRMEM"'
platforms: |
- name: arduino:samd
- source-url: https://github.com/arduino/ArduinoCore-samd/archive/master.zip
name: arduino:samd
libraries: |
- name: ArduinoECCX08
- name: RTCZero
- name: MKRNB
- name: Arduino_MKRMEM
sketch-paths: '"examples/utility/Provisioning" "examples/utility/NB_Cloud_Blink"'
# ESP8266 boards
- board:
type: "esp8266"
platforms: |
# Install ESP8266 platform via Boards Manager
- name: esp8266:esp8266
source-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
libraries:
sketch-paths: '"examples/utility/WiFi_Cloud_Blink_with_security_credentials"'

Expand All @@ -71,8 +116,11 @@ jobs:
- name: Compile examples
uses: arduino/actions/libraries/compile-examples@master
with:
platforms: ${{ matrix.platforms }}
fqbn: ${{ matrix.board.fqbn }}
libraries: "${{ env.UNIVERSAL_LIBRARIES }} ${{ matrix.libraries }}"
libraries: |
${{ env.UNIVERSAL_LIBRARIES }}
${{ matrix.libraries }}
sketch-paths: "${{ env.UNIVERSAL_SKETCH_PATHS }} ${{ matrix.sketch-paths }}"
size-report-sketch: 'ArduinoIoTCloud_Travis_CI'
enable-size-deltas-report: 'true'
Expand Down
11 changes: 8 additions & 3 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "tls/utility/CryptoUtil.h"
#endif

#include "utility/ota/OTAStorage_SSU.h"
#include "utility/ota/OTAStorage_MKRMEM.h"

#include "cbor/CBOREncoder.h"
Expand All @@ -39,9 +40,11 @@

TimeService time_service;

#if OTA_STORAGE_MKRMEM
#if OTA_STORAGE_SSU
static OTAStorage_SSU ota_storage_ssu;
#elif OTA_STORAGE_MKRMEM
static OTAStorage_MKRMEM ota_storage_sfu;
#endif /* OTA_STORAGE_MKRMEM */
#endif

/******************************************************************************
GLOBAL CONSTANTS
Expand Down Expand Up @@ -141,7 +144,9 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)

printConnectionStatus(_iot_status);

#if OTA_STORAGE_MKRMEM
#if OTA_STORAGE_SSU
setOTAStorage(ota_storage_ssu);
#elif OTA_STORAGE_MKRMEM
setOTAStorage(ota_storage_sfu);
#endif /* OTA_STORAGE_MKRMEM */

Expand Down
12 changes: 5 additions & 7 deletions src/ArduinoIoTCloud_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@
#define OTA_STORAGE_MKRMEM (0)
#endif

#ifndef OTA_STORAGE_MKRGSM
#define OTA_STORAGE_MKRGSM (0)
#ifdef ARDUINO_SAMD_MKRGSM1400
#define OTA_STORAGE_SSU (1)
#else
#define OTA_STORAGE_SSU (0)
#endif

/******************************************************************************
* AUTOMATIC CONFIGURED DEFINES
******************************************************************************/

#if !defined(ARDUINO_SAMD_MKR1000) && !defined(ARDUINO_SAMD_MKRWIFI1010) && !defined(ARDUINO_SAMD_MKRGSM1400) && !defined(ARDUINO_SAMD_MKRNB1500)
#define OTA_STORAGE_MKRMEM (0)
#endif

#if OTA_STORAGE_MKRMEM || OTA_STORAGE_MKRGSM
#if OTA_STORAGE_MKRMEM || OTA_STORAGE_SSU
#define OTA_ENABLED (1)
#else
#define OTA_ENABLED (0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
******************************************************************************/

#include <ArduinoIoTCloud_Config.h>
#if OTA_STORAGE_MKRGSM
#if OTA_STORAGE_SSU

#include "OTAStorage_MKRGSM.h"
#include "OTAStorage_SSU.h"

/******************************************************************************
CONSTANTS
Expand All @@ -35,7 +35,7 @@ static char const SSU_CHECK_FILE_NAME[] = "UPDATE.OK";
PUBLIC MEMBER FUNCTIONS
******************************************************************************/

bool OTAStorage_MKRGSM::init()
bool OTAStorage_SSU::init()
{
if (!_fileUtils.begin())
return false;
Expand All @@ -49,28 +49,28 @@ bool OTAStorage_MKRGSM::init()
return false;
}

bool OTAStorage_MKRGSM::open(char const * /* file_name */)
bool OTAStorage_SSU::open(char const * /* file_name */)
{
return true;
}

size_t OTAStorage_MKRGSM::write(uint8_t const* const buf, size_t const num_bytes)
size_t OTAStorage_SSU::write(uint8_t const* const buf, size_t const num_bytes)
{
_fileUtils.appendFile(SSU_UPDATE_FILENAME, (const char*)buf, num_bytes);
return num_bytes;
}

void OTAStorage_MKRGSM::close()
void OTAStorage_SSU::close()
{
/* Nothing to do */
}

void OTAStorage_MKRGSM::remove(char const * /* file_name */)
void OTAStorage_SSU::remove(char const * /* file_name */)
{
_fileUtils.deleteFile(SSU_UPDATE_FILENAME);
}

bool OTAStorage_MKRGSM::rename(char const * /* old_file_name */, char const * /* new_file_name */)
bool OTAStorage_SSU::rename(char const * /* old_file_name */, char const * /* new_file_name */)
{
/* Create a file 'UPDATE.OK' which is used by the SSU
* 2nd stage bootloader to recognise that the update
Expand All @@ -82,9 +82,9 @@ bool OTAStorage_MKRGSM::rename(char const * /* old_file_name */, char const * /*
return (_fileUtils.appendFile(SSU_CHECK_FILE_NAME, &c, sizeof(c)) == sizeof(c));
}

void OTAStorage_MKRGSM::deinit()
void OTAStorage_SSU::deinit()
{
/* Nothing to do */
}

#endif /* OTA_STORAGE_MKRGSM */
#endif /* OTA_STORAGE_SSU */
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
a commercial license, send an email to [email protected].
*/

#ifndef ARDUINO_OTA_STORAGE_MKRGSM_H_
#define ARDUINO_OTA_STORAGE_MKRGSM_H_
#ifndef ARDUINO_OTA_STORAGE_SSU_H_
#define ARDUINO_OTA_STORAGE_SSU_H_

/******************************************************************************
* INCLUDE
******************************************************************************/

#include <ArduinoIoTCloud_Config.h>
#if OTA_STORAGE_MKRGSM
#if OTA_STORAGE_SSU

#include <SSU.h>

#include "OTAStorage.h"

Expand All @@ -33,11 +35,11 @@
* CLASS DECLARATION
******************************************************************************/

class OTAStorage_MKRGSM : public OTAStorage
class OTAStorage_SSU : public OTAStorage
{
public:

virtual ~OTAStorage_MKRGSM() { }
virtual ~OTAStorage_SSU() { }


virtual bool init () override;
Expand All @@ -54,6 +56,6 @@ class OTAStorage_MKRGSM : public OTAStorage

};

#endif /* OTA_STORAGE_MKRGSM */
#endif /* OTA_STORAGE_SSU */

#endif /* ARDUINO_OTA_STORAGE_MKRGSM_H_ */
#endif /* ARDUINO_OTA_STORAGE_SSU_H_ */

0 comments on commit bfc2ff9

Please sign in to comment.