Skip to content

Commit a509cea

Browse files
committed
Change WS.publish to return bool
1 parent 4f1d110 commit a509cea

File tree

6 files changed

+55
-21
lines changed

6 files changed

+55
-21
lines changed

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ lib_deps =
9494

9595
; Common build environment for ESP32 platform
9696
[common:esp32]
97-
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.07/platform-espressif32.zip
97+
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.11/platform-espressif32.zip
9898
; This is needed for occasional new features and bug fixes
9999
; platform = https://github.com/pioarduino/platform-espressif32#develop
100100
lib_ignore = WiFiNINA, WiFi101, OneWire

src/Wippersnapper.cpp

Lines changed: 32 additions & 11 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,9 +995,16 @@ 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,
999-
1);
1000-
WS_DEBUG_PRINTLN("Published!");
998+
if (!WS.publish(WS._topic_signal_servo_device, WS._buffer_outgoing, msgSz,
999+
1))
1000+
{
1001+
WS_DEBUG_PRINTLN("ERROR: Failed to publish Servo Attach Response!");
1002+
return false;
1003+
}
1004+
else
1005+
{
1006+
WS_DEBUG_PRINTLN("Published!");
1007+
}
10011008
} else if (field->tag ==
10021009
wippersnapper_signal_v1_ServoRequest_servo_write_tag) {
10031010
WS_DEBUG_PRINTLN("GOT: Servo Write");
@@ -1161,12 +1168,12 @@ bool cbPWMDecodeMsg(pb_istream_t *stream, const pb_field_t *field, void **arg) {
11611168
pb_get_encoded_size(&msgSz, wippersnapper_signal_v1_PWMResponse_fields,
11621169
&msgPWMResponse);
11631170
WS_DEBUG_PRINT("PUBLISHING: PWM Attach Response...");
1164-
if (!WS._mqtt->publish(WS._topic_signal_pwm_device, WS._buffer_outgoing,
1171+
if (!WS.publish(WS._topic_signal_pwm_device, WS._buffer_outgoing,
11651172
msgSz, 1)) {
11661173
WS_DEBUG_PRINTLN("ERROR: Failed to publish PWM Attach Response!");
11671174
return false;
11681175
}
1169-
WS_DEBUG_PRINTLN("Published!");
1176+
WS_DEBUG_PRINTLN("Published! (PWM Attach Response)");
11701177

11711178
#ifdef USE_DISPLAY
11721179
char buffer[100];
@@ -1571,12 +1578,12 @@ bool cbDecodeUARTMessage(pb_istream_t *stream, const pb_field_t *field,
15711578
pb_get_encoded_size(&msgSz, wippersnapper_signal_v1_UARTResponse_fields,
15721579
&msgUARTResponse);
15731580
WS_DEBUG_PRINT("PUBLISHING: UART Attach Response...");
1574-
if (!WS._mqtt->publish(WS._topic_signal_uart_device, WS._buffer_outgoing,
1581+
if (!WS.publish(WS._topic_signal_uart_device, WS._buffer_outgoing,
15751582
msgSz, 1)) {
15761583
WS_DEBUG_PRINTLN("ERROR: Failed to publish UART Attach Response!");
15771584
return false;
15781585
}
1579-
WS_DEBUG_PRINTLN("Published!");
1586+
WS_DEBUG_PRINTLN("Published! (UART Device Attached)");
15801587

15811588
} else if (field->tag ==
15821589
wippersnapper_signal_v1_UARTRequest_req_uart_device_detach_tag) {
@@ -2653,14 +2660,27 @@ void Wippersnapper::processPackets() {
26532660
The Quality of Service to publish with.
26542661
*/
26552662
/*******************************************************/
2656-
void Wippersnapper::publish(const char *topic, uint8_t *payload, uint16_t bLen,
2663+
bool Wippersnapper::publish(const char *topic, uint8_t *payload, uint16_t bLen,
26572664
uint8_t qos) {
26582665
// runNetFSM(); // NOTE: Removed for now, causes error with virtual _connect
26592666
// method when caused with WS object in another file.
26602667
WS.feedWDT();
2661-
if (!WS._mqtt->publish(topic, payload, bLen, qos)) {
2662-
WS_DEBUG_PRINTLN("Failed to publish MQTT message!");
2668+
bool response = WS._mqtt->publish(topic, payload, bLen, qos);
2669+
if (!response) {
2670+
WS_DEBUG_PRINTLN("Failed to publish MQTT message (t: ");
2671+
WS_DEBUG_PRINT(topic);
2672+
WS_DEBUG_PRINT(" q: ");
2673+
WS_DEBUG_PRINT(qos);
2674+
WS_DEBUG_PRINT(" l: ");
2675+
WS_DEBUG_PRINT(bLen);
2676+
WS_DEBUG_PRINT(" hex: ");
2677+
for (uint16_t i = 0; i < bLen; i++) {
2678+
WS_DEBUG_PRINTHEX(payload[i]);
2679+
WS_DEBUG_PRINT(" ");
2680+
}
2681+
WS_DEBUG_PRINTLN(")\n");
26632682
}
2683+
return response;
26642684
}
26652685

26662686
/**************************************************************/
@@ -2863,6 +2883,7 @@ void Wippersnapper::publishPinConfigComplete() {
28632883
WS_DEBUG_PRINTLN("Publishing to pin config complete...");
28642884
WS.publish(WS._topic_device_pin_config_complete, _message_buffer,
28652885
_message_len, 1);
2886+
WS_DEBUG_PRINTLN("Published! (pin config complete)");
28662887
}
28672888

28682889
/**************************************************************************/

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: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,15 @@ 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);
121-
WS_DEBUG_PRINTLN("Published!");
119+
if (!WS.publish(WS._topic_signal_ds18_device, WS._buffer_outgoing, msgSz,
120+
1))
121+
{
122+
WS_DEBUG_PRINTLN("ERROR: Unable to publish DS18x20 init response message - check MQTT connection!");
123+
}
124+
else
125+
{
126+
WS_DEBUG_PRINTLN("Published! (Ds18x20 Init Response)");
127+
}
122128

123129
return is_success;
124130
}
@@ -294,7 +300,7 @@ void ws_ds18x20::update() {
294300
wippersnapper_signal_v1_Ds18x20Response_fields,
295301
&msgDS18x20Response);
296302
WS_DEBUG_PRINT("PUBLISHING -> msgDS18x20Response Event Message...");
297-
if (!WS._mqtt->publish(WS._topic_signal_ds18_device,
303+
if (!WS.publish(WS._topic_signal_ds18_device,
298304
WS._buffer_outgoing, msgSz, 1)) {
299305
WS_DEBUG_PRINTLN("ERROR: Unable to publish DS18x20 event message - "
300306
"MQTT Publish failed!");

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ bool WipperSnapper_Component_I2C::encodePublishI2CDeviceEventMsg(
910910
pb_get_encoded_size(&msgSz, wippersnapper_signal_v1_I2CResponse_fields,
911911
msgi2cResponse);
912912
WS_DEBUG_PRINT("PUBLISHING -> I2C Device Sensor Event Message...");
913-
if (!WS._mqtt->publish(WS._topic_signal_i2c_device, WS._buffer_outgoing,
913+
if (!WS.publish(WS._topic_signal_i2c_device, WS._buffer_outgoing,
914914
msgSz, 1)) {
915915
WS_DEBUG_PRINTLN("ERROR: MQTT Publish failed!");
916916
return false;

src/components/pixels/ws_pixels.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,16 @@ 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,
186-
1);
187-
WS_DEBUG_PRINTLN("Published!");
185+
if (!WS.publish(WS._topic_signal_pixels_device, WS._buffer_outgoing, msgSz,
186+
1))
187+
{
188+
WS_DEBUG_PRINTLN("ERROR: Unable to publish PixelsResponse message - "
189+
"check MQTT connection!");
190+
}
191+
else
192+
{
193+
WS_DEBUG_PRINTLN("Published! (PixelsResponse)");
194+
}
188195
}
189196

190197
/**************************************************************************/

0 commit comments

Comments
 (0)