Adafruit Library
|
Class that provides storage and functions for the Adafruit IO Wippersnapper interface. More...
#include <Wippersnapper.h>
Public Member Functions | |
virtual | ~Wippersnapper () |
Wippersnapper destructor. | |
void | provision () |
Provisions a WipperSnapper device with its network configuration and Adafruit IO credentials. | |
virtual void | set_user_key () |
Configures the device's Adafruit IO credentials. This method should be used only if filesystem-backed provisioning is not avaliable. | |
virtual void | set_ssid_pass (const char *ssid, const char *ssidPassword) |
Sets the device's wireless network credentials. More... | |
virtual void | set_ssid_pass () |
Sets the device's wireless network credentials from the secrets.json configuration file. | |
virtual bool | check_valid_ssid () |
Performs a scan of local WiFi networks. More... | |
virtual void | _connect () |
Connects to wireless network. | |
virtual void | _disconnect () |
Disconnect Wippersnapper MQTT session and network. | |
void | connect () |
Connects to Adafruit IO+ Wippersnapper broker. | |
void | disconnect () |
Disconnects from Adafruit IO+ Wippersnapper. | |
virtual void | getMacAddr () |
Sets the network interface's unique identifer, typically the MAC address. | |
virtual int32_t | getRSSI () |
Gets the network's RSSI. More... | |
virtual void | setupMQTTClient (const char *clientID) |
Sets up the MQTT client session. More... | |
virtual ws_status_t | networkStatus () |
Returns the network's connection status. More... | |
ws_board_status_t | getBoardStatus () |
Returns the board definition status. More... | |
bool | generateDeviceUID () |
Attempts to generate unique device identifier. More... | |
bool | generateWSTopics () |
Generates device-specific Wippersnapper control topics and subscribes to them. More... | |
bool | generateWSErrorTopics () |
Builds MQTT topics for handling errors returned from the Adafruit IO broker and subscribes to them. More... | |
bool | registerBoard () |
Attempts to register hardware with Adafruit.io WipperSnapper. More... | |
bool | encodePubRegistrationReq () |
Encodes hardware registration request message and publishes the message to the Adafruit IO broker. More... | |
void | decodeRegistrationResp (char *data, uint16_t len) |
Decodes hardware registration response message from the Adafruit IO MQTT broker and initializes hardware components. More... | |
void | pollRegistrationResp () |
Polls the broker for the hardware registration response message. More... | |
void | publishPinConfigComplete () |
Publishes an ACK to the broker that the device has completed its hardware configuration. | |
ws_status_t | run () |
Processes incoming commands and handles network connection. More... | |
void | processPackets () |
Process all incoming packets from the Adafruit IO MQTT broker. Handles network connectivity. | |
void | publish (const char *topic, uint8_t *payload, uint16_t bLen, uint8_t qos=0) |
Publishes a message to the Adafruit IO MQTT broker. Handles network connectivity. More... | |
void | pingBroker () |
Pings the MQTT broker within the keepalive interval to keep the connection alive. Blinks the keepalive LED every STATUS_LED_KAT_BLINK_TIME milliseconds. | |
void | runNetFSM () |
Checks network and MQTT connectivity. Handles network re-connection and mqtt re-establishment. | |
void | enableWDT (int timeoutMS=0) |
Enables the watchdog timer. More... | |
void | feedWDT () |
Feeds the WDT to prevent hardware reset. | |
void | haltError (String error, ws_led_status_t ledStatusColor=WS_LED_STATUS_ERROR_RUNTIME, uint8_t seconds_until_reboot=25) |
Prints an error to the serial and halts the hardware until the WDT bites. More... | |
void | errorWriteHang (String error) |
Writes an error message to the serial and the filesystem, blinks WS_LED_STATUS_ERROR_RUNTIME pattern and hangs. More... | |
bool | decodeSignalMsg (wippersnapper_signal_v1_CreateSignalRequest *encodedSignalMsg) |
Decodes a signal buffer protobuf message. NOTE: Should be executed in-order after a new _buffer is recieved. More... | |
bool | encodePinEvent (wippersnapper_signal_v1_CreateSignalRequest *outgoingSignalMsg, uint8_t pinName, int pinVal) |
Handles MQTT messages on signal topic until timeout. More... | |
bool | configureDigitalPinReq (wippersnapper_pin_v1_ConfigurePinRequest *pinMsg) |
Configures a pin according to a wippersnapper_pin_v1_ConfigurePinRequest message. More... | |
bool | configAnalogInPinReq (wippersnapper_pin_v1_ConfigurePinRequest *pinMsg) |
Configures an analog input pin according to a wippersnapper_pin_v1_ConfigurePinRequest message. More... | |
Public Attributes | |
bool | lockStatusNeoPixel |
True if status LED is using the status neopixel. | |
bool | lockStatusDotStar |
True if status LED is using the status dotstar. | |
bool | lockStatusLED |
True if status LED is using the built-in LED. | |
float | status_pixel_brightness |
std::vector< WipperSnapper_Component_I2C * > | i2cComponents |
Vector containing all I2C components. | |
WipperSnapper_Component_I2C * | _i2cPort0 |
WipperSnapper I2C Component for I2C port #0. More... | |
WipperSnapper_Component_I2C * | _i2cPort1 |
WipperSnapper I2C Component for I2C port #1. More... | |
bool | _isI2CPort0Init |
True if I2C port 0 has been initialized, False otherwise. More... | |
bool | _isI2CPort1Init |
True if I2C port 1 has been initialized, False otherwise. More... | |
uint8_t | _buffer [WS_MQTT_MAX_PAYLOAD_SIZE] |
uint8_t | _buffer_outgoing [WS_MQTT_MAX_PAYLOAD_SIZE] |
uint16_t | bufSize |
ws_board_status_t | _boardStatus |
Hardware's registration status. More... | |
Wippersnapper_DigitalGPIO * | _digitalGPIO |
Instance of digital gpio class. | |
Wippersnapper_AnalogIO * | _analogIO |
Instance of analog io class. | |
Wippersnapper_FS * | _fileSystem |
Instance of Filesystem (native USB) | |
WipperSnapper_LittleFS * | _littleFS |
Instance of LittleFS Filesystem (non-native USB) | |
ws_display_driver * | _display = nullptr |
Instance of display driver class. | |
ws_display_ui_helper * | _ui_helper |
Instance of display UI helper class. More... | |
ws_pixels * | _ws_pixelsComponent |
ptr to instance of ws_pixels class | |
ws_pwm * | _pwmComponent |
Instance of pwm class. | |
ws_servo * | _servoComponent |
Instance of servo class. | |
ws_ds18x20 * | _ds18x20Component |
Instance of DS18x20 class. | |
ws_uart * | _uartComponent |
Instance of UART class. | |
uint8_t | _macAddr [6] |
char | sUID [13] |
const char * | _boardId |
Adafruit_MQTT * | _mqtt |
secretsConfig | _config |
networkConfig | _multiNetworks [3] |
bool | _isWiFiMulti = false |
int32_t | totalDigitalPins |
char * | _topic_description = NULL |
char * | _topic_signal_device = NULL |
char * | _topic_signal_i2c_brkr = NULL |
char * | _topic_signal_i2c_device = NULL |
char * | _topic_signal_servo_brkr = NULL |
char * | _topic_signal_servo_device = NULL |
char * | _topic_signal_pwm_brkr |
char * | _topic_signal_pwm_device |
char * | _topic_signal_ds18_brkr = NULL |
char * | _topic_signal_ds18_device = NULL |
char * | _topic_signal_pixels_brkr = NULL |
char * | _topic_signal_pixels_device = NULL |
char * | _topic_signal_uart_brkr = NULL |
char * | _topic_signal_uart_device = NULL |
wippersnapper_signal_v1_CreateSignalRequest | _incomingSignalMsg |
wippersnapper_signal_v1_I2CRequest | msgSignalI2C |
wippersnapper_signal_v1_Ds18x20Request | msgSignalDS |
wippersnapper_signal_v1_ServoRequest | msgServo |
ServoRequest wrapper message. | |
wippersnapper_signal_v1_PWMRequest | msgPWM |
wippersnapper_signal_v1_PixelsRequest | msgPixels |
PixelsRequest wrapper message. | |
wippersnapper_signal_v1_UARTRequest | msgSignalUART |
UARTReq wrapper message. | |
char * | throttleMessage |
int | throttleTime |
bool | pinCfgCompleted = false |
ws_ledc * | _ledc = nullptr |
Pointer to LEDC object. | |
Protected Attributes | |
ws_status_t | _status = WS_IDLE |
uint32_t | _last_mqtt_connect = 0 |
uint32_t | _prv_ping = 0 |
uint32_t | _prvKATBlink = 0 |
const char * | _deviceId |
char * | _device_uid |
char * | _topic_description_status |
char * | _topic_description_status_complete = NULL |
char * | _topic_device_pin_config_complete |
char * | _topic_signal_brkr = NULL |
char * | _err_topic = NULL |
char * | _throttle_topic = NULL |
Adafruit_MQTT_Subscribe * | _topic_description_sub |
Adafruit_MQTT_Publish * | _topic_signal_device_pub |
Adafruit_MQTT_Subscribe * | _topic_signal_brkr_sub |
Adafruit_MQTT_Subscribe * | _topic_signal_i2c_sub |
Adafruit_MQTT_Subscribe * | _topic_signal_servo_sub |
Adafruit_MQTT_Subscribe * | _topic_signal_pwm_sub |
Adafruit_MQTT_Subscribe * | _topic_signal_ds18_sub |
Adafruit_MQTT_Subscribe * | _topic_signal_pixels_sub |
Adafruit_MQTT_Subscribe * | _topic_signal_uart_sub |
Adafruit_MQTT_Subscribe * | _err_sub |
Adafruit_MQTT_Subscribe * | _throttle_sub |
wippersnapper_signal_v1_CreateSignalRequest | _outgoingSignalMsg |
Class that provides storage and functions for the Adafruit IO Wippersnapper interface.
|
virtual |
Sets the device's wireless network credentials.
ssid | Your wireless network's SSID |
ssidPassword | Your wireless network's password. |
Reimplemented in Wippersnapper_AIRLIFT, and Wippersnapper_ESP32.
|
virtual |
Performs a scan of local WiFi networks.
_network_ssid
is found, False otherwise. Reimplemented in Wippersnapper_AIRLIFT, and Wippersnapper_ESP32.
|
virtual |
Gets the network's RSSI.
Reimplemented in Wippersnapper_AIRLIFT, and Wippersnapper_ESP32.
|
virtual |
Sets up the MQTT client session.
clientID | A unique client identifier string. |
Reimplemented in Wippersnapper_AIRLIFT, and Wippersnapper_ESP32.
|
virtual |
Returns the network's connection status.
Reimplemented in Wippersnapper_AIRLIFT, and Wippersnapper_ESP32.
ws_board_status_t Wippersnapper::getBoardStatus | ( | ) |
Returns the board definition status.
bool Wippersnapper::generateDeviceUID | ( | ) |
Attempts to generate unique device identifier.
bool Wippersnapper::generateWSTopics | ( | ) |
Generates device-specific Wippersnapper control topics and subscribes to them.
bool Wippersnapper::generateWSErrorTopics | ( | ) |
Builds MQTT topics for handling errors returned from the Adafruit IO broker and subscribes to them.
bool Wippersnapper::registerBoard | ( | ) |
Attempts to register hardware with Adafruit.io WipperSnapper.
bool Wippersnapper::encodePubRegistrationReq | ( | ) |
Encodes hardware registration request message and publishes the message to the Adafruit IO broker.
void Wippersnapper::decodeRegistrationResp | ( | char * | data, |
uint16_t | len | ||
) |
Decodes hardware registration response message from the Adafruit IO MQTT broker and initializes hardware components.
data | MQTT message from the Adafruit IO MQTT broker. |
len | Length of data from the Adafruit IO MQTT broker. |
void Wippersnapper::pollRegistrationResp | ( | ) |
Polls the broker for the hardware registration response message.
NOTE: This function is BLOCKING and will trigger a WDT reset if the message has not arrived.
NOTE: The registration response msg will arrive async. at the cbRegistrationStatus
function and set the boardStatus
ws_status_t Wippersnapper::run | ( | ) |
Processes incoming commands and handles network connection.
void Wippersnapper::publish | ( | const char * | topic, |
uint8_t * | payload, | ||
uint16_t | bLen, | ||
uint8_t | qos = 0 |
||
) |
Publishes a message to the Adafruit IO MQTT broker. Handles network connectivity.
topic | The MQTT topic to publish to. |
payload | The payload to publish. |
bLen | The length of the payload. |
qos | The Quality of Service to publish with. |
void Wippersnapper::enableWDT | ( | int | timeoutMS = 0 | ) |
Enables the watchdog timer.
timeoutMS | The desired amount of time to elapse before the WDT executes. |
void Wippersnapper::haltError | ( | String | error, |
ws_led_status_t | ledStatusColor = WS_LED_STATUS_ERROR_RUNTIME , |
||
uint8_t | seconds_until_reboot = 25 |
||
) |
Prints an error to the serial and halts the hardware until the WDT bites.
error | The error to print to serial. |
ledStatusColor | The color to blink. |
seconds_until_reboot | The amount of time to wait before rebooting. |
void Wippersnapper::errorWriteHang | ( | String | error | ) |
Writes an error message to the serial and the filesystem, blinks WS_LED_STATUS_ERROR_RUNTIME pattern and hangs.
error | The error message to write to the serial and filesystem. |
bool Wippersnapper::decodeSignalMsg | ( | wippersnapper_signal_v1_CreateSignalRequest * | encodedSignalMsg | ) |
Decodes a signal buffer protobuf message. NOTE: Should be executed in-order after a new _buffer is recieved.
encodedSignalMsg | Encoded signal message. |
bool Wippersnapper::encodePinEvent | ( | wippersnapper_signal_v1_CreateSignalRequest * | outgoingSignalMsg, |
uint8_t | pinName, | ||
int | pinVal | ||
) |
Handles MQTT messages on signal topic until timeout.
outgoingSignalMsg | Empty signal message struct. |
pinName | Name of pin. |
pinVal | Value of pin. |
bool Wippersnapper::configureDigitalPinReq | ( | wippersnapper_pin_v1_ConfigurePinRequest * | pinMsg | ) |
Configures a pin according to a wippersnapper_pin_v1_ConfigurePinRequest message.
pinMsg | Pointer to a wippersnapper_pin_v1_ConfigurePinRequest message. |
bool Wippersnapper::configAnalogInPinReq | ( | wippersnapper_pin_v1_ConfigurePinRequest * | pinMsg | ) |
Configures an analog input pin according to a wippersnapper_pin_v1_ConfigurePinRequest message.
pinMsg | Pointer to a wippersnapper_pin_v1_ConfigurePinRequest message. |
float Wippersnapper::status_pixel_brightness |
Global status pixel's brightness (from 0.0 to 1.0)
WipperSnapper_Component_I2C* Wippersnapper::_i2cPort0 |
WipperSnapper I2C Component for I2C port #0.
WipperSnapper_Component_I2C* Wippersnapper::_i2cPort1 |
WipperSnapper I2C Component for I2C port #1.
bool Wippersnapper::_isI2CPort0Init |
True if I2C port 0 has been initialized, False otherwise.
bool Wippersnapper::_isI2CPort1Init |
True if I2C port 1 has been initialized, False otherwise.
uint8_t Wippersnapper::_buffer[WS_MQTT_MAX_PAYLOAD_SIZE] |
Shared buffer to save callback payload
uint8_t Wippersnapper::_buffer_outgoing[WS_MQTT_MAX_PAYLOAD_SIZE] |
buffer which contains outgoing payload data
uint16_t Wippersnapper::bufSize |
Length of data inside buffer
ws_board_status_t Wippersnapper::_boardStatus |
Hardware's registration status.
ws_display_ui_helper* Wippersnapper::_ui_helper |
Instance of display UI helper class.
uint8_t Wippersnapper::_macAddr[6] |
Unique network iface identifier
char Wippersnapper::sUID[13] |
Unique network iface identifier
const char* Wippersnapper::_boardId |
Adafruit IO+ board string
Adafruit_MQTT* Wippersnapper::_mqtt |
Reference to Adafruit_MQTT, _mqtt.
secretsConfig Wippersnapper::_config |
Wippersnapper secrets.json as a struct.
networkConfig Wippersnapper::_multiNetworks[3] |
Wippersnapper networks as structs.
bool Wippersnapper::_isWiFiMulti = false |
True if multiple networks are defined.
int32_t Wippersnapper::totalDigitalPins |
Total number of digital-input capable pins
char* Wippersnapper::_topic_description = NULL |
MQTT topic for the device description
char* Wippersnapper::_topic_signal_device = NULL |
Device->Wprsnpr messages
char* Wippersnapper::_topic_signal_i2c_brkr = NULL |
Topic carries messages from a device to a broker.
char* Wippersnapper::_topic_signal_i2c_device = NULL |
Topic carries messages from a broker to a device.
char* Wippersnapper::_topic_signal_servo_brkr = NULL |
Topic carries messages from a device to a broker.
char* Wippersnapper::_topic_signal_servo_device = NULL |
Topic carries messages from a broker to a device.
char* Wippersnapper::_topic_signal_pwm_brkr |
Topic carries PWM messages from a device to a broker.
char* Wippersnapper::_topic_signal_pwm_device |
Topic carries PWM messages from a broker to a device.
char* Wippersnapper::_topic_signal_ds18_brkr = NULL |
Topic carries ds18x20 messages from a device to a broker.
char* Wippersnapper::_topic_signal_ds18_device = NULL |
Topic carries ds18x20 messages from a broker to a device.
char* Wippersnapper::_topic_signal_pixels_brkr = NULL |
Topic carries pixel messages
char* Wippersnapper::_topic_signal_pixels_device = NULL |
Topic carries pixel messages
char* Wippersnapper::_topic_signal_uart_brkr = NULL |
Topic carries UART messages
char* Wippersnapper::_topic_signal_uart_device = NULL |
Topic carries UART messages
wippersnapper_signal_v1_CreateSignalRequest Wippersnapper::_incomingSignalMsg |
Incoming signal message from broker
wippersnapper_signal_v1_I2CRequest Wippersnapper::msgSignalI2C |
I2C request wrapper message
wippersnapper_signal_v1_Ds18x20Request Wippersnapper::msgSignalDS |
DS request message wrapper
wippersnapper_signal_v1_PWMRequest Wippersnapper::msgPWM |
PWM request wrapper message.
char* Wippersnapper::throttleMessage |
Pointer to throttle message data.
int Wippersnapper::throttleTime |
Total amount of time to throttle the device, in milliseconds.
bool Wippersnapper::pinCfgCompleted = false |
Did initial pin sync complete?
|
protected |
Adafruit IO connection status
|
protected |
Previous time when client connected to Adafruit IO, in milliseconds.
|
protected |
Previous time when client pinged Adafruit IO's MQTT broker, in milliseconds.
|
protected |
Previous time when client pinged Adafruit IO's MQTT broker, in milliseconds.
|
protected |
Adafruit IO+ device identifier string
|
protected |
Unique device identifier
|
protected |
MQTT subtopic carrying the description status resp. from the broker
|
protected |
MQTT topic carrying the ACK signal from the device to the broker after registration
|
protected |
MQTT topic carrying the ACK signal from the device to the broker after hardware configuration
|
protected |
Wprsnpr->Device messages
|
protected |
Adafruit IO MQTT error message topic.
|
protected |
Adafruit IO MQTT throttle message topic.
|
protected |
Subscription callback for registration topic.
|
protected |
Subscription callback for D2C signal topic.
|
protected |
Subscription callback for C2D signal topic.
|
protected |
Subscription callback for I2C topic.
|
protected |
Subscription callback for servo topic.
|
protected |
Subscription callback for pwm topic.
|
protected |
Subscribes to signal's ds18x20 topic.
|
protected |
Subscribes to pixel device topic.
|
protected |
Subscribes to signal's UART topic.
|
protected |
Subscription to Adafruit IO Error topic.
|
protected |
Subscription to Adafruit IO Throttle topic.
|
protected |
Outgoing signal message from device