Initial Commit - Hooks for MQTT topics and decoders
This commit is contained in:
parent
114aa7aa7b
commit
b784f3ffe3
5 changed files with 123 additions and 5 deletions
|
|
@ -1,5 +1,5 @@
|
|||
name=Adafruit WipperSnapper
|
||||
version=1.0.0-beta.110
|
||||
version=1.0.0-beta.111
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <adafruitio@adafruit.com>
|
||||
sentence=Arduino application for Adafruit.io WipperSnapper
|
||||
|
|
@ -7,4 +7,4 @@ paragraph=Arduino application for Adafruit.io WipperSnapper
|
|||
category=Communication
|
||||
url=https://github.com/adafruit/Adafruit_Wippersnapper_Arduino
|
||||
architectures=*
|
||||
depends=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306
|
||||
depends=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306, Adafruit EPD
|
||||
|
|
|
|||
|
|
@ -90,9 +90,9 @@ lib_deps =
|
|||
https://github.com/tyeth/omron-devhub_d6t-arduino.git
|
||||
https://github.com/pstolarz/OneWireNg.git
|
||||
; COMMENT OUT FOR RP2040/RP2350 BOARDS
|
||||
https://github.com/milesburton/Arduino-Temperature-Control-Library.git
|
||||
;https://github.com/milesburton/Arduino-Temperature-Control-Library.git
|
||||
; AND UNCOMMENT FOR RP2040/RP2350 BOARDS
|
||||
; https://github.com/pstolarz/Arduino-Temperature-Control-Library.git
|
||||
https://github.com/pstolarz/Arduino-Temperature-Control-Library.git
|
||||
https://github.com/Sensirion/arduino-sht.git
|
||||
https://github.com/Sensirion/arduino-i2c-scd4x.git
|
||||
https://github.com/Sensirion/arduino-i2c-sen5x.git
|
||||
|
|
@ -100,6 +100,7 @@ lib_deps =
|
|||
https://github.com/adafruit/WiFiNINA.git
|
||||
https://github.com/Starmbi/hp_BH1750.git
|
||||
https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git
|
||||
Adafruit EPD
|
||||
|
||||
|
||||
|
||||
|
|
@ -265,7 +266,7 @@ extends = common:esp32
|
|||
board = adafruit_magtag29_esp32s2
|
||||
build_flags = -DARDUINO_MAGTAG29_ESP32S2 -DBOARD_HAS_PSRAM
|
||||
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
|
||||
board_build.partitions = tinyuf2-partitions-4MB.csv
|
||||
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
|
||||
extra_scripts = pre:rename_usb_config.py
|
||||
|
||||
; Adafruit Metro ESP32-S2
|
||||
|
|
|
|||
|
|
@ -1655,6 +1655,37 @@ void cbSignalUARTReq(char *data, uint16_t len) {
|
|||
WS_DEBUG_PRINTLN("ERROR: Unable to decode UART Signal message");
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Called when the device receives a new message from the
|
||||
/display/ topic.
|
||||
@param data
|
||||
Incoming data from MQTT broker.
|
||||
@param len
|
||||
Length of incoming data.
|
||||
*/
|
||||
void cbDisplayMessage(char *data, uint16_t len) {
|
||||
WS_DEBUG_PRINTLN("* NEW MESSAGE [Topic: Display]: ");
|
||||
WS_DEBUG_PRINT(len);
|
||||
WS_DEBUG_PRINTLN(" bytes.");
|
||||
// zero-out current buffer
|
||||
memset(WS._buffer, 0, sizeof(WS._buffer));
|
||||
// copy mqtt data into buffer
|
||||
memcpy(WS._buffer, data, len);
|
||||
WS.bufSize = len;
|
||||
|
||||
// Set up the payload callback, which will set up the callbacks for
|
||||
// each oneof payload field once the field tag is known
|
||||
// TODO:
|
||||
// WS.msgPixels.cb_payload.funcs.decode = cbDecodePixelsMsg;
|
||||
|
||||
// Decode pixel message from buffer
|
||||
pb_istream_t istream = pb_istream_from_buffer(WS._buffer, WS.bufSize);
|
||||
// TODO: Change fields and message type here
|
||||
if (!ws_pb_decode(&istream, wippersnapper_signal_v1_PixelsRequest_fields,
|
||||
&WS.msgPixels))
|
||||
WS_DEBUG_PRINTLN("ERROR: Unable to decode display message");
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/*!
|
||||
@brief Handles MQTT messages on signal topic until timeout.
|
||||
|
|
@ -2344,6 +2375,61 @@ bool Wippersnapper::generateWSTopics() {
|
|||
WS_DEBUG_PRINTLN("FATAL ERROR: Failed to allocate memory for UART topic!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create d2b display topic
|
||||
#ifdef USE_PSRAM
|
||||
WS._topic_signal_display_brkr = (char *)ps_malloc(
|
||||
sizeof(char) * strlen(WS._config.aio_user) + strlen("/") +
|
||||
strlen(_device_uid) + strlen("/wprsnpr/") + strlen(TOPIC_SIGNALS) +
|
||||
strlen("broker") + strlen(TOPIC_DISPLAY) + 1);
|
||||
#else
|
||||
WS._topic_signal_display_brkr = (char *)malloc(
|
||||
sizeof(char) * strlen(WS._config.aio_user) + strlen("/") +
|
||||
strlen(_device_uid) + strlen("/wprsnpr/") + strlen(TOPIC_SIGNALS) +
|
||||
strlen("broker") + strlen(TOPIC_DISPLAY) + 1);
|
||||
#endif
|
||||
if (WS._topic_signal_display_brkr != NULL) {
|
||||
strcpy(WS._topic_signal_display_brkr, WS._config.aio_user);
|
||||
strcat(WS._topic_signal_display_brkr, TOPIC_WS);
|
||||
strcat(WS._topic_signal_display_brkr, _device_uid);
|
||||
strcat(WS._topic_signal_display_brkr, TOPIC_SIGNALS);
|
||||
strcat(WS._topic_signal_display_brkr, "broker");
|
||||
strcat(WS._topic_signal_display_brkr, TOPIC_DISPLAY);
|
||||
} else { // malloc failed
|
||||
WS_DEBUG_PRINTLN("ERROR: Failed to add a display topic!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Subscribe to the display sub-topic
|
||||
_topic_signal_display_sub =
|
||||
new Adafruit_MQTT_Subscribe(WS._mqtt, WS._topic_signal_display_brkr, 1);
|
||||
WS._mqtt->subscribe(_topic_signal_display_sub);
|
||||
_topic_signal_display_sub->setCallback(cbDisplayMessage);
|
||||
|
||||
// Create a b2d display topic
|
||||
#ifdef USE_PSRAM
|
||||
WS._topic_signal_display_device = (char *)ps_malloc(
|
||||
sizeof(char) * strlen(WS._config.aio_user) + strlen("/") +
|
||||
strlen(_device_uid) + strlen("/wprsnpr/") + strlen(TOPIC_SIGNALS) +
|
||||
strlen("device") + strlen(TOPIC_DISPLAY) + 1);
|
||||
#else
|
||||
WS._topic_signal_display_device = (char *)malloc(
|
||||
sizeof(char) * strlen(WS._config.aio_user) + strlen("/") +
|
||||
strlen(_device_uid) + strlen("/wprsnpr/") + strlen(TOPIC_SIGNALS) +
|
||||
strlen("device") + strlen(TOPIC_DISPLAY) + 1);
|
||||
#endif
|
||||
if (WS._topic_signal_display_device != NULL) {
|
||||
strcpy(WS._topic_signal_display_device, WS._config.aio_user);
|
||||
strcat(WS._topic_signal_display_device, TOPIC_WS);
|
||||
strcat(WS._topic_signal_display_device, _device_uid);
|
||||
strcat(WS._topic_signal_display_device, TOPIC_SIGNALS);
|
||||
strcat(WS._topic_signal_display_device, "device");
|
||||
strcat(WS._topic_signal_display_device, TOPIC_DISPLAY);
|
||||
} else { // malloc failed
|
||||
WS_DEBUG_PRINTLN("ERROR: Failed to add a display topic!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -153,6 +153,7 @@
|
|||
#define TOPIC_INFO "/info/" ///< Registration sub-topic
|
||||
#define TOPIC_SIGNALS "/signals/" ///< Signals sub-topic
|
||||
#define TOPIC_I2C "/i2c" ///< I2C sub-topic
|
||||
#define TOPIC_DISPLAY "/display" ///< Display sub-topic (EPD, OLED, TFT, etc.)
|
||||
#define MQTT_TOPIC_PIXELS_DEVICE \
|
||||
"/signals/device/pixel" ///< Pixels device->broker topic
|
||||
#define MQTT_TOPIC_PIXELS_BROKER \
|
||||
|
|
@ -404,6 +405,8 @@ public:
|
|||
char *_topic_signal_pixels_device = NULL; /*!< Topic carries pixel messages */
|
||||
char *_topic_signal_uart_brkr = NULL; /*!< Topic carries UART messages */
|
||||
char *_topic_signal_uart_device = NULL; /*!< Topic carries UART messages */
|
||||
char *_topic_signal_display_brkr = NULL; /*!< Topic carries messages from a device to a broker. */
|
||||
char *_topic_signal_display_device = NULL; /*!< Topic carries messages from a broker to a device. */
|
||||
|
||||
wippersnapper_signal_v1_CreateSignalRequest
|
||||
_incomingSignalMsg; /*!< Incoming signal message from broker */
|
||||
|
|
@ -490,6 +493,8 @@ protected:
|
|||
*_topic_signal_pixels_sub; /*!< Subscribes to pixel device topic. */
|
||||
Adafruit_MQTT_Subscribe
|
||||
*_topic_signal_uart_sub; /*!< Subscribes to signal's UART topic. */
|
||||
Adafruit_MQTT_Subscribe
|
||||
*_topic_signal_display_sub; /*!< Subscription callback for display topic. */
|
||||
|
||||
Adafruit_MQTT_Subscribe
|
||||
*_err_sub; /*!< Subscription to Adafruit IO Error topic. */
|
||||
|
|
|
|||
26
src/Wippersnapper_demo.ino.cpp
Normal file
26
src/Wippersnapper_demo.ino.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# 1 "/var/folders/ff/dmzflvf52tq9kzvt6g8jglxw0000gn/T/tmpvcrl51_o"
|
||||
#include <Arduino.h>
|
||||
# 1 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo.ino"
|
||||
# 16 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo.ino"
|
||||
#include "Wippersnapper_Networking.h"
|
||||
Wippersnapper_WiFi wipper;
|
||||
|
||||
|
||||
#define WS_DEBUG
|
||||
void setup();
|
||||
void loop();
|
||||
#line 22 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo.ino"
|
||||
void setup() {
|
||||
|
||||
wipper.provision();
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
|
||||
wipper.connect();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
wipper.run();
|
||||
}
|
||||
Loading…
Reference in a new issue