@@ -750,7 +750,8 @@ bool Wippersnapper::buildWSTopics() {
750750 // Topic to signal pin configuration complete from device to broker
751751 WS._topic_device_pin_config_complete = (char *)malloc (
752752 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 );
754755
755756 // Topic for signals from device to broker
756757 WS._topic_signal_device = (char *)malloc (
@@ -786,7 +787,7 @@ bool Wippersnapper::buildWSTopics() {
786787 is_success = false ;
787788 }
788789
789- // Create registration status complete topic
790+ // Create registration status complete topic
790791 if (WS._topic_description_status_complete ) {
791792 strcpy (WS._topic_description_status_complete , WS._username );
792793 strcat (WS._topic_description_status_complete , " /wprsnpr/" );
@@ -1084,50 +1085,60 @@ void Wippersnapper::connect() {
10841085 setStatusLEDColor (LED_CONNECTED);
10851086
10861087 // Register hardware with Wippersnapper
1087- WS_DEBUG_PRINTLN (" Registering Board ..." )
1088+ WS_DEBUG_PRINTLN (" Registering hardware with WipperSnapper ..." )
10881089 setStatusLEDColor (LED_IO_REGISTER_HW);
10891090
10901091 if (!registerBoard ()) {
1091- haltError (" Unable to register board with Wippersnapper ." );
1092+ haltError (" Unable to register with WipperSnapper ." );
10921093 }
10931094 feedWDT (); // Hardware registered with IO, feed WDT */
1095+ WS_DEBUG_PRINTLN (" Registered with WipperSnapper." );
10941096
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..." );
10991098 WS._mqtt ->processPackets (2000 );
1099+
11001100 // did we get and process the registration message?
11011101 if (!WS.pinCfgCompleted )
11021102 haltError (" Did not get configuration message from broker, resetting..." );
11031103
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 ();
11281108
1109+ // Run application
1110+ statusLEDBlink (WS_LED_STATUS_CONNECTED);
1111+ WS_DEBUG_PRINTLN (
1112+ " Registration and configuration complete!\n Running application..." );
1113+ }
11291114
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!" );
11311142}
11321143
11331144/* *************************************************************************/
@@ -1138,12 +1149,8 @@ void Wippersnapper::connect() {
11381149/* *************************************************************************/
11391150ws_status_t Wippersnapper::run () {
11401151 // Check networking
1141- // TODO: Handle MQTT errors within the new netcode, or bring them outwards to
1142- // another fsm
11431152 runNetFSM ();
11441153 feedWDT ();
1145-
1146- // keepalive
11471154 pingBroker ();
11481155
11491156 // Process all incoming packets from Wippersnapper MQTT Broker
0 commit comments