🚧 SD - parsing to dispatch working for one component only

This commit is contained in:
brentru 2024-11-05 11:54:58 -05:00
parent 1aeee684df
commit ad574e23c6
7 changed files with 131 additions and 10 deletions

View file

@ -78,7 +78,7 @@ lib_deps =
https://github.com/Sensirion/arduino-i2c-sen5x.git https://github.com/Sensirion/arduino-i2c-sen5x.git
https://github.com/adafruit/WiFiNINA.git https://github.com/adafruit/WiFiNINA.git
https://github.com/Starmbi/hp_BH1750.git https://github.com/Starmbi/hp_BH1750.git
https://github.com/adafruit/RTClib.git
; Common build environment for ESP32 platform ; Common build environment for ESP32 platform
[common:esp32] [common:esp32]

View file

@ -434,6 +434,28 @@ void cbBrokerToDevice(char *data, uint16_t len) {
WS_DEBUG_PRINTLN("Decoded BrokerToDevice message!"); WS_DEBUG_PRINTLN("Decoded BrokerToDevice message!");
} }
void callDecodeB2D() {
WS_DEBUG_PRINTLN("\n[App] Parsing new Signal->B2D Message");
wippersnapper_signal_BrokerToDevice msg_signal =
wippersnapper_signal_BrokerToDevice_init_default;
// Configure the payload callback
msg_signal.cb_payload.funcs.decode = cbDecodeBrokerToDevice;
// Decode msg_signal
WS_DEBUG_PRINTLN("Creating input stream...");
pb_istream_t istream =
pb_istream_from_buffer(WsV2._msgBuf, WsV2._szMessageBuf);
WS_DEBUG_PRINTLN("Decoding BrokerToDevice message...");
if (!pb_decode(&istream, wippersnapper_signal_BrokerToDevice_fields,
&msg_signal)) {
WS_DEBUG_PRINTLN("ERROR: Unable to decode BrokerToDevice message!");
return;
}
WS_DEBUG_PRINTLN("Decoded BrokerToDevice message!");
}
/**************************************************************************/ /**************************************************************************/
/*! /*!
@brief Called when client receives a message published across the @brief Called when client receives a message published across the
@ -1170,7 +1192,8 @@ void Wippersnapper_V2::connectV2() {
// Parse the JSON file // Parse the JSON file
if (!WsV2._sdCardV2->parseConfigFile()) if (!WsV2._sdCardV2->parseConfigFile())
haltErrorV2("Failed to parse incoming JSON file"); haltErrorV2("Failed to parse incoming JSON file");
// TODO: Configure the device using the incoming JSON file WS_DEBUG_PRINT("[Offline] Attempting to configure hardware...");
callDecodeB2D(); // TODO: We need a way to repeat this call better
WS_DEBUG_PRINTLN( WS_DEBUG_PRINTLN(
"[Offline Mode] Hardware configured, skipping network setup..."); "[Offline Mode] Hardware configured, skipping network setup...");
return; return;

View file

@ -254,6 +254,12 @@ public:
#endif #endif
bool got_checkin_response; ///< True if a checkin response was received, False bool got_checkin_response; ///< True if a checkin response was received, False
///< otherwise. ///< otherwise.
wippersnapper_signal_BrokerToDevice _signalB2dV2;
pb_ostream_t _signalStream;
size_t _szMessageBuf;
uint8_t _msgBuf[512];
private: private:
void _initV2(); void _initV2();

View file

@ -0,0 +1,38 @@
# 1 "/var/folders/ff/dmzflvf52tq9kzvt6g8jglxw0000gn/T/tmpurmcpxg_"
#include <Arduino.h>
# 1 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo_wokwi.ino"
# 14 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo_wokwi.ino"
#define IO_USERNAME "brubell"
#define IO_KEY "YOUR_AIO_KEY"
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASS ""
#define WS_DEBUG
#define API_PIN 0
#include "ws_manager.h"
Wippersnapper_Manager manager;
Wippersnapper_WiFiV2 wipper(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, "io.adafruit.com", 8883);
void setup();
void loop();
#line 31 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo_wokwi.ino"
void setup() {
manager.checkAPIVersion(API_PIN);
manager.provision();
Serial.begin(115200);
Serial.println("Adafruit Wippersnapper API Manager Demo");
Serial.print("Running Wippersnapper API Version: ");
Serial.println(manager.getAPIVersion());
manager.connect();
}
void loop() {
manager.run();
}

View file

@ -90,6 +90,16 @@ bool AnalogIOController::Handle_AnalogIOAdd(pb_istream_t *stream) {
// Initialize the pin // Initialize the pin
_analogio_hardware->InitPin(pin_name); _analogio_hardware->InitPin(pin_name);
// Print out the pin's details
WS_DEBUG_PRINTLN("Added new analog pin:");
WS_DEBUG_PRINT("Pin Name: ");
WS_DEBUG_PRINTLN(new_pin.name);
WS_DEBUG_PRINT("Period: ");
WS_DEBUG_PRINTLN(new_pin.period);
WS_DEBUG_PRINT("Read Mode: ");
WS_DEBUG_PRINTLN(new_pin.read_mode);
// Add the new pin to the vector // Add the new pin to the vector
_analogio_pins.push_back(new_pin); _analogio_pins.push_back(new_pin);

View file

@ -100,10 +100,12 @@ bool ws_sdcard::parseConfigFile() {
components["componentAPI"]; // ie: "analogio", "digitalio", etc. components["componentAPI"]; // ie: "analogio", "digitalio", etc.
if (component_api_type == nullptr) { if (component_api_type == nullptr) {
WS_DEBUG_PRINTLN("[SD] FATAL Parsing error - No component API type found in JSON string!"); WS_DEBUG_PRINTLN("[SD] FATAL Parsing error - No component API type found "
"in JSON string!");
return false; return false;
} else { } else {
WS_DEBUG_PRINTLN("[SD] Component API type found: " + String(component_api_type)); WS_DEBUG_PRINTLN("[SD] Component API type found: " +
String(component_api_type));
} }
// TODO- maybe a Switch case to handle the different component API types but // TODO- maybe a Switch case to handle the different component API types but
@ -186,6 +188,41 @@ bool ws_sdcard::parseConfigFile() {
WS_DEBUG_PRINTLN("Pin Name: " + String(msg_AnalogIOAdd.pin_name)); WS_DEBUG_PRINTLN("Pin Name: " + String(msg_AnalogIOAdd.pin_name));
WS_DEBUG_PRINTLN("Period: " + String(msg_AnalogIOAdd.period)); WS_DEBUG_PRINTLN("Period: " + String(msg_AnalogIOAdd.period));
WS_DEBUG_PRINTLN("Read Mode: " + String(msg_AnalogIOAdd.read_mode)); WS_DEBUG_PRINTLN("Read Mode: " + String(msg_AnalogIOAdd.read_mode));
// TODO: Note that the TOP-LEVEL decoder is actually looking
// for a SIGNAL message with one of these SUBMESSAGEd
// so we'll need to encode this into a signalproto form before sending
// it over
// Zero-out the signal message
// TODO: This should be global
WsV2._signalB2dV2 = wippersnapper_signal_BrokerToDevice_init_zero;
//. Fill the signal message with msg_AnalogIOAdd data
WsV2._signalB2dV2.which_payload =
wippersnapper_signal_BrokerToDevice_analogio_add_tag;
WsV2._signalB2dV2.payload.analogio_add = msg_AnalogIOAdd;
// Get the encoded size of the signal message
WS_DEBUG_PRINTLN("Encoding D2b signal message...");
// size_t szMessageBuf;
if (!pb_get_encoded_size(&WsV2._szMessageBuf,
wippersnapper_signal_BrokerToDevice_fields,
&WsV2._signalB2dV2)) {
WS_DEBUG_PRINTLN("[SD] ERROR: Unable to get signal message size!");
return false;
}
// Encode the signal message
// uint8_t msgBuf[szMessageBuf];
WsV2._signalStream =
pb_ostream_from_buffer(WsV2._msgBuf, WsV2._szMessageBuf);
if (!ws_pb_encode(&WsV2._signalStream,
wippersnapper_signal_BrokerToDevice_fields,
&WsV2._signalB2dV2)) {
WS_DEBUG_PRINTLN("[SD] ERROR: Unable to encode D2B signal message!");
return false;
}
WS_DEBUG_PRINTLN("Encoded the D2b signal message");
} else { } else {
// Unknown component API type // Unknown component API type
WS_DEBUG_PRINTLN("[SD] Unknown component API type found: " + WS_DEBUG_PRINTLN("[SD] Unknown component API type found: " +
@ -193,11 +230,6 @@ bool ws_sdcard::parseConfigFile() {
return false; return false;
} }
// TODO: Note that the TOP-LEVEL decoder is actually looking
// for a SIGNAL message with one of these SUBMESSAGEd
// so we'll need to encode this into a signalproto form before sending
// it over
return true; return true;
} }

View file

@ -11,6 +11,14 @@
"left": -290.93, "left": -290.93,
"rotate": 90, "rotate": 90,
"attrs": {} "attrs": {}
},
{
"type": "wokwi-ds1307",
"id": "rtc1",
"top": -129.5,
"left": -204.4,
"rotate": 270,
"attrs": {}
} }
], ],
"connections": [ "connections": [
@ -21,7 +29,11 @@
[ "sd1:CS", "esp:D15", "#8f4814", [ "v0" ] ], [ "sd1:CS", "esp:D15", "#8f4814", [ "v0" ] ],
[ "sd1:DI", "esp:D23", "blue", [ "v0" ] ], [ "sd1:DI", "esp:D23", "blue", [ "v0" ] ],
[ "sd1:SCK", "esp:D18", "green", [ "v0" ] ], [ "sd1:SCK", "esp:D18", "green", [ "v0" ] ],
[ "sd1:DO", "esp:D19", "orange", [ "v0" ] ] [ "sd1:DO", "esp:D19", "orange", [ "v0" ] ],
[ "rtc1:5V", "esp:VIN", "red", [ "v163.2", "h-230.8" ] ],
[ "rtc1:GND", "esp:GND.1", "black", [ "v76.8", "h-124.5" ] ],
[ "rtc1:SDA", "esp:D21", "violet", [ "v57.6", "h-144" ] ],
[ "rtc1:SCL", "esp:D22", "green", [ "v28.8", "h-153.5" ] ]
], ],
"serialMonitor": { "display": "terminal", "newline": "lf" }, "serialMonitor": { "display": "terminal", "newline": "lf" },
"dependencies": {} "dependencies": {}