MistyGro API
C++ API for MistyGro's ESP32 controller based on the Arduino framework
test_firebase_logger.cpp
Go to the documentation of this file.
1 // Copyright 2023 Myron Rodrigues
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <Arduino.h>
16 #include <WiFi.h>
17 
18 #include "firebase_logger.h"
19 #include "scheduler.h"
20 #include "secrets.h"
21 
22 int64_t count = 0;
23 
26 
27 void set_value()
28 {
29  count++;
30  flog.set_int("test/int", count);
31 }
32 
33 void check_wifi()
34 {
35  if (!WiFi.isConnected()) {
36  Serial.print(millis());
37  Serial.println("Reconnecting to WiFi...");
38  WiFi.disconnect();
39  WiFi.reconnect();
40  }
41  Serial.printf(
42  "Is firebase connected: %s\n", flog.is_connected() ? "true" : "false");
43 }
44 
46 
47 void setup()
48 {
49  Serial.begin(115200);
50  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
51  flog.begin(
52  FIREBASE_URL, FIREBASE_TOKEN, FIREBASE_USER_EMAIL, FIREBASE_USER_PASSWORD);
53 
54  scheduler.begin();
58 
59  Serial.println("Done setup");
60 }
61 
62 void loop() { scheduler.run(); }
Firebase RTDB logger.
bool is_connected()
Get http server connection status.
void begin(const char *fire_url, const char *fire_token, const char *email, const char *pass)
initialise and authorise system to use Firebase RTDB (real time database) make sure wifi is initialis...
void set_int(const char *path, int64_t value)
Set an integer value.
bool check_and_refresh_token()
refresh token if expired
A scheduler for running tasks on the controller, minimum time between events is 1 second based off th...
Definition: scheduler.h:34
void begin(long int timer_sync_interval_ms=600000)
initialise timer
Definition: scheduler.cpp:45
void run()
This needs to be run in the loop function continuously. Best practice is to have a loop function that...
Definition: scheduler.cpp:31
void create_task(void(*task_func)(), unsigned long interval_sec)
Create a task.
Definition: scheduler.cpp:21
void set_value()
FireLogger flog
void setup()
Scheduler scheduler
void check_and_refresh_firebase_token()
void check_wifi()
int64_t count
void loop()