Skip to content

Commit e5d21ba

Browse files
committed
WIP: Set WS.publish to bool, add single retry, logging
1 parent 1a84583 commit e5d21ba

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

src/Wippersnapper.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ void publishI2CResponse(wippersnapper_signal_v1_I2CResponse *msgi2cResponse) {
558558
pb_get_encoded_size(&msgSz, wippersnapper_signal_v1_I2CResponse_fields,
559559
msgi2cResponse);
560560
WS_DEBUG_PRINT("Publishing Message: I2CResponse...");
561-
if (!WS._mqtt->publish(WS._topic_signal_i2c_device, WS._buffer_outgoing,
561+
if (!WS.publish(WS._topic_signal_i2c_device, WS._buffer_outgoing,
562562
msgSz, 1)) {
563563
WS_DEBUG_PRINTLN("ERROR: Failed to publish I2C Response!");
564564
} else {
@@ -995,7 +995,7 @@ bool cbDecodeServoMsg(pb_istream_t *stream, const pb_field_t *field,
995995
pb_get_encoded_size(&msgSz, wippersnapper_signal_v1_ServoResponse_fields,
996996
&msgServoResp);
997997
WS_DEBUG_PRINT("-> Servo Attach Response...");
998-
WS._mqtt->publish(WS._topic_signal_servo_device, WS._buffer_outgoing, msgSz,
998+
WS.publish(WS._topic_signal_servo_device, WS._buffer_outgoing, msgSz,
999999
1);
10001000
WS_DEBUG_PRINTLN("Published!");
10011001
} else if (field->tag ==
@@ -1161,7 +1161,7 @@ bool cbPWMDecodeMsg(pb_istream_t *stream, const pb_field_t *field, void **arg) {
11611161
pb_get_encoded_size(&msgSz, wippersnapper_signal_v1_PWMResponse_fields,
11621162
&msgPWMResponse);
11631163
WS_DEBUG_PRINT("PUBLISHING: PWM Attach Response...");
1164-
if (!WS._mqtt->publish(WS._topic_signal_pwm_device, WS._buffer_outgoing,
1164+
if (!WS.publish(WS._topic_signal_pwm_device, WS._buffer_outgoing,
11651165
msgSz, 1)) {
11661166
WS_DEBUG_PRINTLN("ERROR: Failed to publish PWM Attach Response!");
11671167
return false;
@@ -1571,7 +1571,7 @@ bool cbDecodeUARTMessage(pb_istream_t *stream, const pb_field_t *field,
15711571
pb_get_encoded_size(&msgSz, wippersnapper_signal_v1_UARTResponse_fields,
15721572
&msgUARTResponse);
15731573
WS_DEBUG_PRINT("PUBLISHING: UART Attach Response...");
1574-
if (!WS._mqtt->publish(WS._topic_signal_uart_device, WS._buffer_outgoing,
1574+
if (!WS.publish(WS._topic_signal_uart_device, WS._buffer_outgoing,
15751575
msgSz, 1)) {
15761576
WS_DEBUG_PRINTLN("ERROR: Failed to publish UART Attach Response!");
15771577
return false;
@@ -2653,14 +2653,26 @@ void Wippersnapper::processPackets() {
26532653
The Quality of Service to publish with.
26542654
*/
26552655
/*******************************************************/
2656-
void Wippersnapper::publish(const char *topic, uint8_t *payload, uint16_t bLen,
2656+
bool Wippersnapper::publish(const char *topic, uint8_t *payload, uint16_t bLen,
26572657
uint8_t qos) {
26582658
// runNetFSM(); // NOTE: Removed for now, causes error with virtual _connect
26592659
// method when caused with WS object in another file.
26602660
WS.feedWDT();
26612661
if (!WS._mqtt->publish(topic, payload, bLen, qos)) {
2662-
WS_DEBUG_PRINTLN("Failed to publish MQTT message!");
2662+
if (WS._mqtt->connected()) {
2663+
WS_DEBUG_PRINTLN("Failed to publish MQTT message, retrying!");
2664+
} else {
2665+
WS_DEBUG_PRINTLN("MQTT Disconnected! Running network FSM then publish...");
2666+
WS._mqtt->disconnect();
2667+
runNetFSM();
2668+
}
2669+
WS.feedWDT();
2670+
if (!WS._mqtt->publish(topic, payload, bLen, qos)) {
2671+
WS_DEBUG_PRINTLN("Failed to publish MQTT message!");
2672+
return false;
2673+
}
26632674
}
2675+
return true;
26642676
}
26652677

26662678
/**************************************************************/

src/Wippersnapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class Wippersnapper {
298298
// run() loop
299299
ws_status_t run();
300300
void processPackets();
301-
void publish(const char *topic, uint8_t *payload, uint16_t bLen,
301+
bool publish(const char *topic, uint8_t *payload, uint16_t bLen,
302302
uint8_t qos = 0);
303303

304304
// Networking helpers

src/components/ds18x20/ws_ds18x20.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ bool ws_ds18x20::addDS18x20(
116116
pb_get_encoded_size(&msgSz, wippersnapper_signal_v1_Ds18x20Response_fields,
117117
&msgInitResp);
118118
WS_DEBUG_PRINT("-> DS18x Init Response...");
119-
WS._mqtt->publish(WS._topic_signal_ds18_device, WS._buffer_outgoing, msgSz,
120-
1);
119+
WS.publish(WS._topic_signal_ds18_device, WS._buffer_outgoing, msgSz, 1);
121120
WS_DEBUG_PRINTLN("Published!");
122121

123122
return is_success;
@@ -294,7 +293,7 @@ void ws_ds18x20::update() {
294293
wippersnapper_signal_v1_Ds18x20Response_fields,
295294
&msgDS18x20Response);
296295
WS_DEBUG_PRINT("PUBLISHING -> msgDS18x20Response Event Message...");
297-
if (!WS._mqtt->publish(WS._topic_signal_ds18_device,
296+
if (!WS.publish(WS._topic_signal_ds18_device,
298297
WS._buffer_outgoing, msgSz, 1)) {
299298
WS_DEBUG_PRINTLN("ERROR: Unable to publish DS18x20 event message - "
300299
"MQTT Publish failed!");

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ bool WipperSnapper_Component_I2C::encodePublishI2CDeviceEventMsg(
921921
pb_get_encoded_size(&msgSz, wippersnapper_signal_v1_I2CResponse_fields,
922922
msgi2cResponse);
923923
WS_DEBUG_PRINT("PUBLISHING -> I2C Device Sensor Event Message...");
924-
if (!WS._mqtt->publish(WS._topic_signal_i2c_device, WS._buffer_outgoing,
924+
if (!WS.publish(WS._topic_signal_i2c_device, WS._buffer_outgoing,
925925
msgSz, 1)) {
926926
WS_DEBUG_PRINTLN("ERROR: MQTT Publish failed!");
927927
return false;

src/components/pixels/ws_pixels.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void ws_pixels::publishAddStrandResponse(bool is_success,
182182
pb_get_encoded_size(&msgSz, wippersnapper_signal_v1_PixelsResponse_fields,
183183
&msgInitResp);
184184
WS_DEBUG_PRINT("-> wippersnapper_signal_v1_PixelsResponse...");
185-
WS._mqtt->publish(WS._topic_signal_pixels_device, WS._buffer_outgoing, msgSz,
185+
WS.publish(WS._topic_signal_pixels_device, WS._buffer_outgoing, msgSz,
186186
1);
187187
WS_DEBUG_PRINTLN("Published!");
188188
}

0 commit comments

Comments
 (0)