Skip to content

Commit 5c60bf7

Browse files
committed
increase buffer sizes, update mallocs
1 parent 52ded2f commit 5c60bf7

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

src/Wippersnapper.cpp

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -733,41 +733,41 @@ bool Wippersnapper::buildWSTopics() {
733733
// Global registration topic
734734
WS._topic_description =
735735
(char *)malloc(sizeof(char) * strlen(WS._username) + strlen("/wprsnpr") +
736-
strlen(TOPIC_DESCRIPTION) + strlen("status") + 1);
736+
strlen(TOPIC_INFO) + strlen("status") + 1);
737737

738738
// Registration status topic
739-
WS._topic_description_status = (char *)malloc(
740-
sizeof(char) * strlen(WS._username) + +strlen("/wprsnpr/") +
741-
strlen(_device_uid) + strlen(TOPIC_DESCRIPTION) + strlen("status") +
742-
strlen("broker") + 1);
739+
WS._topic_description_status =
740+
(char *)malloc(sizeof(char) * strlen(WS._username) + strlen("/wprsnpr/") +
741+
strlen(_device_uid) + strlen(TOPIC_INFO) +
742+
strlen("status/") + strlen("broker") + 1);
743743

744744
// Registration status completion topic
745-
WS._topic_description_status_complete = (char *)malloc(
746-
sizeof(char) * strlen(WS._username) + +strlen("/wprsnpr/") +
747-
strlen(_device_uid) + strlen(TOPIC_DESCRIPTION) + strlen("status") +
748-
strlen("/device/complete") + 1);
745+
WS._topic_description_status_complete =
746+
(char *)malloc(sizeof(char) * strlen(WS._username) + strlen("/wprsnpr/") +
747+
strlen(_device_uid) + strlen(TOPIC_INFO) +
748+
strlen("status") + strlen("/device/complete") + 1);
749749

750750
// Topic to signal pin configuration complete from device to broker
751-
WS._topic_device_pin_config_complete = (char *)malloc(
752-
sizeof(char) * strlen(WS._username) + +strlen("/") + strlen(_device_uid) +
753-
strlen("/wprsnpr/") + strlen(TOPIC_SIGNALS) +
754-
strlen("device/pinConfigComplete") + 1);
751+
WS._topic_device_pin_config_complete =
752+
(char *)malloc(sizeof(char) * strlen(WS._username) + strlen("/wprsnpr/") +
753+
strlen(_device_uid) + strlen(TOPIC_SIGNALS) +
754+
strlen("device/pinConfigComplete") + 1);
755755

756756
// Topic for signals from device to broker
757757
WS._topic_signal_device = (char *)malloc(
758-
sizeof(char) * strlen(WS._username) + +strlen("/") + strlen(_device_uid) +
759-
strlen("/wprsnpr/") + strlen(TOPIC_SIGNALS) + strlen("device") + 1);
758+
sizeof(char) * strlen(WS._username) + strlen("/wprsnpr/") +
759+
strlen(_device_uid) + strlen(TOPIC_SIGNALS) + strlen("device") + 1);
760760

761761
// Topic for signals from broker to device
762762
WS._topic_signal_brkr = (char *)malloc(
763-
sizeof(char) * strlen(WS._username) + +strlen("/") + strlen(_device_uid) +
764-
strlen("/wprsnpr/") + strlen(TOPIC_SIGNALS) + strlen("broker") + 1);
763+
sizeof(char) * strlen(WS._username) + strlen("/wprsnpr/") +
764+
strlen(_device_uid) + strlen(TOPIC_SIGNALS) + strlen("broker") + 1);
765765

766766
// Create global registration topic
767767
if (WS._topic_description) {
768768
strcpy(WS._topic_description, WS._username);
769769
strcat(WS._topic_description, "/wprsnpr");
770-
strcat(WS._topic_description, TOPIC_DESCRIPTION);
770+
strcat(WS._topic_description, TOPIC_INFO);
771771
strcat(WS._topic_description, "status");
772772
} else { // malloc failed
773773
WS._topic_description = 0;
@@ -779,7 +779,7 @@ bool Wippersnapper::buildWSTopics() {
779779
strcpy(WS._topic_description_status, WS._username);
780780
strcat(WS._topic_description_status, "/wprsnpr/");
781781
strcat(WS._topic_description_status, _device_uid);
782-
strcat(WS._topic_description_status, TOPIC_DESCRIPTION);
782+
strcat(WS._topic_description_status, TOPIC_INFO);
783783
strcat(WS._topic_description_status, "status");
784784
strcat(WS._topic_description_status, "/broker");
785785
} else { // malloc failed
@@ -792,7 +792,7 @@ bool Wippersnapper::buildWSTopics() {
792792
strcpy(WS._topic_description_status_complete, WS._username);
793793
strcat(WS._topic_description_status_complete, "/wprsnpr/");
794794
strcat(WS._topic_description_status_complete, _device_uid);
795-
strcat(WS._topic_description_status_complete, TOPIC_DESCRIPTION);
795+
strcat(WS._topic_description_status_complete, TOPIC_INFO);
796796
strcat(WS._topic_description_status_complete, "status");
797797
strcat(WS._topic_description_status_complete, "/device/complete");
798798
} else { // malloc failed
@@ -847,13 +847,15 @@ bool Wippersnapper::buildWSTopics() {
847847
void Wippersnapper::subscribeWSTopics() {
848848
// Subscribe to signal topic
849849
_topic_signal_brkr_sub =
850-
new Adafruit_MQTT_Subscribe(WS._mqtt, WS._topic_signal_brkr, 1);
850+
new Adafruit_MQTT_Subscribe(WS._mqtt, WS._topic_signal_brkr, 0);
851+
WS_DEBUG_PRINTLN("Subscribing to signals/broker");
851852
WS._mqtt->subscribe(_topic_signal_brkr_sub);
852853
_topic_signal_brkr_sub->setCallback(cbSignalTopic);
853854

854855
// Subscribe to registration status topic
855856
_topic_description_sub =
856857
new Adafruit_MQTT_Subscribe(WS._mqtt, WS._topic_description_status, 1);
858+
WS_DEBUG_PRINTLN("Subscribing to signals/status");
857859
WS._mqtt->subscribe(_topic_description_sub);
858860
_topic_description_sub->setCallback(cbRegistrationStatus);
859861
}
@@ -941,7 +943,6 @@ void Wippersnapper::haltError(String error) {
941943
*/
942944
/**************************************************************************/
943945
bool Wippersnapper::registerBoard() {
944-
bool is_success = false;
945946
WS_DEBUG_PRINTLN("Registering hardware with IO...");
946947

947948
// Encode and publish registration request message to broker
@@ -1065,18 +1066,20 @@ void Wippersnapper::connect() {
10651066
// enable WDT
10661067
enableWDT(WS_WDT_TIMEOUT);
10671068

1069+
// TODO!
10681070
// not sure we need to track these...
10691071
_status = WS_IDLE;
10701072
WS._boardStatus = WS_BOARD_DEF_IDLE;
10711073

1072-
// build MQTT topics for WipperSnapper app, and subscribe
1074+
// build MQTT topics for WipperSnapper and subscribe
10731075
if (!buildWSTopics()) {
10741076
haltError("Unable to allocate space for MQTT topics");
10751077
}
1076-
subscribeWSTopics();
10771078
if (!buildErrorTopics()) {
10781079
haltError("Unable to allocate space for MQTT error topics");
10791080
}
1081+
WS_DEBUG_PRINTLN("Subscribing to MQTT topics...");
1082+
subscribeWSTopics();
10801083
subscribeErrorTopics();
10811084

10821085
// Run the network fsm
@@ -1096,7 +1099,8 @@ void Wippersnapper::connect() {
10961099
// Configure hardware
10971100
WS.pinCfgCompleted = false;
10981101
while (!WS.pinCfgCompleted) {
1099-
WS_DEBUG_PRINTLN("Polling for message containing hardware configuration...");
1102+
WS_DEBUG_PRINTLN(
1103+
"Polling for message containing hardware configuration...");
11001104
WS._mqtt->processPackets(10); // poll
11011105
}
11021106
// Publish that we have completed the configuration workflow

src/Wippersnapper.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171
#define TOPIC_IO_ERRORS "/errors" ///< Adafruit IO Error MQTT Topic
7272

7373
// Reserved Wippersnapper topics
74-
#define TOPIC_WS "/wprsnpr/" ///< Global /wprsnpr/ topic
75-
#define TOPIC_DESCRIPTION "/info/" ///< Device description topic
76-
#define TOPIC_SIGNALS "/signals/" ///< Device signals topic
74+
#define TOPIC_WS "/wprsnpr/" ///< Global /wprsnpr/ topic
75+
#define TOPIC_INFO "/info/" ///< Device description topic
76+
#define TOPIC_SIGNALS "/signals/" ///< Device signals topic
7777

7878
#define WS_DEBUG ///< Define to enable debugging to serial terminal
7979
#define WS_PRINTER Serial ///< Where debug messages will be printed
@@ -259,7 +259,7 @@ class Wippersnapper {
259259
Wippersnapper_ESP32_nvs *_nvs; ///< Instance of nvs
260260

261261
uint8_t _uid[6]; /*!< Unique network iface identifier */
262-
char sUID[10]; /*!< Unique network iface identifier */
262+
char sUID[13]; /*!< Unique network iface identifier */
263263
const char *_boardId; /*!< Adafruit IO+ board string */
264264
Adafruit_MQTT *_mqtt; /*!< Reference to Adafruit_MQTT, _mqtt. */
265265
char *_topic_description; /*!< MQTT topic for the device description */

src/components/register/Wippersnapper_Register.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool Wippersnapper::encodePubRegistrationReq() {
4242
strcpy(_message.str_version, WS_VERSION);
4343

4444
// encode registration request message
45-
uint8_t _message_buffer[128];
45+
uint8_t _message_buffer[256];
4646
pb_ostream_t _msg_stream =
4747
pb_ostream_from_buffer(_message_buffer, sizeof(_message_buffer));
4848

0 commit comments

Comments
 (0)