@@ -558,7 +558,7 @@ void publishI2CResponse(wippersnapper_signal_v1_I2CResponse *msgi2cResponse) {
558
558
pb_get_encoded_size (&msgSz, wippersnapper_signal_v1_I2CResponse_fields,
559
559
msgi2cResponse);
560
560
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 ,
562
562
msgSz, 1 )) {
563
563
WS_DEBUG_PRINTLN (" ERROR: Failed to publish I2C Response!" );
564
564
} else {
@@ -995,7 +995,7 @@ bool cbDecodeServoMsg(pb_istream_t *stream, const pb_field_t *field,
995
995
pb_get_encoded_size (&msgSz, wippersnapper_signal_v1_ServoResponse_fields,
996
996
&msgServoResp);
997
997
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,
999
999
1 );
1000
1000
WS_DEBUG_PRINTLN (" Published!" );
1001
1001
} else if (field->tag ==
@@ -1161,7 +1161,7 @@ bool cbPWMDecodeMsg(pb_istream_t *stream, const pb_field_t *field, void **arg) {
1161
1161
pb_get_encoded_size (&msgSz, wippersnapper_signal_v1_PWMResponse_fields,
1162
1162
&msgPWMResponse);
1163
1163
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 ,
1165
1165
msgSz, 1 )) {
1166
1166
WS_DEBUG_PRINTLN (" ERROR: Failed to publish PWM Attach Response!" );
1167
1167
return false ;
@@ -1571,7 +1571,7 @@ bool cbDecodeUARTMessage(pb_istream_t *stream, const pb_field_t *field,
1571
1571
pb_get_encoded_size (&msgSz, wippersnapper_signal_v1_UARTResponse_fields,
1572
1572
&msgUARTResponse);
1573
1573
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 ,
1575
1575
msgSz, 1 )) {
1576
1576
WS_DEBUG_PRINTLN (" ERROR: Failed to publish UART Attach Response!" );
1577
1577
return false ;
@@ -2653,14 +2653,26 @@ void Wippersnapper::processPackets() {
2653
2653
The Quality of Service to publish with.
2654
2654
*/
2655
2655
/* ******************************************************/
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,
2657
2657
uint8_t qos) {
2658
2658
// runNetFSM(); // NOTE: Removed for now, causes error with virtual _connect
2659
2659
// method when caused with WS object in another file.
2660
2660
WS.feedWDT ();
2661
2661
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
+ }
2663
2674
}
2675
+ return true ;
2664
2676
}
2665
2677
2666
2678
/* *************************************************************/
0 commit comments