@@ -733,41 +733,41 @@ bool Wippersnapper::buildWSTopics() {
733
733
// Global registration topic
734
734
WS._topic_description =
735
735
(char *)malloc (sizeof (char ) * strlen (WS._username ) + strlen (" /wprsnpr" ) +
736
- strlen (TOPIC_DESCRIPTION ) + strlen (" status" ) + 1 );
736
+ strlen (TOPIC_INFO ) + strlen (" status" ) + 1 );
737
737
738
738
// 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 );
743
743
744
744
// 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 );
749
749
750
750
// 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 );
755
755
756
756
// Topic for signals from device to broker
757
757
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 );
760
760
761
761
// Topic for signals from broker to device
762
762
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 );
765
765
766
766
// Create global registration topic
767
767
if (WS._topic_description ) {
768
768
strcpy (WS._topic_description , WS._username );
769
769
strcat (WS._topic_description , " /wprsnpr" );
770
- strcat (WS._topic_description , TOPIC_DESCRIPTION );
770
+ strcat (WS._topic_description , TOPIC_INFO );
771
771
strcat (WS._topic_description , " status" );
772
772
} else { // malloc failed
773
773
WS._topic_description = 0 ;
@@ -779,7 +779,7 @@ bool Wippersnapper::buildWSTopics() {
779
779
strcpy (WS._topic_description_status , WS._username );
780
780
strcat (WS._topic_description_status , " /wprsnpr/" );
781
781
strcat (WS._topic_description_status , _device_uid);
782
- strcat (WS._topic_description_status , TOPIC_DESCRIPTION );
782
+ strcat (WS._topic_description_status , TOPIC_INFO );
783
783
strcat (WS._topic_description_status , " status" );
784
784
strcat (WS._topic_description_status , " /broker" );
785
785
} else { // malloc failed
@@ -792,7 +792,7 @@ bool Wippersnapper::buildWSTopics() {
792
792
strcpy (WS._topic_description_status_complete , WS._username );
793
793
strcat (WS._topic_description_status_complete , " /wprsnpr/" );
794
794
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 );
796
796
strcat (WS._topic_description_status_complete , " status" );
797
797
strcat (WS._topic_description_status_complete , " /device/complete" );
798
798
} else { // malloc failed
@@ -847,13 +847,15 @@ bool Wippersnapper::buildWSTopics() {
847
847
void Wippersnapper::subscribeWSTopics () {
848
848
// Subscribe to signal topic
849
849
_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" );
851
852
WS._mqtt ->subscribe (_topic_signal_brkr_sub);
852
853
_topic_signal_brkr_sub->setCallback (cbSignalTopic);
853
854
854
855
// Subscribe to registration status topic
855
856
_topic_description_sub =
856
857
new Adafruit_MQTT_Subscribe (WS._mqtt , WS._topic_description_status , 1 );
858
+ WS_DEBUG_PRINTLN (" Subscribing to signals/status" );
857
859
WS._mqtt ->subscribe (_topic_description_sub);
858
860
_topic_description_sub->setCallback (cbRegistrationStatus);
859
861
}
@@ -941,7 +943,6 @@ void Wippersnapper::haltError(String error) {
941
943
*/
942
944
/* *************************************************************************/
943
945
bool Wippersnapper::registerBoard () {
944
- bool is_success = false ;
945
946
WS_DEBUG_PRINTLN (" Registering hardware with IO..." );
946
947
947
948
// Encode and publish registration request message to broker
@@ -1065,18 +1066,20 @@ void Wippersnapper::connect() {
1065
1066
// enable WDT
1066
1067
enableWDT (WS_WDT_TIMEOUT);
1067
1068
1069
+ // TODO!
1068
1070
// not sure we need to track these...
1069
1071
_status = WS_IDLE;
1070
1072
WS._boardStatus = WS_BOARD_DEF_IDLE;
1071
1073
1072
- // build MQTT topics for WipperSnapper app, and subscribe
1074
+ // build MQTT topics for WipperSnapper and subscribe
1073
1075
if (!buildWSTopics ()) {
1074
1076
haltError (" Unable to allocate space for MQTT topics" );
1075
1077
}
1076
- subscribeWSTopics ();
1077
1078
if (!buildErrorTopics ()) {
1078
1079
haltError (" Unable to allocate space for MQTT error topics" );
1079
1080
}
1081
+ WS_DEBUG_PRINTLN (" Subscribing to MQTT topics..." );
1082
+ subscribeWSTopics ();
1080
1083
subscribeErrorTopics ();
1081
1084
1082
1085
// Run the network fsm
@@ -1096,7 +1099,8 @@ void Wippersnapper::connect() {
1096
1099
// Configure hardware
1097
1100
WS.pinCfgCompleted = false ;
1098
1101
while (!WS.pinCfgCompleted ) {
1099
- WS_DEBUG_PRINTLN (" Polling for message containing hardware configuration..." );
1102
+ WS_DEBUG_PRINTLN (
1103
+ " Polling for message containing hardware configuration..." );
1100
1104
WS._mqtt ->processPackets (10 ); // poll
1101
1105
}
1102
1106
// Publish that we have completed the configuration workflow
0 commit comments