DeviceNameHelperRK
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
DeviceNameHelperEEPROM Class Reference

Version of DeviceNameHelper that stores the name in EEPROM emulation. More...

#include <DeviceNameHelperRK.h>

Inheritance diagram for DeviceNameHelperEEPROM:
DeviceNameHelper

Public Member Functions

void setup (int eepromStart)
 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()
 
DeviceNameHelperwithNameCallback (std::function< void(const char *)> nameCallback)
 Adds a function to call when the name is known. More...
 
DeviceNameHelperwithCheckPeriod (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 DeviceNameHelperEEPROMinstance ()
 Get the singleton instance of this class, creating it if necessary. More...
 
- Static Public Member Functions inherited from DeviceNameHelper
static DeviceNameHelpergetInstance ()
 Special generic instance getter. More...
 

Protected Member Functions

 DeviceNameHelperEEPROM ()
 Constructor - You never instantiate this class directly. More...
 
virtual ~DeviceNameHelperEEPROM ()
 This class is a singleton and never deleted.
 
virtual void save ()
 Virtual override of base class to save data to the EEPROM.
 
- 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.
 
DeviceNameHelperoperator= (const DeviceNameHelper &)=delete
 This class is not copyable.
 
void commonSetup ()
 All of the storage-method specific setup methods call that at the end.
 
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

int eepromStart
 Start offset into the EEPROM for where to save the data.
 
DeviceNameHelperData eepromData
 Heap-allocated data. A pointer to this is stored in the base class' data field. More...
 
- Protected Attributes inherited from DeviceNameHelper
DeviceNameHelperDatadata = 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.
 

Detailed Description

Version of DeviceNameHelper that stores the name in EEPROM emulation.

It requires 44 bytes of EEPROM emulation. You specify the start address as a parameter to setup and the data is a DeviceNameHelperData object.

You must make sure the whole range of values does not interfere with any other data stored in EEPROM. You do not need to initialize the data in any way.

On Gen 3 devices running Device OS 2.0.0 you may want to use a file on the flash file system using DeviceNameHelperFile instead of using EEPROM.

Constructor & Destructor Documentation

◆ DeviceNameHelperEEPROM()

DeviceNameHelperEEPROM::DeviceNameHelperEEPROM ( )
protected

Constructor - You never instantiate this class directly.

Instead, use DeviceNameHelperEEPROM::instance() to get the singleton instance, creating it if necessary.

Member Function Documentation

◆ instance()

DeviceNameHelperEEPROM & DeviceNameHelperEEPROM::instance ( )
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().

◆ setup()

void DeviceNameHelperEEPROM::setup ( int  eepromStart)

You must call setup() from global setup()!

This is typically done like this from your app's setup() method.

DeviceNameHelperEEPROM::instance().setup(0);

Also note that you must do the same from global loop():

DeviceNameHelperEEPROM::instance().loop();

Field Documentation

◆ eepromData

DeviceNameHelperData DeviceNameHelperEEPROM::eepromData
protected

Heap-allocated data. A pointer to this is stored in the base class' data field.

It's read from the EEPROM during setup().


The documentation for this class was generated from the following files: