This is an application library, which is used usually as a project library for particular PlatformIO project. It encapsulates common core methods for project centric application libraries and acts as their parent class. The encapsulation provides following advantages:
- Functionality is hidden from the main sketch.
- The library is reusable for various projects providing basic functionality.
- Update in library is valid for all involved projects.
- It provides error handling for all derived classes.
- Unified error handling.
- Enumerated result and error codes.
- Detecting microcontroller restart (boot) reason.
- Registering HTTP response codes and texts.
- Rounding float numbers.
- Arduino.h: Main include file for the Arduino SDK.
- avr/pgmspace.h: Processing flashed strings.
- inttypes.h: Integer type conversions. This header file includes the exact-width integer definitions and extends them with additional facilities provided by the implementation.
- Arduino.h: Main include file for the Arduino platform.
- pgmspace.h: Processing flashed strings.
- user_interface.h: Various macros and definitions.
- Arduino.h: Main include file for the Arduino platform.
- pgmspace.h: Processing flashed strings.
- ResultCodes::SUCCESS: Result code for successful processing.
- ResultCodes::ERROR_UKNOWN: Unexpected or not recognized error.
- ResultCodes::ERROR_NOINIT: Not initialized yet.
- ResultCodes::ERROR_NODEVICE: No device detected.
- ResultCodes::ERROR_PINS: Wrong GPIO assignment.
- ResultCodes::ERROR_ADDR: No or wrong address.
- ResultCodes::ERROR_DATA: Not or wrong data.
- ResultCodes::ERROR_ACK: No acknoledgment for a comunicating device.
- ResultCodes::ERROR_CONNECT: Connection failed.
- ResultCodes::ERROR_PUBLISH: Publishing failed.
- ResultCodes::ERROR_SUBSCRIBE: Subsribing failed.
- ResultCodes::ERROR_AUTH: Authorization failed.
- BootReasons::BOOT_UNKNOWN: Not detected or unknown.
- BootReasons::BOOT_DEFAULT_RST: Normal startup by power on.
- BootReasons::BOOT_WDT_RST: Hardware watch dog reset.
- BootReasons::BOOT_EXCEPTION_RST: Exception reset, GPIO status won’t change.
- BootReasons::BOOT_SOFT_WDT_RST: Software watch dog reset, GPIO status won’t change.
- BootReasons::BOOT_INT_WDT_RST: Interrupt watch dog reset.
- BootReasons::BOOT_TASK_WDT_RST: Task watch dog reset.
- BootReasons::BOOT_SOFT_RESTART: Software restart, system restart, GPIO status won’t change.
- BootReasons::BOOT_DEEP_SLEEP_AWAKE: Wake up from deep-sleep.
- BootReasons::BOOT_EXT_SYS_RST: External system reset (assertion of reset pin).
- BootReasons::BOOT_DEEPSLEEP: After exiting deep sleep mode.
- BootReasons::BOOT_BROWNOUT: Brownout reset (software or hardware).
- BootReasons::BOOT_SDIO: Reset over SDIO.
- BootReasons::BOOT_WAKEUP_UNDEFINED: Not caused by exit from deep sleep.
- BootReasons::BOOT_WAKEUP_ALL: Not a wakeup cause.
- BootReasons::BOOT_WAKEUP_EXT0: Wakeup caused by external signal using RTC_IO.
- BootReasons::BOOT_WAKEUP_EXT1: Wakeup caused by external signal using RTC_CNTL.
- BootReasons::BOOT_WAKEUP_TIMER: Wakeup caused by timer.
- BootReasons::BOOT_WAKEUP_TOUCHPAD: Wakeup caused by touchpad.
- BootReasons::BOOT_WAKEUP_ULP: Wakeup caused by ULP program.
- BootReasons::BOOT_WAKEUP_GPIO: Wakeup caused by GPIO (light sleep only).
- BootReasons::BOOT_WAKEUP_UART: Wakeup caused by UART (light sleep only).
- gbj_appcore()
- setLastResult()
- getLastResult()
- setLastHttpCode()
- setLastHttpText()
- getLastHttpCode()
- getLastHttpText()
- getResetReason() (valid just for ESP8266, ESP32)
- getResultName()
- getResetName() (valid just for ESP8266, ESP32)
- isSuccess()
- isError()
- roundoff()
Enumeration with result and error codes.
ResultCodes::<code_name>
Enumeration with boot reason codes.
BootReasons::<code_name>
Constructor creates the class instance object, determines microcontroller reset reason, and sets recent result code to SUCCESS.
gbj_appcore()
None
Object determining microcontroller reset reason. However, it is not intended to be instantiated as itself, only in form of a child class instance.
The method sets the internal status of recent processing to input value.
- Without input parameter the method sets success internal status with result constant SUCCESS.
ResultCodes setLastResult(ResultCodes lastResult)
- lastResult: Desired result code that should be set as a last result code.
- Valid values: some of result or error codes
- Default value: SUCCESS
New (actual) result code of the recent operation.
The method returns a result or error code of the recent operation. It is usually called for error handling in a sketch.
ResultCodes getLastResult()
None
Some of result or error codes.
The particular method registers the HTTP response code and related text to the object for later utilization.
- Without input HTTP code argument the method sets neutral HTTP response code.
- Without input HTTP text argument the method sets empty HTTP response text.
int setLastHttpCode(int lastHttpCode)
String setLastHttpCode(String lastHttpText)
-
lastHttpCode: Recent HTTP response code.
- Valid values: -32628 ~ 32628
- Default value: 0
-
lastHttpText: Description of recent HTTP response code.
- Valid values: String
- Default value: empty string
The value of the just put input argument.
The method returns recent HTTP response code and its related text, if any.
int getLastHttpCode()
String getLastHttpCode()
None
The value of the recently registered HTTP response code and its related description.
The method returns a boot reason code of the recent microcontroller restart from boot reason codes.
- The method is valid only for microcontrollers ESP5266 and ESP32. For others it returns always unknown boot reason.
BootReasons getResetReason()
None
Some of boot reason codes.
The method returns a pointer to textual name of last result of a recent operation.
- The result names are equal to corresponding enumeration literals from result or error codes.
char *getResultName()
None
Pointer to name of a recent operation.
The method returns a pointer to textual name of a boot reason of the recent microcontroller restart.
- The method is valid only for microcontrollers ESP5266 and ESP32. For others it returns always unknown boot reason name.
- The boot reason names are equal to corresponding enumeration literals from boot reason codes.
char *getResetName()
None
Pointer to name of a microcontroller reset reason name.
The overloade method returns a flag whether the recent operation was successful or input argument is a success code.
bool isSuccess()
bool isSuccess(ResultCodes lastResult)
- lastResult: Optional error code as a last result code.
- Valid values: some of result or error codes
- Default value: none
Flag about successful processing of the recent operation or input as a success code.
The method returns a flag whether the recent operation failed or input argument is an error code. The corresponding error code can be obtained by the method getLastResult().
bool isError()
bool isError(ResultCodes lastResult)
- lastResult: Optional error code as a last result code.
- Valid values: some of result or error codes
- Default value: none
Flag about failing of the recent operation or input as an error code.
The method rounds provided rational number to desired decimal places.
float roundoff(float value, byte prec)
-
value: A number to be rounded.
- Valid values: float numbers
- Default value: none
-
prec: Rounding precision in number of decimal places.
- Valid values: 0 ~ 255
- Default value: none
Rounded rational number to provided number of decimal places.