DeviceNameHelperRK
|
Version of DeviceNameHelper that stores the name in volatile RAM. More...
#include <DeviceNameHelperRK.h>
Public Member Functions | |
void | setup () |
You must call setup() from global setup()! More... | |
Public Member Functions inherited from DeviceNameHelper | |
void | loop () |
You must call this from loop on every call to loop() | |
DeviceNameHelper & | withNameCallback (std::function< void(const char *)> nameCallback) |
Adds a function to call when the name is known. More... | |
DeviceNameHelper & | withCheckPeriod (std::chrono::seconds checkPeriod) |
Sets. More... | |
bool | hasName () const |
Returns true if the name has been retrived and is non-empty. | |
const char * | getName () const |
Returns the device name as a c-string. More... | |
long | getLastNameCheckTime () const |
Get the time the name was last fetched. More... | |
void | checkName () |
Request the name again. More... | |
void | subscriptionRemoved () |
Call if you've called Particle.unsubscribe. More... | |
Static Public Member Functions | |
static DeviceNameHelperNoStorage & | instance () |
Get the singleton instance of this class, creating it if necessary. More... | |
Static Public Member Functions inherited from DeviceNameHelper | |
static DeviceNameHelper * | getInstance () |
Special generic instance getter. More... | |
Protected Member Functions | |
DeviceNameHelperNoStorage () | |
Constructor - You never instantiate this class directly. More... | |
virtual | ~DeviceNameHelperNoStorage () |
This class is a singleton and never deleted. | |
Protected Member Functions inherited from DeviceNameHelper | |
DeviceNameHelper () | |
Constructor - You never instantiate this class directly. More... | |
virtual | ~DeviceNameHelper () |
This class is a singleton and never deleted. | |
DeviceNameHelper (const DeviceNameHelper &)=delete | |
This class is not copyable. | |
DeviceNameHelper & | operator= (const DeviceNameHelper &)=delete |
This class is not copyable. | |
void | commonSetup () |
All of the storage-method specific setup methods call that at the end. | |
virtual void | save () |
This method is called to save the DeviceNameHelperData. More... | |
void | stateStart () |
State handler, entry point when starting up. More... | |
void | stateSubscribe () |
Add a subscription handler, if necessary. More... | |
void | stateWaitConnected () |
Waits until Particle.connected() and Time.isValid() are true. More... | |
void | stateWaitRequest () |
Waits POST_CONNECT_WAIT_MS milliseconds (2 seconds) then publishes the request for device name event "particle/device/name". More... | |
void | stateWaitResponse () |
Waits for a device name event to be received. More... | |
void | stateWaitRetry () |
Waits 5 minutes (RETRY_WAIT_MS) and tries requesting the name again. More... | |
void | stateWaitRecheck () |
Wait until it's time to check the name again. More... | |
void | subscriptionHandler (const char *eventName, const char *eventData) |
Subscription handler for the "particle/device/name" event. More... | |
Protected Attributes | |
DeviceNameHelperData | _data |
Heap-allocated data. A pointer to this is stored in the base class' data field. | |
Protected Attributes inherited from DeviceNameHelper | |
DeviceNameHelperData * | data = 0 |
DeviceNameHelperData structure pointer. More... | |
std::chrono::seconds | checkPeriod = 0s |
How often to fetch the name again in seconds (0 = never check again) | |
std::function< void(const char *)> | nameCallback = 0 |
Optional function or C++11 lambda to call when the name is known. More... | |
std::function< void(DeviceNameHelper &)> | stateHandler = 0 |
Current state handler, or NULL if in done state. | |
unsigned long | stateTime = 0 |
Some states use this for timing. It's a value from millis() if used. | |
bool | hasSubscribed = false |
true if Particle.subscribe has been called | |
bool | gotResponse = false |
true if the event subscription handler was called. The name is stored in data.name. | |
bool | forceCheck = false |
Used by checkName() to force the name to be checked again. | |
Additional Inherited Members | |
Static Public Attributes inherited from DeviceNameHelper | |
static const uint32_t | DATA_MAGIC = 0x7787a2f2 |
Magic bytes used to detect if EEPROM or retained memory has been initialized. | |
Static Protected Attributes inherited from DeviceNameHelper | |
static const unsigned long | POST_CONNECT_WAIT_MS = 2000 |
Amount of time to wait after connection for the subscription to be activated (milliseconds) | |
static const unsigned long | RESPONSE_WAIT_MS = 15000 |
How long to wait for a device name response before timing out and waiting to retry (milliseconds) | |
static const unsigned long | RETRY_WAIT_MS = 5 * 60 * 1000 |
How long to wait to retry a request to get the device name (in milliseconds) | |
static DeviceNameHelper * | _instance = 0 |
Singleton instance pointer, set by the subclass instance() methods. | |
Version of DeviceNameHelper that stores the name in volatile RAM.
Useful on Gen 2 devices if you don't have sufficient retained RAM or EEPROM available. The name will be fetched on every startup. On Gen 3 devices you can use DeviceNameHelperFile with Device OS 2.0.0 and later to store the device name in a file on the 2MB flash file system.
This is not recommended if you are using HIBERNATE sleep mode as the name would need to be fetched on every wake!
|
protected |
Constructor - You never instantiate this class directly.
Instead, use DeviceNameHelperNoStorage::instance() to get the singleton instance, creating it if necessary.
|
static |
Get the singleton instance of this class, creating it if necessary.
You cannot construct an instance of this class manually, as a global or on the stack. You must instead use instance().
void DeviceNameHelperNoStorage::setup | ( | ) |