@@ -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/* *************************************************************/
0 commit comments