@@ -750,7 +750,8 @@ bool Wippersnapper::buildWSTopics() {
750
750
// Topic to signal pin configuration complete from device to broker
751
751
WS._topic_device_pin_config_complete = (char *)malloc (
752
752
sizeof (char ) * strlen (WS._username ) + +strlen (" /" ) + strlen (_device_uid) +
753
- strlen (" /wprsnpr/" ) + strlen (TOPIC_SIGNALS) + strlen (" device/pinConfigComplete" ) + 1 );
753
+ strlen (" /wprsnpr/" ) + strlen (TOPIC_SIGNALS) +
754
+ strlen (" device/pinConfigComplete" ) + 1 );
754
755
755
756
// Topic for signals from device to broker
756
757
WS._topic_signal_device = (char *)malloc (
@@ -786,7 +787,7 @@ bool Wippersnapper::buildWSTopics() {
786
787
is_success = false ;
787
788
}
788
789
789
- // Create registration status complete topic
790
+ // Create registration status complete topic
790
791
if (WS._topic_description_status_complete ) {
791
792
strcpy (WS._topic_description_status_complete , WS._username );
792
793
strcat (WS._topic_description_status_complete , " /wprsnpr/" );
@@ -1084,50 +1085,60 @@ void Wippersnapper::connect() {
1084
1085
setStatusLEDColor (LED_CONNECTED);
1085
1086
1086
1087
// Register hardware with Wippersnapper
1087
- WS_DEBUG_PRINTLN (" Registering Board ..." )
1088
+ WS_DEBUG_PRINTLN (" Registering hardware with WipperSnapper ..." )
1088
1089
setStatusLEDColor (LED_IO_REGISTER_HW);
1089
1090
1090
1091
if (!registerBoard ()) {
1091
- haltError (" Unable to register board with Wippersnapper ." );
1092
+ haltError (" Unable to register with WipperSnapper ." );
1092
1093
}
1093
1094
feedWDT (); // Hardware registered with IO, feed WDT */
1095
+ WS_DEBUG_PRINTLN (" Registered with WipperSnapper." );
1094
1096
1095
- WS_DEBUG_PRINTLN (" Registered board with Wippersnapper." );
1096
- statusLEDBlink (WS_LED_STATUS_CONNECTED);
1097
-
1098
- WS_DEBUG_PRINTLN (" POLLING CONFIG PACKETS FOR 2SEC." );
1097
+ WS_DEBUG_PRINTLN (" Polling for configuration message..." );
1099
1098
WS._mqtt ->processPackets (2000 );
1099
+
1100
1100
// did we get and process the registration message?
1101
1101
if (!WS.pinCfgCompleted )
1102
1102
haltError (" Did not get configuration message from broker, resetting..." );
1103
1103
1104
- // Publish that we've set up the pins and are ready to run
1105
- // Publish RegistrationComplete message to broker
1106
- wippersnapper_signal_v1_SignalResponse msg = wippersnapper_signal_v1_SignalResponse_init_zero;
1107
- msg.which_payload = wippersnapper_signal_v1_SignalResponse_configuration_complete_tag;
1108
- msg.payload .configuration_complete = true ;
1109
-
1110
- // encode registration request message
1111
- uint8_t _message_buffer[128 ];
1112
- pb_ostream_t _msg_stream =
1113
- pb_ostream_from_buffer (_message_buffer, sizeof (_message_buffer));
1114
-
1115
- bool _status = pb_encode (
1116
- &_msg_stream,
1117
- wippersnapper_description_v1_RegistrationComplete_fields, &msg);
1118
- size_t _message_len = _msg_stream.bytes_written ;
1119
-
1120
- // verify message encoded correctly
1121
- if (!_status)
1122
- haltError (" Could not encode, resetting..." );
1123
-
1124
- // Publish message
1125
- WS_DEBUG_PRINTLN (" Publishing to pin config complete..." );
1126
- WS.publish (WS._topic_device_pin_config_complete , _message_buffer, _message_len, 1 );
1127
- WS_DEBUG_PRINTLN (" Completed registration process, configuration next!" );
1104
+ // Publish that we have completed the configuration workflow
1105
+ feedWDT ();
1106
+ runNetFSM ();
1107
+ publishPinConfigComplete ();
1128
1108
1109
+ // Run application
1110
+ statusLEDBlink (WS_LED_STATUS_CONNECTED);
1111
+ WS_DEBUG_PRINTLN (
1112
+ " Registration and configuration complete!\n Running application..." );
1113
+ }
1129
1114
1130
- WS_DEBUG_PRINTLN (" Configuration complete!\n Running application." );
1115
+ void Wippersnapper::publishPinConfigComplete () {
1116
+ // Publish that we've set up the pins and are ready to run
1117
+ wippersnapper_signal_v1_SignalResponse msg =
1118
+ wippersnapper_signal_v1_SignalResponse_init_zero;
1119
+ msg.which_payload =
1120
+ wippersnapper_signal_v1_SignalResponse_configuration_complete_tag;
1121
+ msg.payload .configuration_complete = true ;
1122
+
1123
+ // encode registration request message
1124
+ uint8_t _message_buffer[128 ];
1125
+ pb_ostream_t _msg_stream =
1126
+ pb_ostream_from_buffer (_message_buffer, sizeof (_message_buffer));
1127
+
1128
+ bool _status =
1129
+ pb_encode (&_msg_stream,
1130
+ wippersnapper_description_v1_RegistrationComplete_fields, &msg);
1131
+ size_t _message_len = _msg_stream.bytes_written ;
1132
+
1133
+ // verify message encoded correctly
1134
+ if (!_status)
1135
+ haltError (" Could not encode, resetting..." );
1136
+
1137
+ // Publish message
1138
+ WS_DEBUG_PRINTLN (" Publishing to pin config complete..." );
1139
+ WS.publish (WS._topic_device_pin_config_complete , _message_buffer,
1140
+ _message_len, 1 );
1141
+ WS_DEBUG_PRINTLN (" Completed registration process, configuration next!" );
1131
1142
}
1132
1143
1133
1144
/* *************************************************************************/
@@ -1138,12 +1149,8 @@ void Wippersnapper::connect() {
1138
1149
/* *************************************************************************/
1139
1150
ws_status_t Wippersnapper::run () {
1140
1151
// Check networking
1141
- // TODO: Handle MQTT errors within the new netcode, or bring them outwards to
1142
- // another fsm
1143
1152
runNetFSM ();
1144
1153
feedWDT ();
1145
-
1146
- // keepalive
1147
1154
pingBroker ();
1148
1155
1149
1156
// Process all incoming packets from Wippersnapper MQTT Broker
0 commit comments