@@ -741,12 +741,17 @@ bool Wippersnapper::buildWSTopics() {
741
741
strlen (_device_uid) + strlen (TOPIC_DESCRIPTION) + strlen (" status" ) +
742
742
strlen (" broker" ) + 1 );
743
743
744
- // Registration status topic
744
+ // Registration status completion topic
745
745
WS._topic_description_status_complete = (char *)malloc (
746
746
sizeof (char ) * strlen (WS._username ) + +strlen (" /wprsnpr/" ) +
747
747
strlen (_device_uid) + strlen (TOPIC_DESCRIPTION) + strlen (" status" ) +
748
748
strlen (" /device/complete" ) + 1 );
749
749
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) + strlen (" device/pinConfigComplete" ) + 1 );
754
+
750
755
// Topic for signals from device to broker
751
756
WS._topic_signal_device = (char *)malloc (
752
757
sizeof (char ) * strlen (WS._username ) + +strlen (" /" ) + strlen (_device_uid) +
@@ -806,6 +811,18 @@ bool Wippersnapper::buildWSTopics() {
806
811
is_success = false ;
807
812
}
808
813
814
+ // Create device-to-broker signal topic
815
+ if (WS._topic_device_pin_config_complete ) {
816
+ strcpy (WS._topic_device_pin_config_complete , WS._username );
817
+ strcat (WS._topic_device_pin_config_complete , " /wprsnpr/" );
818
+ strcat (WS._topic_device_pin_config_complete , _device_uid);
819
+ strcat (WS._topic_device_pin_config_complete , TOPIC_SIGNALS);
820
+ strcat (WS._topic_device_pin_config_complete , " device/pinConfigComplete" );
821
+ } else { // malloc failed
822
+ WS._topic_device_pin_config_complete = 0 ;
823
+ is_success = false ;
824
+ }
825
+
809
826
// Create broker-to-device signal topic
810
827
if (WS._topic_signal_brkr ) {
811
828
strcpy (WS._topic_signal_brkr , WS._username );
@@ -1080,11 +1097,36 @@ void Wippersnapper::connect() {
1080
1097
1081
1098
WS_DEBUG_PRINTLN (" POLLING CONFIG PACKETS FOR 2SEC." );
1082
1099
WS._mqtt ->processPackets (2000 );
1083
- // TODO
1084
1100
// did we get and process the registration message?
1085
1101
if (!WS.pinCfgCompleted )
1086
1102
haltError (" Did not get configuration message from broker, resetting..." );
1087
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!" );
1128
+
1129
+
1088
1130
WS_DEBUG_PRINTLN (" Configuration complete!\n Running application." );
1089
1131
}
1090
1132
0 commit comments