Skip to content

Commit

Permalink
Merge pull request #158 from adafruit/small-updates
Browse files Browse the repository at this point in the history
Small updates for beta.11
  • Loading branch information
brentru authored Sep 22, 2021
2 parents 9a5b56a + 3c09a55 commit 44184fd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 34 deletions.
50 changes: 26 additions & 24 deletions src/Wippersnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/Wippersnapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
5 changes: 2 additions & 3 deletions src/components/register/Wippersnapper_Register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/statusLED/Wippersnapper_StatusLED_Colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 44184fd

Please sign in to comment.