Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pb error msgs #584

Merged
merged 55 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
7b0fdf5
Initial tweak to pb_encode
tyeth May 8, 2024
d8f99f9
Swap out pb_encode for i2c
tyeth May 8, 2024
f00e41e
WIP: decode added all untested
tyeth May 9, 2024
c89b4c3
CLang and Doxygen
tyeth May 9, 2024
64ba1fb
WIP: untested replace of all encodes
tyeth May 9, 2024
0908621
set lib_archive = no for samd
tyeth May 9, 2024
7393a97
remove static
tyeth May 10, 2024
17db34c
refactor header file
tyeth May 10, 2024
b8a42a4
Fix: Log if ping is successful or not
tyeth May 21, 2024
1f81fe2
Add logging if MQTT publishes fail
tyeth May 21, 2024
5a6931b
Clang tidy ping
tyeth May 21, 2024
fdb2ef2
Correct publish check for i2c
tyeth May 22, 2024
f17e5be
Fix: set ping logging to be one line
tyeth May 22, 2024
aeef7d1
Add reset before connect for AIRLIFT/WIFININA
tyeth May 29, 2024
5585061
Correct WIFININA reset pin name inline with Arduino Nano_33_iot/MkrWi…
tyeth May 29, 2024
9adaeb1
Add RSSI to network interfaces and log on join or ping
tyeth May 29, 2024
ed385b9
fix closing bracket on conditional + Clang format
tyeth May 29, 2024
eb5770e
clang-format _RSSI
tyeth May 29, 2024
d52a4c5
WIP: use SS/GPIO0 pins for reset too
tyeth May 30, 2024
36edeef
WIP: end wifi object before restart
tyeth May 30, 2024
291d50f
WIP: restart SPI after wifi end/deinit
tyeth May 30, 2024
3ad9bdc
WIP: end and begin SPIWIFI
tyeth May 30, 2024
4ec8fdd
Fix update RSSI call, triggering base class too
tyeth May 30, 2024
baa0bdb
clang format
tyeth May 30, 2024
532e488
Fix: runNetFSM if ping fails
tyeth May 30, 2024
5ef4b2a
Relabel PING to MQTT PING
tyeth Jun 14, 2024
72e746c
Remove unnecessary delay after setPins + extra vars
tyeth Jun 14, 2024
4686f23
Add reset method for ESP32 Airlift
tyeth Jun 14, 2024
c657cc6
Cleanup comments
tyeth Jun 14, 2024
4b3cdfa
Formatting
tyeth Jun 14, 2024
80b3cdf
Add WS_DELAY and RETRY_FUNCTION_UNTIL_TIMEOUT
tyeth Jun 14, 2024
9ee84b3
Swap AIRLIFT delays after wifi attempt to actually check status
tyeth Jun 14, 2024
1f78184
Revert WIFININA changes (reset code), leaving RSSI logging
tyeth Jun 14, 2024
0cd45cf
Swap Pico and AirLift to check status after wifi begin with macro
tyeth Jun 14, 2024
2f11a9e
Clang format
tyeth Jun 14, 2024
c4f3d0a
Correct return types for lambda conditionals
tyeth Jun 14, 2024
e16c2c4
clang format wippersnapper.h
tyeth Jun 14, 2024
97f6407
Swap RSSI to an accessor method instead of saving + format
tyeth Jun 14, 2024
8c338be
Remove debug print of Airlift reset pin value
tyeth Jul 1, 2024
ea35d73
Correct ws_pb_helpers includes + CompareVersion for Airlift FW + RSSI…
tyeth Jul 1, 2024
75b9aff
Swap line endings to avoid showing in diff + no secrets
tyeth Jul 2, 2024
cf850bb
Change to LN to avoid whitespace showing in diff
tyeth Jul 2, 2024
0a174a9
Correct initialisation of firmware variables in compareVersions
tyeth Jul 2, 2024
ac31ff9
Fix: calls to getRSSI unqualified inside Wippersnapper.cpp + only get…
tyeth Jul 3, 2024
2cee18a
Merge branch 'main' into pb-error-msgs
tyeth Jul 25, 2024
5bbbe40
RETRY_FUNCTION: Correct rollover check
tyeth Jul 25, 2024
4f79f7b
AirLift: define magic numbers for retry timings
tyeth Jul 25, 2024
0d959cd
AirLift: initialise placeholder firmware version
tyeth Jul 25, 2024
d0bb5c5
Define magic numbers for timeout/retry + print SSID in multi mode
tyeth Jul 25, 2024
7c35b54
Update staging certificates for testing
tyeth Jul 25, 2024
fa035f8
Pico: remove unnecessary c_str calls
tyeth Jul 25, 2024
19e634a
new ssl cert, NetWorkClient update
brentru Jul 24, 2024
2e77858
add wifi changes to pico, fix pio ini to avoid compile override
brentru Jul 25, 2024
ad3c019
Ignore Wifi101 on ESP32
tyeth Jul 25, 2024
4d1c204
Add WiFi101 to lib_ignore for ESP8266
tyeth Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ src/.vscode/settings.json

examples/Wippersnapper_demo/build/

#Platformio artifacts
# Platformio artifacts
.pio/

# Secrets
data/
49 changes: 40 additions & 9 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,22 @@ lib_deps =
; Common build environment for ESP32 platform
[common:esp32]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.03/platform-espressif32.zip
lib_ignore = WiFiNINA
lib_ignore = WiFiNINA, WiFi101
monitor_filters = esp32_exception_decoder, time

; Common build environment for ESP8266 platform
[common:esp8266]
platform = espressif8266
lib_ignore = WiFiNINA, Adafruit TinyUSB Library
lib_ignore = WiFiNINA, WiFi101, Adafruit TinyUSB Library

; Common build environment for Atmel/Microchip SAMDx platform
[common:atsamd]
platform = atmelsam
platform_packages =
platformio/framework-arduino-samd-adafruit@^1.7.13
platformio/tool-jlink@^1.78811.0
lib_ldf_mode = deep

lib_archive = no ; debug timer issues see https://community.platformio.org/t/choose-usb-stack-as-tiny-usb/22451/5

[common:rp2040]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
Expand All @@ -107,9 +110,12 @@ board_build.core = earlephilhower
board_build.filesystem_size = 0.5m
build_flags = -DUSE_TINYUSB
; Once https://github.com/platformio/platformio-core > 6.1.11 these can be removed
lib_ignore = WiFiNINA, Adafruit Zero DMA Library
lib_ignore = WiFiNINA, WiFi101, Adafruit Zero DMA Library
lib_compat_mode = soft ; can be strict once pio detects SleepyDog on RP2040


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Individual Board Definitions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; ESP32-x Boards ;

; Adafruit ESP32 Feather
Expand Down Expand Up @@ -292,14 +298,39 @@ build_flags = -DUSE_TINYUSB=1
[env:adafruit_pyportal_m4_titano]
extends = common:atsamd
board = adafruit_pyportal_m4_titano
; build_type = debug
build_type = debug
upload_protocol = sam-ba
; upload_protocol = jlink
; debug_tool = jlink
debug_tool = jlink
monitor_port = auto
; monitor_port = jlink
; debug_init_break =
; monitor_port = socket://localhost:19021
; debug_init_break = tbreak clearConfiguration
lib_ignore = USBHost
build_flags = -DUSE_TINYUSB=1
-DADAFRUIT_PYPORTAL_M4_TITANO
build_flags = -DUSE_TINYUSB
-D__SAMD51J20A__
-DCRYSTALLESS
-DADAFRUIT_PYPORTAL_M4_TITANO
-D__SAMD51__
-D__FPU_PRESENT
-DARM_MATH_CM4
-mfloat-abi=hard
-mfpu=fpv4-sp-d16
-DCORE_DEBUG_LEVEL=5
-DARDUINO_USB_CDC_ON_BOOT=1
-DCFG_TUSB_DEBUG=1
-DDEBUG=1
-DNDEBUG=1
-DUSE_AIRLIFT=1
-g
; -DUSBCON
; -UCDC_DISABLED
; -UPLUGGABLE_USB_DISABLED
; -DCDC_ENABLED
; -DPLUGGABLE_USB_ENABLED
; -DSERIAL_DEBUG=1
; -DSERIAL_PORT=Serial1
; -DSERCOM_INSTANCE_SERIAL=1

; Adafruit Metro M4 Airlift Lite
[env:adafruit_metro_m4_airliftlite]
Expand Down
212 changes: 127 additions & 85 deletions src/Wippersnapper.cpp

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions src/Wippersnapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,57 @@
{} ///< Prints line from debug output.
#endif

#define WS_DELAY_WITH_WDT(timeout) \
{ \
unsigned long start = millis(); \
while (millis() - start < timeout) { \
delay(10); \
yield(); \
feedWDT(); \
if (millis() < start) { \
start = millis(); /* if rollover */ \
} \
} \
} ///< Delay function

/**************************************************************************/
/*!
@brief Retry a function until a condition is met or a timeout is reached.
@param func
The function to retry.
@param result_type
The type of the result of the function.
@param result_var
The variable to store the last result of the function.
@param condition
The condition to check the result against.
@param timeout
The maximum time to retry the function.
@param interval
The time to wait between retries.
@param ...
The arguments to pass to the function.
*/
/**************************************************************************/
#define RETRY_FUNCTION_UNTIL_TIMEOUT(func, result_type, result_var, condition, \
tyeth marked this conversation as resolved.
Show resolved Hide resolved
timeout, interval, ...) \
{ \
unsigned long startTime = millis(); \
while (millis() - startTime < timeout) { \
result_type result_var = func(__VA_ARGS__); \
if (condition(result_var)) { \
break; \
} \
if (startTime > millis()) { \
startTime = millis(); /* if rollover */ \
} \
WS_DELAY_WITH_WDT(interval); \
} \
} ///< Retry a function until a condition is met or a timeout is reached.

// Wippersnapper pb helpers
#include <nanopb/ws_pb_helpers.h>

// Wippersnapper components
#include "components/analogIO/Wippersnapper_AnalogIO.h"
#include "components/digitalIO/Wippersnapper_DigitalGPIO.h"
Expand Down Expand Up @@ -220,6 +271,7 @@ class Wippersnapper {
void disconnect();

virtual void getMacAddr();
virtual int32_t getRSSI();
virtual void setupMQTTClient(const char *clientID);

virtual ws_status_t networkStatus();
Expand Down
4 changes: 2 additions & 2 deletions src/components/analogIO/Wippersnapper_AnalogIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ bool Wippersnapper_AnalogIO::encodePinEvent(
// Encode signal message
pb_ostream_t stream =
pb_ostream_from_buffer(WS._buffer_outgoing, sizeof(WS._buffer_outgoing));
if (!pb_encode(&stream, wippersnapper_signal_v1_CreateSignalRequest_fields,
&outgoingSignalMsg)) {
if (!ws_pb_encode(&stream, wippersnapper_signal_v1_CreateSignalRequest_fields,
&outgoingSignalMsg)) {
WS_DEBUG_PRINTLN("ERROR: Unable to encode signal message");
return false;
}
Expand Down
12 changes: 7 additions & 5 deletions src/components/ds18x20/ws_ds18x20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ bool ws_ds18x20::addDS18x20(
memset(WS._buffer_outgoing, 0, sizeof(WS._buffer_outgoing));
pb_ostream_t ostream =
pb_ostream_from_buffer(WS._buffer_outgoing, sizeof(WS._buffer_outgoing));
if (!pb_encode(&ostream, wippersnapper_signal_v1_Ds18x20Response_fields,
&msgInitResp)) {
if (!ws_pb_encode(&ostream, wippersnapper_signal_v1_Ds18x20Response_fields,
&msgInitResp)) {
WS_DEBUG_PRINTLN("ERROR: Unable to encode msg_init response message!");
return false;
}
Expand Down Expand Up @@ -257,9 +257,9 @@ void ws_ds18x20::update() {
memset(WS._buffer_outgoing, 0, sizeof(WS._buffer_outgoing));
pb_ostream_t ostream = pb_ostream_from_buffer(
WS._buffer_outgoing, sizeof(WS._buffer_outgoing));
if (!pb_encode(&ostream,
wippersnapper_signal_v1_Ds18x20Response_fields,
&msgDS18x20Response)) {
if (!ws_pb_encode(&ostream,
wippersnapper_signal_v1_Ds18x20Response_fields,
&msgDS18x20Response)) {
WS_DEBUG_PRINTLN(
"ERROR: Unable to encode DS18x20 event responsemessage!");
snprintf(buffer, 100,
Expand Down Expand Up @@ -296,6 +296,8 @@ void ws_ds18x20::update() {
WS_DEBUG_PRINT("PUBLISHING -> msgDS18x20Response Event Message...");
if (!WS._mqtt->publish(WS._topic_signal_ds18_device,
WS._buffer_outgoing, msgSz, 1)) {
WS_DEBUG_PRINTLN("ERROR: Unable to publish DS18x20 event message - "
"MQTT Publish failed!");
return;
};
WS_DEBUG_PRINTLN("PUBLISHED!");
Expand Down
5 changes: 3 additions & 2 deletions src/components/i2c/WipperSnapper_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,8 @@ bool WipperSnapper_Component_I2C::encodePublishI2CDeviceEventMsg(
memset(WS._buffer_outgoing, 0, sizeof(WS._buffer_outgoing));
pb_ostream_t ostream =
pb_ostream_from_buffer(WS._buffer_outgoing, sizeof(WS._buffer_outgoing));
if (!pb_encode(&ostream, wippersnapper_signal_v1_I2CResponse_fields,
msgi2cResponse)) {
if (!ws_pb_encode(&ostream, wippersnapper_signal_v1_I2CResponse_fields,
msgi2cResponse)) {
WS_DEBUG_PRINTLN(
"ERROR: Unable to encode I2C device event response message!");
return false;
Expand All @@ -873,6 +873,7 @@ bool WipperSnapper_Component_I2C::encodePublishI2CDeviceEventMsg(
WS_DEBUG_PRINT("PUBLISHING -> I2C Device Sensor Event Message...");
if (!WS._mqtt->publish(WS._topic_signal_i2c_device, WS._buffer_outgoing,
msgSz, 1)) {
WS_DEBUG_PRINTLN("ERROR: MQTT Publish failed!");
return false;
};
WS_DEBUG_PRINTLN("PUBLISHED!");
Expand Down
4 changes: 2 additions & 2 deletions src/components/pixels/ws_pixels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ void ws_pixels::publishAddStrandResponse(bool is_success,
memset(WS._buffer_outgoing, 0, sizeof(WS._buffer_outgoing));
pb_ostream_t ostream =
pb_ostream_from_buffer(WS._buffer_outgoing, sizeof(WS._buffer_outgoing));
if (!pb_encode(&ostream, wippersnapper_signal_v1_PixelsResponse_fields,
&msgInitResp)) {
if (!ws_pb_encode(&ostream, wippersnapper_signal_v1_PixelsResponse_fields,
&msgInitResp)) {
WS_DEBUG_PRINTLN("ERROR: Unable to encode "
"wippersnapper_signal_v1_PixelsResponse message!");
return;
Expand Down
11 changes: 6 additions & 5 deletions src/components/register/Wippersnapper_Register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool Wippersnapper::encodePubRegistrationReq() {
pb_ostream_t _msg_stream =
pb_ostream_from_buffer(_message_buffer, sizeof(_message_buffer));

_status = pb_encode(
_status = ws_pb_encode(
&_msg_stream,
wippersnapper_description_v1_CreateDescriptionRequest_fields, &_message);
size_t _message_len = _msg_stream.bytes_written;
Expand Down Expand Up @@ -107,9 +107,10 @@ void Wippersnapper::decodeRegistrationResp(char *data, uint16_t len) {
// create input stream for buffer
pb_istream_t stream = pb_istream_from_buffer(buffer, len);
// decode the stream
if (!pb_decode(&stream,
wippersnapper_description_v1_CreateDescriptionResponse_fields,
&message)) {
if (!ws_pb_decode(
&stream,
wippersnapper_description_v1_CreateDescriptionResponse_fields,
&message)) {
WS.haltError("Could not decode registration response");
}
// Decode registration response message
Expand Down Expand Up @@ -140,7 +141,7 @@ void Wippersnapper::decodeRegistrationResp(char *data, uint16_t len) {
pb_ostream_t _msg_stream =
pb_ostream_from_buffer(_message_buffer, sizeof(_message_buffer));

bool _status = pb_encode(
bool _status = ws_pb_encode(
&_msg_stream, wippersnapper_description_v1_RegistrationComplete_fields,
&msg);
size_t _message_len = _msg_stream.bytes_written;
Expand Down
4 changes: 2 additions & 2 deletions src/components/uart/drivers/ws_uart_drv_pm25aqi.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ class ws_uart_drv_pm25aqi : public ws_uart_drv {
uint8_t mqttBuffer[512] = {0};
pb_ostream_t ostream =
pb_ostream_from_buffer(mqttBuffer, sizeof(mqttBuffer));
if (!pb_encode(&ostream, wippersnapper_signal_v1_UARTResponse_fields,
&msgUARTResponse)) {
if (!ws_pb_encode(&ostream, wippersnapper_signal_v1_UARTResponse_fields,
&msgUARTResponse)) {
Serial.println("[ERROR, UART]: Unable to encode device response!");
return;
}
Expand Down
61 changes: 61 additions & 0 deletions src/nanopb/ws_pb_helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*!
* @file ws_pb_helpers.cpp
*
* Protobuf encode/decode helpers with error logging for Wippersnapper.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) Tyeth Gundry 2024 for Adafruit Industries.
*
* BSD license, all text here must be included in any redistribution.
*
*/

#include "ws_pb_helpers.h"
#include "../Wippersnapper.h"

// *****************************************************************************
/*!
@brief Decodes a protobuf message from a stream and prints any error.
@param stream
The stream to decode from.
@param fields
The protobuf message fields.
@param dest_struct
The destination struct to decode into.
@return True if decode was successful, false otherwise.
!*/
// *****************************************************************************
bool ws_pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields,
void *dest_struct) {
bool status = pb_decode(stream, fields, dest_struct);
if (!status) {
WS_DEBUG_PRINT("Protobuf decode error: ");
WS_DEBUG_PRINTLN(PB_GET_ERROR(stream));
}
return status;
}

// *****************************************************************************
/*!
@brief Encodes a protobuf message to a stream and prints any error.
@param stream
The stream to encode to.
@param fields
The protobuf message fields.
@param src_struct
The source struct to encode from.
@return True if encode was successful, false otherwise.
!*/
// *****************************************************************************
bool ws_pb_encode(pb_ostream_t *stream, const pb_msgdesc_t *fields,
const void *src_struct) {
bool status = pb_encode(stream, fields, src_struct);
if (!status) {
WS_DEBUG_PRINT("Protobuf encode error: ");
WS_DEBUG_PRINTLN(PB_GET_ERROR(stream));
}
return status;
}
28 changes: 28 additions & 0 deletions src/nanopb/ws_pb_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*!
* @file ws_pb_helpers.h
*
* Protobuf encode/decode helpers with error logging for Wippersnapper.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) Tyeth Gundry 2024 for Adafruit Industries.
*
* BSD license, all text here must be included in any redistribution.
*
*/
#ifndef WS_PB_ENCODE_H
#define WS_PB_ENCODE_H

#include "pb.h"
tyeth marked this conversation as resolved.
Show resolved Hide resolved
#include "pb_decode.h"
#include "pb_encode.h"

bool ws_pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields,
void *dest_struct);

bool ws_pb_encode(pb_ostream_t *stream, const pb_msgdesc_t *fields,
const void *src_struct);

#endif // WS_PB_ENCODE_H
Loading
Loading