Skip to content

Commit ea2b44a

Browse files
committed
WIP: logging around connected/publish
1 parent e5d21ba commit ea2b44a

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

src/Wippersnapper.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,7 +2364,7 @@ void Wippersnapper::runNetFSM() {
23642364
while (fsmNetwork != FSM_NET_CONNECTED) {
23652365
switch (fsmNetwork) {
23662366
case FSM_NET_CHECK_MQTT:
2367-
if (WS._mqtt->connected()) {
2367+
if (WS._mqtt->connected() && networkStatus() == WS_NET_CONNECTED) {
23682368
// WS_DEBUG_PRINTLN("Connected to Adafruit IO!");
23692369
fsmNetwork = FSM_NET_CONNECTED;
23702370
return;
@@ -2659,18 +2659,26 @@ bool Wippersnapper::publish(const char *topic, uint8_t *payload, uint16_t bLen,
26592659
// method when caused with WS object in another file.
26602660
WS.feedWDT();
26612661
if (!WS._mqtt->publish(topic, payload, bLen, qos)) {
2662-
if (WS._mqtt->connected()) {
2662+
WS_DEBUG_PRINTLN("FAILED!");
2663+
WS_DEBUG_PRINT("Mqtt connected: ");
2664+
WS_DEBUG_PRINTLN(WS._mqtt->connected());
2665+
WS_DEBUG_PRINT("Network status: ");
2666+
WS_DEBUG_PRINTLN(networkStatus());
2667+
if (WS._mqtt->connected() && networkStatus() == WS_NET_CONNECTED) {
26632668
WS_DEBUG_PRINTLN("Failed to publish MQTT message, retrying!");
26642669
} else {
2665-
WS_DEBUG_PRINTLN("MQTT Disconnected! Running network FSM then publish...");
2670+
WS_DEBUG_PRINTLN("MQTT connection broken! Running network FSM then publish...");
26662671
WS._mqtt->disconnect();
2672+
WS_DEBUG_PRINTLN("MQTT forcibly disconnected. Running Network FSM...");
26672673
runNetFSM();
26682674
}
26692675
WS.feedWDT();
2676+
WS_DEBUG_PRINTLN("Retrying publish...");
26702677
if (!WS._mqtt->publish(topic, payload, bLen, qos)) {
26712678
WS_DEBUG_PRINTLN("Failed to publish MQTT message!");
26722679
return false;
26732680
}
2681+
WS_DEBUG_PRINTLN("MQTT message published successfully!");
26742682
}
26752683
return true;
26762684
}

src/nanopb/ws_pb_helpers.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,27 @@
3030
// *****************************************************************************
3131
bool ws_pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields,
3232
void *dest_struct) {
33+
if(!stream || !fields || !dest_struct) {
34+
WS_DEBUG_PRINTLN("Protobuf decode error: Invalid arguments to function");
35+
if (!stream) {
36+
WS_DEBUG_PRINTLN("stream is NULL");
37+
} else if (stream == nullptr) {
38+
WS_DEBUG_PRINTLN("stream is nullptr");
39+
}
40+
41+
if (!fields) {
42+
WS_DEBUG_PRINTLN("fields is NULL");
43+
} else if (fields == nullptr) {
44+
WS_DEBUG_PRINTLN("fields is nullptr");
45+
}
46+
47+
if (!dest_struct) {
48+
WS_DEBUG_PRINTLN("dest_struct is NULL");
49+
} else if (dest_struct == nullptr) {
50+
WS_DEBUG_PRINTLN("dest_struct is nullptr");
51+
}
52+
return false;
53+
}
3354
bool status = pb_decode(stream, fields, dest_struct);
3455
if (!status) {
3556
WS_DEBUG_PRINT("Protobuf decode error: ");
@@ -52,6 +73,27 @@ bool ws_pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields,
5273
// *****************************************************************************
5374
bool ws_pb_encode(pb_ostream_t *stream, const pb_msgdesc_t *fields,
5475
const void *src_struct) {
76+
if(!stream || !fields || !src_struct) {
77+
WS_DEBUG_PRINTLN("Protobuf encode error: Invalid arguments to function");
78+
if (!stream) {
79+
WS_DEBUG_PRINTLN("stream is NULL");
80+
} else if (stream == nullptr) {
81+
WS_DEBUG_PRINTLN("stream is nullptr");
82+
}
83+
84+
if (!fields) {
85+
WS_DEBUG_PRINTLN("fields is NULL");
86+
} else if (fields == nullptr) {
87+
WS_DEBUG_PRINTLN("fields is nullptr");
88+
}
89+
90+
if (!src_struct) {
91+
WS_DEBUG_PRINTLN("src_struct is NULL");
92+
} else if (src_struct == nullptr) {
93+
WS_DEBUG_PRINTLN("src_struct is nullptr");
94+
}
95+
return false;
96+
}
5597
bool status = pb_encode(stream, fields, src_struct);
5698
if (!status) {
5799
WS_DEBUG_PRINT("Protobuf encode error: ");

0 commit comments

Comments
 (0)