Skip to content

Commit f490a4a

Browse files
committed
add message for pinconfigcomplete
1 parent 877c601 commit f490a4a

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/Wippersnapper.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,12 +741,17 @@ bool Wippersnapper::buildWSTopics() {
741741
strlen(_device_uid) + strlen(TOPIC_DESCRIPTION) + strlen("status") +
742742
strlen("broker") + 1);
743743

744-
// Registration status topic
744+
// Registration status completion topic
745745
WS._topic_description_status_complete = (char *)malloc(
746746
sizeof(char) * strlen(WS._username) + +strlen("/wprsnpr/") +
747747
strlen(_device_uid) + strlen(TOPIC_DESCRIPTION) + strlen("status") +
748748
strlen("/device/complete") + 1);
749749

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+
750755
// Topic for signals from device to broker
751756
WS._topic_signal_device = (char *)malloc(
752757
sizeof(char) * strlen(WS._username) + +strlen("/") + strlen(_device_uid) +
@@ -806,6 +811,18 @@ bool Wippersnapper::buildWSTopics() {
806811
is_success = false;
807812
}
808813

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+
809826
// Create broker-to-device signal topic
810827
if (WS._topic_signal_brkr) {
811828
strcpy(WS._topic_signal_brkr, WS._username);
@@ -1080,11 +1097,36 @@ void Wippersnapper::connect() {
10801097

10811098
WS_DEBUG_PRINTLN("POLLING CONFIG PACKETS FOR 2SEC.");
10821099
WS._mqtt->processPackets(2000);
1083-
// TODO
10841100
// did we get and process the registration message?
10851101
if (!WS.pinCfgCompleted)
10861102
haltError("Did not get configuration message from broker, resetting...");
10871103

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+
10881130
WS_DEBUG_PRINTLN("Configuration complete!\nRunning application.");
10891131
}
10901132

src/Wippersnapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ class Wippersnapper {
301301
char *_topic_description_status; /*!< MQTT subtopic carrying the description
302302
status resp. from the broker */
303303
char *_topic_description_status_complete;
304+
char *_topic_device_pin_config_complete;
304305
char *_topic_signal_brkr; /*!< Wprsnpr->Device messages */
305306

306307
Adafruit_MQTT_Subscribe

0 commit comments

Comments
 (0)