Skip to content

Commit

Permalink
Merge pull request #176 from adafruit/add-use-staging-pr
Browse files Browse the repository at this point in the history
Make pull requests also build staging artifacts
  • Loading branch information
brentru authored Nov 5, 2021
2 parents a0076cc + 55d6d89 commit 1bd59c1
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 31 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ jobs:
run: |
mv examples/*/build/*/Wippersnapper_demo.ino.uf2 wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.uf2
mv examples/*/build/*/Wippersnapper_demo.ino.bin wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.bin
mv examples/*/build/*/Wippersnapper_demo_staging.ino.uf2 staging.wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.uf2
mv examples/*/build/*/Wippersnapper_demo_staging.ino.bin staging.wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.bin
- name: upload build artifacts
uses: actions/upload-artifact@v2
with:
name: build-files
path: |
wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.uf2
wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.bin
staging.wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.uf2
staging.wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.bin
build-esp32:
Expand Down Expand Up @@ -101,12 +105,14 @@ jobs:
- name: Rename build artifacts to reflect the platform name
run: |
mv examples/Wippersnapper_demo/build/esp32.esp32.*/Wippersnapper_demo.ino.bin wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.bin
mv examples/Wippersnapper_demo_staging/build/esp32.esp32.*/Wippersnapper_demo_staging.ino.bin staging.wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.bin
- name: upload build artifacts
uses: actions/upload-artifact@v2
with:
name: build-files
path: |
wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.bin
staging.wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.bin
build-samd:
name: Build WipperSnapper SAMD
Expand Down Expand Up @@ -142,13 +148,18 @@ jobs:
run: |
mv examples/*/build/*/Wippersnapper_demo.ino.uf2 wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.uf2
mv examples/*/build/*/Wippersnapper_demo.ino.hex wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.hex
mv examples/*/build/*/Wippersnapper_demo_staging.ino.uf2 staging.wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.uf2
mv examples/*/build/*/Wippersnapper_demo_staging.ino.hex staging.wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.hex
- name: upload build artifacts
uses: actions/upload-artifact@v2
with:
name: build-files
path: |
wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.uf2
wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.hex
staging.wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.uf2
staging.wippersnapper.${{ matrix.arduino-platform }}.${{ env.WS_VERSION }}.hex
clang_and_doxy:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions examples/Wippersnapper_demo_staging/.esp32.generate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions examples/Wippersnapper_demo_staging/.esp8266.test.skip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@



37 changes: 37 additions & 0 deletions examples/Wippersnapper_demo_staging/Wippersnapper_demo_staging.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Adafruit IO WipperSnapper Beta
//
//
// NOTE: This software is a BETA release and in active development.
// Please report bugs or errors to https://github.com/adafruit/Adafruit_Wippersnapper_Arduino/issues
//
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Brent Rubell for Adafruit Industries, 2021
//
// All text above must be included in any redistribution.

#include "Wippersnapper_Networking.h"
Wippersnapper_WiFi wipper;

// Enable debug output for beta builds
#define WS_DEBUG
// Enable staging server
bool useStaging = true;

void setup() {
// Provisioning must occur prior to serial init.
wipper.provision();

Serial.begin(115200);
//while (!Serial) delay(10);

wipper.connect(useStaging);

}

void loop() {
wipper.run();
}
18 changes: 13 additions & 5 deletions src/Wippersnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,12 @@ void Wippersnapper::setUID() {
@brief Sets up the MQTT client session.
@param clientID
A unique client identifier string.
@param useStaging
True to use the Adafruit.io staging broker, False otherwise.
*/
/****************************************************************************/
void Wippersnapper::setupMQTTClient(const char *clientID) {
void Wippersnapper::setupMQTTClient(const char *clientID,
bool useStaging = false) {
WS_DEBUG_PRINTLN("ERROR: Please define a network interface!");
}

Expand Down Expand Up @@ -963,11 +966,13 @@ void Wippersnapper::subscribeErrorTopics() {
/**************************************************************************/
/*!
@brief Generates device-specific Wippersnapper control topics.
@param useStagingBroker
True if using non-production MQTT broker, false otherwise.
@returns True if memory for control topics allocated successfully,
False otherwise.
*/
/**************************************************************************/
bool Wippersnapper::buildWSTopics() {
bool Wippersnapper::buildWSTopics(bool useStagingBroker) {
bool is_success = true;
// Get UID from the network iface
setUID();
Expand All @@ -989,7 +994,7 @@ bool Wippersnapper::buildWSTopics() {
strcat(_device_uid, WS.sUID);

// Create MQTT client object
setupMQTTClient(_device_uid);
setupMQTTClient(_device_uid, useStagingBroker);

// Global registration topic
WS._topic_description =
Expand Down Expand Up @@ -1413,9 +1418,12 @@ void Wippersnapper::publish(const char *topic, uint8_t *payload, uint16_t bLen,
/**************************************************************************/
/*!
@brief Connects to Adafruit IO+ Wippersnapper broker.
@param useStagingBroker
True to use the Adafruit.io staging MQTT broker for debugging
new features, False otherwise.
*/
/**************************************************************************/
void Wippersnapper::connect() {
void Wippersnapper::connect(bool useStagingBroker) {
// enable WDT
enableWDT(WS_WDT_TIMEOUT);

Expand All @@ -1425,7 +1433,7 @@ void Wippersnapper::connect() {
WS._boardStatus = WS_BOARD_DEF_IDLE;

// build MQTT topics for WipperSnapper and subscribe
if (!buildWSTopics()) {
if (!buildWSTopics(useStagingBroker)) {
haltError("Unable to allocate space for MQTT topics");
}
if (!buildErrorTopics()) {
Expand Down
15 changes: 4 additions & 11 deletions src/Wippersnapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@
#include "Adafruit_SleepyDog.h"
#endif

// Uncomment the following use the staging IO server //
//#define USE_STAGING ///< Use Adafruit IO staging
// certificate
#define IO_MQTT_SERVER "io.adafruit.com" ///< Adafruit IO MQTT Server
//(Production)

#ifdef USE_TINYUSB
#include "provisioning/tinyusb/Wippersnapper_FS.h"
#endif
Expand Down Expand Up @@ -199,16 +193,16 @@ class Wippersnapper {

virtual void _connect();
virtual void _disconnect();
void connect();
void connect(bool useStagingBroker = false);
void disconnect();

virtual void setUID();
virtual void setupMQTTClient(const char *clientID);
virtual void setupMQTTClient(const char *clientID, bool useStaging);

virtual ws_status_t networkStatus();
ws_board_status_t getBoardStatus();

bool buildWSTopics();
bool buildWSTopics(bool useStagingBroker);
void subscribeWSTopics();
bool buildErrorTopics();
void subscribeErrorTopics();
Expand Down Expand Up @@ -281,8 +275,7 @@ class Wippersnapper {
Adafruit_MQTT *_mqtt; /*!< Reference to Adafruit_MQTT, _mqtt. */
char *_topic_description; /*!< MQTT topic for the device description */

const char *_mqtt_broker = IO_MQTT_SERVER; /*!< MQTT Broker URL */
uint16_t _mqtt_port = 8883; /*!< MQTT Broker URL */
uint16_t _mqtt_port = 8883; /*!< MQTT Broker URL */

// AIO credentials
const char *_username; /*!< Adafruit IO username */
Expand Down
19 changes: 14 additions & 5 deletions src/network_interfaces/Wippersnapper_AIRLIFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,19 @@ class Wippersnapper_AIRLIFT : public Wippersnapper {
@brief Initializes the MQTT client.
@param clientID
MQTT client identifier
@param useStaging
True to use the Adafruit.io staging broker,
False otherwise.
*/
/********************************************************/
void setupMQTTClient(const char *clientID) {
void setupMQTTClient(const char *clientID, bool useStaging = false) {
if (useStaging == true) {
_mqttBrokerURL = "io.adafruit.us";
} else {
_mqttBrokerURL = "io.adafruit.com";
}
WS._mqtt =
new Adafruit_MQTT_Client(_mqtt_client, WS._mqtt_broker, WS._mqtt_port,
new Adafruit_MQTT_Client(_mqtt_client, _mqttBrokerURL, WS._mqtt_port,
clientID, WS._username, WS._key);
}

Expand Down Expand Up @@ -194,9 +202,10 @@ class Wippersnapper_AIRLIFT : public Wippersnapper {
const char *connectionType() { return "AIRLIFT"; }

protected:
const char *_ssid; /*!< Network SSID. */
const char *_pass; /*!< Network password. */
String _fv; /*!< nina-fw firmware version. */
const char *_ssid; /*!< Network SSID. */
const char *_pass; /*!< Network password. */
const char *_mqttBrokerURL; /*!< MQTT broker URL. */
String _fv; /*!< nina-fw firmware version. */
uint8_t mac[6] = {0x00, 0x00, 0x00,
0x00, 0x00, 0x00}; /*!< ESP32 interface's MAC address. */
int _ssPin = -1; /*!< SPI S.S. pin. */
Expand Down
24 changes: 16 additions & 8 deletions src/network_interfaces/Wippersnapper_ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,22 @@ class Wippersnapper_ESP32 : public Wippersnapper {
@brief Initializes the MQTT client.
@param clientID
MQTT client identifier
@param useStaging
True to use the Adafruit.io staging broker,
False otherwise.
*/
/********************************************************/
void setupMQTTClient(const char *clientID) {
void setupMQTTClient(const char *clientID, bool useStaging = false) {
if (useStaging == true) {
_mqttBrokerURL = "io.adafruit.us";
_mqtt_client->setCACert(_aio_root_ca_staging);
} else {
_mqttBrokerURL = "io.adafruit.com";
_mqtt_client->setCACert(_aio_root_ca_prod);
}
WS._mqtt =
new Adafruit_MQTT_Client(_mqtt_client, WS._mqtt_broker, WS._mqtt_port,
new Adafruit_MQTT_Client(_mqtt_client, _mqttBrokerURL, WS._mqtt_port,
clientID, WS._username, WS._key);
_mqtt_client->setCACert(_aio_root_ca);
}

/********************************************************/
Expand Down Expand Up @@ -136,12 +145,12 @@ class Wippersnapper_ESP32 : public Wippersnapper {
protected:
const char *_ssid;
const char *_pass;
const char *_mqttBrokerURL;
uint8_t mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
WiFiClientSecure *_mqtt_client;

#ifdef USE_STAGING
// io.adafruit.us
const char *_aio_root_ca =
const char *_aio_root_ca_staging =
"-----BEGIN CERTIFICATE-----\n"
"MIIEZTCCA02gAwIBAgIQQAF1BIMUpMghjISpDBbN3zANBgkqhkiG9w0BAQsFADA/\n"
"MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n"
Expand All @@ -168,9 +177,9 @@ class Wippersnapper_ESP32 : public Wippersnapper {
"O5b85o3AM/OJ+CktFBQtfvBhcJVd9wvlwPsk+uyOy2HI7mNxKKgsBTt375teA2Tw\n"
"UdHkhVNcsAKX1H7GNNLOEADksd86wuoXvg==\n"
"-----END CERTIFICATE-----\n";
#else

// io.adafruit.com
const char *_aio_root_ca =
const char *_aio_root_ca_prod =
"-----BEGIN CERTIFICATE-----\n"
"MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n"
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n"
Expand All @@ -193,7 +202,6 @@ class Wippersnapper_ESP32 : public Wippersnapper {
"YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n"
"CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n"
"-----END CERTIFICATE-----\n";
#endif

/**************************************************************************/
/*!
Expand Down
13 changes: 11 additions & 2 deletions src/network_interfaces/Wippersnapper_ESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,19 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
@brief Sets up an Adafruit_MQTT_Client
@param clientID
MQTT client identifier
@param useStaging
True to use the Adafruit.io staging broker,
False otherwise.
*/
/*******************************************************************/
void setupMQTTClient(const char *clientID) {
void setupMQTTClient(const char *clientID, bool useStaging = false) {
if (useStaging == true) {
_mqttBrokerURL = "io.adafruit.us";
} else {
_mqttBrokerURL = "io.adafruit.com";
}
WS._mqtt =
new Adafruit_MQTT_Client(_mqtt_client, WS._mqtt_broker, WS._mqtt_port,
new Adafruit_MQTT_Client(_mqtt_client, _mqttBrokerURL, WS._mqtt_port,
clientID, WS._username, WS._key);
}

Expand Down Expand Up @@ -142,6 +150,7 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
protected:
const char *_ssid;
const char *_pass;
const char *_mqttBrokerURL;
uint8_t mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
WiFiClientSecure *_mqtt_client;

Expand Down

0 comments on commit 1bd59c1

Please sign in to comment.