diff --git a/src/Wippersnapper.cpp b/src/Wippersnapper.cpp index d7fd93292..18215bc29 100644 --- a/src/Wippersnapper.cpp +++ b/src/Wippersnapper.cpp @@ -733,41 +733,41 @@ bool Wippersnapper::buildWSTopics() { // Global registration topic WS._topic_description = (char *)malloc(sizeof(char) * strlen(WS._username) + strlen("/wprsnpr") + - strlen(TOPIC_DESCRIPTION) + strlen("status") + 1); + strlen(TOPIC_INFO) + strlen("status") + 1); // Registration status topic - WS._topic_description_status = (char *)malloc( - sizeof(char) * strlen(WS._username) + +strlen("/wprsnpr/") + - strlen(_device_uid) + strlen(TOPIC_DESCRIPTION) + strlen("status") + - strlen("broker") + 1); + WS._topic_description_status = + (char *)malloc(sizeof(char) * strlen(WS._username) + strlen("/wprsnpr/") + + strlen(_device_uid) + strlen(TOPIC_INFO) + + strlen("status/") + strlen("broker") + 1); // Registration status completion topic - WS._topic_description_status_complete = (char *)malloc( - sizeof(char) * strlen(WS._username) + +strlen("/wprsnpr/") + - strlen(_device_uid) + strlen(TOPIC_DESCRIPTION) + strlen("status") + - strlen("/device/complete") + 1); + WS._topic_description_status_complete = + (char *)malloc(sizeof(char) * strlen(WS._username) + strlen("/wprsnpr/") + + strlen(_device_uid) + strlen(TOPIC_INFO) + + strlen("status") + strlen("/device/complete") + 1); // Topic to signal pin configuration complete from device to broker - WS._topic_device_pin_config_complete = (char *)malloc( - sizeof(char) * strlen(WS._username) + +strlen("/") + strlen(_device_uid) + - strlen("/wprsnpr/") + strlen(TOPIC_SIGNALS) + - strlen("device/pinConfigComplete") + 1); + WS._topic_device_pin_config_complete = + (char *)malloc(sizeof(char) * strlen(WS._username) + strlen("/wprsnpr/") + + strlen(_device_uid) + strlen(TOPIC_SIGNALS) + + strlen("device/pinConfigComplete") + 1); // Topic for signals from device to broker WS._topic_signal_device = (char *)malloc( - sizeof(char) * strlen(WS._username) + +strlen("/") + strlen(_device_uid) + - strlen("/wprsnpr/") + strlen(TOPIC_SIGNALS) + strlen("device") + 1); + sizeof(char) * strlen(WS._username) + strlen("/wprsnpr/") + + strlen(_device_uid) + strlen(TOPIC_SIGNALS) + strlen("device") + 1); // Topic for signals from broker to device WS._topic_signal_brkr = (char *)malloc( - sizeof(char) * strlen(WS._username) + +strlen("/") + strlen(_device_uid) + - strlen("/wprsnpr/") + strlen(TOPIC_SIGNALS) + strlen("broker") + 1); + sizeof(char) * strlen(WS._username) + strlen("/wprsnpr/") + + strlen(_device_uid) + strlen(TOPIC_SIGNALS) + strlen("broker") + 1); // Create global registration topic if (WS._topic_description) { strcpy(WS._topic_description, WS._username); strcat(WS._topic_description, "/wprsnpr"); - strcat(WS._topic_description, TOPIC_DESCRIPTION); + strcat(WS._topic_description, TOPIC_INFO); strcat(WS._topic_description, "status"); } else { // malloc failed WS._topic_description = 0; @@ -779,7 +779,7 @@ bool Wippersnapper::buildWSTopics() { strcpy(WS._topic_description_status, WS._username); strcat(WS._topic_description_status, "/wprsnpr/"); strcat(WS._topic_description_status, _device_uid); - strcat(WS._topic_description_status, TOPIC_DESCRIPTION); + strcat(WS._topic_description_status, TOPIC_INFO); strcat(WS._topic_description_status, "status"); strcat(WS._topic_description_status, "/broker"); } else { // malloc failed @@ -792,7 +792,7 @@ bool Wippersnapper::buildWSTopics() { strcpy(WS._topic_description_status_complete, WS._username); strcat(WS._topic_description_status_complete, "/wprsnpr/"); strcat(WS._topic_description_status_complete, _device_uid); - strcat(WS._topic_description_status_complete, TOPIC_DESCRIPTION); + strcat(WS._topic_description_status_complete, TOPIC_INFO); strcat(WS._topic_description_status_complete, "status"); strcat(WS._topic_description_status_complete, "/device/complete"); } else { // malloc failed @@ -941,7 +941,6 @@ void Wippersnapper::haltError(String error) { */ /**************************************************************************/ bool Wippersnapper::registerBoard() { - bool is_success = false; WS_DEBUG_PRINTLN("Registering hardware with IO..."); // Encode and publish registration request message to broker @@ -1065,18 +1064,20 @@ void Wippersnapper::connect() { // enable WDT enableWDT(WS_WDT_TIMEOUT); + // TODO! // not sure we need to track these... _status = WS_IDLE; WS._boardStatus = WS_BOARD_DEF_IDLE; - // build MQTT topics for WipperSnapper app, and subscribe + // build MQTT topics for WipperSnapper and subscribe if (!buildWSTopics()) { haltError("Unable to allocate space for MQTT topics"); } - subscribeWSTopics(); if (!buildErrorTopics()) { haltError("Unable to allocate space for MQTT error topics"); } + WS_DEBUG_PRINTLN("Subscribing to MQTT topics..."); + subscribeWSTopics(); subscribeErrorTopics(); // Run the network fsm @@ -1096,7 +1097,8 @@ void Wippersnapper::connect() { // Configure hardware WS.pinCfgCompleted = false; while (!WS.pinCfgCompleted) { - WS_DEBUG_PRINTLN("Polling for message containing hardware configuration..."); + WS_DEBUG_PRINTLN( + "Polling for message containing hardware configuration..."); WS._mqtt->processPackets(10); // poll } // Publish that we have completed the configuration workflow diff --git a/src/Wippersnapper.h b/src/Wippersnapper.h index 31af45586..99e50e323 100644 --- a/src/Wippersnapper.h +++ b/src/Wippersnapper.h @@ -64,16 +64,16 @@ #endif #define WS_VERSION \ - "1.0.0-beta.10" ///< WipperSnapper app. version (semver-formatted) + "1.0.0-beta.11" ///< WipperSnapper app. version (semver-formatted) // Reserved Adafruit IO MQTT topics #define TOPIC_IO_THROTTLE "/throttle" ///< Adafruit IO Throttle MQTT Topic #define TOPIC_IO_ERRORS "/errors" ///< Adafruit IO Error MQTT Topic // Reserved Wippersnapper topics -#define TOPIC_WS "/wprsnpr/" ///< Global /wprsnpr/ topic -#define TOPIC_DESCRIPTION "/info/" ///< Device description topic -#define TOPIC_SIGNALS "/signals/" ///< Device signals topic +#define TOPIC_WS "/wprsnpr/" ///< Global /wprsnpr/ topic +#define TOPIC_INFO "/info/" ///< Device description topic +#define TOPIC_SIGNALS "/signals/" ///< Device signals topic #define WS_DEBUG ///< Define to enable debugging to serial terminal #define WS_PRINTER Serial ///< Where debug messages will be printed @@ -154,7 +154,7 @@ typedef enum { 4000 ///< Session keepalive interval time, in milliseconds #define WS_MQTT_MAX_PAYLOAD_SIZE \ - 300 ///< MAXIMUM expected payload size, in bytes + 512 ///< MAXIMUM expected payload size, in bytes class Wippersnapper_DigitalGPIO; class Wippersnapper_AnalogIO; @@ -259,7 +259,7 @@ class Wippersnapper { Wippersnapper_ESP32_nvs *_nvs; ///< Instance of nvs uint8_t _uid[6]; /*!< Unique network iface identifier */ - char sUID[10]; /*!< Unique network iface identifier */ + char sUID[13]; /*!< Unique network iface identifier */ const char *_boardId; /*!< Adafruit IO+ board string */ Adafruit_MQTT *_mqtt; /*!< Reference to Adafruit_MQTT, _mqtt. */ char *_topic_description; /*!< MQTT topic for the device description */ diff --git a/src/components/register/Wippersnapper_Register.cpp b/src/components/register/Wippersnapper_Register.cpp index a9b923faf..d56fc9858 100644 --- a/src/components/register/Wippersnapper_Register.cpp +++ b/src/components/register/Wippersnapper_Register.cpp @@ -42,7 +42,7 @@ bool Wippersnapper::encodePubRegistrationReq() { strcpy(_message.str_version, WS_VERSION); // encode registration request message - uint8_t _message_buffer[128]; + uint8_t _message_buffer[256]; pb_ostream_t _msg_stream = pb_ostream_from_buffer(_message_buffer, sizeof(_message_buffer)); @@ -80,8 +80,7 @@ void Wippersnapper::pollRegistrationResp() { while (WS._boardStatus != WS_BOARD_DEF_OK) { WS_DEBUG_PRINT("Polling for registration message response..."); WS_DEBUG_PRINTLN(WS._boardStatus); - WS._mqtt->processPackets(10); // poll - // WS._mqtt->ping(); // keepalive + WS._mqtt->processPackets(20); // long-poll } } diff --git a/src/components/statusLED/Wippersnapper_StatusLED_Colors.h b/src/components/statusLED/Wippersnapper_StatusLED_Colors.h index a69ea979e..b56c10e61 100644 --- a/src/components/statusLED/Wippersnapper_StatusLED_Colors.h +++ b/src/components/statusLED/Wippersnapper_StatusLED_Colors.h @@ -22,7 +22,7 @@ #define BLUE 0x0000FF ///< Blue (as a uint32) // colors for each status state -#define LED_NET_CONNECT CYAN ///< Network connection state +#define LED_NET_CONNECT PINK ///< Network connection state #define LED_IO_CONNECT BLUE ///< MQTT broker connection state #define LED_IO_REGISTER_HW YELLOW ///< Hardware registration state #define LED_CONNECTED GREEN ///< Successful registration state