This is an application library, which is used usually as a project library for particular PlatformIO project. It encapsulates the functionality of central project data management
. The encapsulation provides following advantages:
- Functionality is hidden from the main sketch.
- The library follows the principle
separation of concerns
. - The library is reusable for every project with its derived class acting as a central project data hub.
- Update in library is valid for all involved projects.
- The class from the library is not intended to be used directly in a sketch, just as a parent class for project specific data hub libraries, e.g.,
app_data
. - The class provide definition of a structure for a data item management with its methods and members, mostly flags.
- A data item value is kept in the library instance object always in string form in order to publish it independent from its original data type.
- gbj_serial_debug: Auxilliary library for debug serial output loaded from the file
gbj_serial_debug.h
. It enables to exclude serial outputs from final compilation.
- Arduino.h: Main include file for the Arduino platform.
- Arduino.h: Main include file for the Arduino platform.
- Particle.h: Includes alternative (C++) data type definitions.
The structure with members and member methods as a template of a data item.
- A data item as an instance of this structure acts as a cache for entire project and is considered a part of the data hub.
- A set of boolean flags determines specific behaviour of an item, especially at definition as well as after publishing.
- While it is a structure, all methods are public even if some of them are used as private ones and should not be used outside of the definition.
- Parameter(const char *key): Constructor for a data item.
- key: The name of a data parameter. It is usually stored in flash memory for reducing operational memory usage and is generally prefixed as label with abbreviation
lbl
, e.g., lblPeriodPublish. Data item names are usually defined in include configuration files with names starting withconfig_params
either in common or shared location, e.g., config_params_gen.h or specifically in a project.
- key: The name of a data parameter. It is usually stored in flash memory for reducing operational memory usage and is generally prefixed as label with abbreviation
- void set([<datatype> value, [unsigned int decimal]]): The overloaded setter for updating a data item, each for particular data type. Two parameters are used just at float values. The method converts value from original data type to String data type and stores the provided value with help of the method
setValue()
. The setter returns updated value by calling its getter. At no input arguments the method implicitly store the textual valuen.a.
.- value: The new value of the data item. Its valid data types are defined by enumeration
Datatype
and can be:- TYPE_NONE - Unknown data type is set at creating the data item or by method
reset()
, and its value is stored by methodset()
. - TYPE_BOOL - bool - Boolean data type with string values
true
andfalse
. - TYPE_BYTE - byte - Unsigned one character integer (8-bit) data type.
- TYPE_INT - int - Signed integer (16-bit) data type.
- TYPE_LONG - long - Signed long integer (32-bit) data type.
- TYPE_UINT - unsigned int - Unsigned integer (16-bit) data type.
- TYPE_LONG - unsigned long - Unsigned signed long integer (32-bit) data type.
- TYPE_FLOAT - float - Floating point numeric data type.
- TYPE_STRING - String - Stringified data type.
- TYPE_CCHAR - const char* - Pointer to an external string buffer
- TYPE_NONE - Unknown data type is set at creating the data item or by method
- value: The new value of the data item. Its valid data types are defined by enumeration
- void setValue(String value): The method stores the stringified value. If it differs from currently stored one, i.e., it is new one, it sets flags for publishing and eventing. The method sets flag for a new item in either case. If the item is mark as repeatable by the method
always()
, it is marked as new even if the input value has not changed.- value: Stringified value of the data item.
- void reset(): The method initializes the data item in it was at its creation. It calls method
set()
, so that the value of it isn.a.
and type unknown. - String get(): The getter returns the stringified data items's current value.
- bool getBool(): The getter returns the data items's current value converted to boolean value.
- char *getName(): The getter returns pointer to buffer with the data item's name.
- Datatype getType(): The getter returns the enumeration literal determining the original data type of the item.
- unsigned long getPubIniMs(): The getter returns the timestamp in milliseconds of the recent initialization of the item by the method
pubInit()
. - String event(): The getter resets event flag and fires the
get()
method. - bool eventBool(): The getter resets event flag and fires the
getBool()
method. - String publish(): The method returns the stringified data items's current value for publishing in IoT platform with method
get()
and marks the item as published. - String publish(): The method returns the stringified data items's current value for eventing in webservers with method
get()
and marks the item as published. The timestamp of the publish initiation is reset (zeroed) as well. - bool isSet(): The method decides whether the data item has been set.
- bool isNew(): The method determines whether the data item's value differs from currently stored, i.e., whether it is new.
- bool isEvent(): The method decides whether the data item is available for eventing.
- bool isPub(): The method decides whether the data item is available for publishing.
- void pubReset(): It marks the data item as published, i.e., publishing is suppressed without setting a value.
- void pubInit(): It marks the data item as it is allowed for publishing and registers the timestamp of the initiation, which can be obtained by the method
getPubIniMs()
. The timestamp is utilized by retry at publishing failure. - void always(): It marks the data item as new in the method
setValue()
even if the input value has not changed. - void change(): It is counterpart for the previous method and marks the data item that it should be published only after changing its value from recently published one.
- void show(): It marks the data item that it is generally enabled for publishing and/or eventing.
- void hide(): It is counterpart for the previous method and marks the data item that it is generally disabled for publishing. It can be utilized for temporary suppressing the data item for particular conditions.
Constructor creates the class instance object and initiates internal resources.
gbj_appdata()
None
Object performing data items management.
The method returns a pointer to a buffer with data item name.
const char *getPrmName(const char *progmemPrmName)
- progmemPrmName: Pointer to an internal buffer with copy of a data item name stored in the flash memory of the microcontroller.
- Valid values: pointer to a constant array of characters
- Default value: none
Pointer to a data item name.