Magic Poi Lite 0.1
IOT LED Poi
|
Public Member Functions | |
Loading () | |
Default constructor for Loading class. | |
String | getTimelineNumber () |
Retrieves the current timeline number from the server. | |
bool | getTimeline (String tln) |
Retrieves the timeline data from the server based on the specified timeline number. | |
void | saveTimeline (const String &timelineData) |
Saves the timeline data to a file. | |
bool | load () |
Loads data required for the application. | |
Private Attributes | |
WiFiClient | client |
WiFi client object. | |
Authentication | authentication |
Authentication object. | |
char | token [512] |
JWT token buffer. | |
String | timelineNumber = "0" |
Default timeline number. | |
String | timelineFilePath = "/timeline" + timelineNumber + ".txt" |
File path of the timeline file. | |
Loading::Loading | ( | ) |
Default constructor for Loading class.
This constructor initializes the Loading object. It attempts to load a JWT token from a file using the Authentication object. If a token is successfully loaded, it is stored internally. Otherwise, it prepares to use password login if token loading fails.
References authentication, Authentication::readJWTTokenFromFile(), and token.
bool Loading::getTimeline | ( | String | tln | ) |
Retrieves the timeline data from the server based on the specified timeline number.
This method sends a GET request to the server to retrieve the timeline data corresponding to the provided timeline number. It includes the JWT token in the request headers for authentication. If the request is successful and the response code is OK, the timeline data is saved and the method returns true. If any error occurs during the HTTP request or the response code indicates a failure, the method returns false.
tln | The timeline number to retrieve data for. |
References client, saveTimeline(), and token.
Referenced by load().
String Loading::getTimelineNumber | ( | ) |
Retrieves the current timeline number from the server.
This method sends a GET request to the server to retrieve the current timeline number. It includes the JWT token in the request headers for authentication. If the request is successful and the response code is OK, the method returns the timeline number received from the server. If any error occurs during the HTTP request or the response code indicates a failure, an empty string is returned.
Referenced by load().
bool Loading::load | ( | ) |
Loads data required for the application.
This method attempts to load data required for the application. It first tries to retrieve the current timeline number from the server. If successful, it proceeds to load the timeline data. If both operations succeed, the method returns true indicating successful loading. If any of the operations fail, the method returns false.
References getTimeline(), getTimelineNumber(), and timelineNumber.
Referenced by handleAuthenticationAndLoading().
void Loading::saveTimeline | ( | const String & | timelineData | ) |
Saves the timeline data to a file.
This method saves the provided timeline data to a file using the LittleFS (Little File System). If LittleFS initialization succeeds and the file is successfully created and written, a success message is printed to the Serial monitor. If there's any failure during the file system operation, the method returns without saving the data.
timelineData | The timeline data to be saved to the file. |
References timelineFilePath.
Referenced by getTimeline().
|
private |
Authentication object.
This object is used for handling authentication operations.
Referenced by Loading().
|
private |
WiFi client object.
This object is used for network communication with the server.
Referenced by getTimeline(), and getTimelineNumber().
|
private |
File path of the timeline file.
This string represents the file path of the timeline data file, saved in LittleFS.
Referenced by saveTimeline().
|
private |
Default timeline number.
This string represents the default timeline number used for file paths.
Referenced by load().
|
private |
JWT token buffer.
This buffer stores the JWT token retrieved from authentication.
Referenced by getTimeline(), getTimelineNumber(), and Loading().