diff --git a/README.md b/README.md index 26344b12..bf17c6f1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4390794.svg)](https://doi.org/10.5281/zenodo.4390794) -Google's Firebase Realtime Database Arduino Library for ESP8266 v 3.1.7 +Google's Firebase Realtime Database Arduino Library for ESP8266 v 3.1.8 This library supports ESP8266 MCU from Espressif. The following are platforms in which libraries are also available. diff --git a/examples/Authentications/Access_Token_from_File/Access_Token_from_File.ino b/examples/Authentications/Access_Token_from_File/Access_Token_from_File.ino index ed1c31b9..96b48601 100644 --- a/examples/Authentications/Access_Token_from_File/Access_Token_from_File.ino +++ b/examples/Authentications/Access_Token_from_File/Access_Token_from_File.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Authentications/Anonymous_Signin/Anonymous_Signin.ino b/examples/Authentications/Anonymous_Signin/Anonymous_Signin.ino index 88c1dd6f..7d898c40 100644 --- a/examples/Authentications/Anonymous_Signin/Anonymous_Signin.ino +++ b/examples/Authentications/Anonymous_Signin/Anonymous_Signin.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ @@ -33,7 +33,7 @@ /** 3. Define the API key * * The API key can be obtained since you created the project and set up - * the Authentication in Firebase conssole. + * the Authentication in Firebase console. * * You may need to enable the Identity provider at https://console.cloud.google.com/customer-identity/providers * Select your project, click at ENABLE IDENTITY PLATFORM button. diff --git a/examples/Authentications/Custom_Token/Custom_Token.ino b/examples/Authentications/Custom_Token/Custom_Token.ino index bfc27f14..55342343 100644 --- a/examples/Authentications/Custom_Token/Custom_Token.ino +++ b/examples/Authentications/Custom_Token/Custom_Token.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ @@ -35,7 +35,7 @@ /** 3. Define the API key * * The API key can be obtained since you created the project and set up - * the Authentication in Firebase conssole. + * the Authentication in Firebase console. * * You may need to enable the Identity provider at https://console.cloud.google.com/customer-identity/providers * Select your project, click at ENABLE IDENTITY PLATFORM button. @@ -185,7 +185,7 @@ void setup() * To modify the database rules in this exanple, we need the full access rights then * using the database secret in prepareDatabaseRules function to sign in. * - * If you database rules has been modified, plesse comment this code out. + * If you database rules has been modified, please comment this code out. * * The character $ is to make a wildcard variable (can be any name) represents any node key * which located at some level in the rule structure and use as reference variable diff --git a/examples/Authentications/Custom_Token_from_File/Custom_Token_from_File.ino b/examples/Authentications/Custom_Token_from_File/Custom_Token_from_File.ino index fdac2ada..cf3098ab 100644 --- a/examples/Authentications/Custom_Token_from_File/Custom_Token_from_File.ino +++ b/examples/Authentications/Custom_Token_from_File/Custom_Token_from_File.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ @@ -35,7 +35,7 @@ /** 3. Define the API key * * The API key can be obtained since you created the project and set up - * the Authentication in Firebase conssole. + * the Authentication in Firebase console. * * You may need to enable the Identity provider at https://console.cloud.google.com/customer-identity/providers * Select your project, click at ENABLE IDENTITY PLATFORM button. @@ -155,7 +155,7 @@ void setup() * To modify the database rules in this exanple, we need the full access rights then * using the database secret in prepareDatabaseRules function to sign in. * - * If you database rules has been modified, plesse comment this code out. + * If you database rules has been modified, please comment this code out. * * The character $ is to make a wildcard variable (can be any name) represents any node key * which located at some level in the rule structure and use as reference variable @@ -268,7 +268,7 @@ void prepareDatabaseRules(const char *path, const char *var, const char *readVal Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); Serial.println("------------------------------------"); - Serial.println("Read database ruless..."); + Serial.println("Read database rules..."); if (Firebase.getRules(fbdo)) { FirebaseJsonData result; diff --git a/examples/Authentications/Email_Password/Email_Password.ino b/examples/Authentications/Email_Password/Email_Password.ino index 1bbcde46..09962d66 100644 --- a/examples/Authentications/Email_Password/Email_Password.ino +++ b/examples/Authentications/Email_Password/Email_Password.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ @@ -36,7 +36,7 @@ /** 3. Define the API key * * The API key (required) can be obtained since you created the project and set up - * the Authentication in Firebase conssole. Then you will get the API key from + * the Authentication in Firebase console. Then you will get the API key from * Firebase project Web API key in Project settings, on General tab should show the * Web API Key. * @@ -47,7 +47,7 @@ */ #define API_KEY "WEB_API_KEY" -/* 4. Define the user Email and password that alreadey registerd or added in your project */ +/* 4. Define the user Email and password that alreaey registerd or added in your project */ #define USER_EMAIL "USER_EMAIL" #define USER_PASSWORD "USER_PASSWORD" @@ -134,7 +134,7 @@ void setup() * which located at some level in the rule structure and use as reference variable * in .read, .write and .validate rules * - * If you database rules has been modified, plesse comment this code out + * If you database rules has been modified, please comment this code out */ String var = "$user"; String val = "(auth.uid === $user)"; @@ -219,7 +219,7 @@ void prepareDatabaseRules(const char *path, const char *var, const char *readVal Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); Serial.println("------------------------------------"); - Serial.println("Read database ruless..."); + Serial.println("Read database rules..."); if (Firebase.getRules(fbdo)) { FirebaseJsonData result; diff --git a/examples/Authentications/Legacy_Token/Legacy_Token.ino b/examples/Authentications/Legacy_Token/Legacy_Token.ino index 47fdf7e0..04d49a3a 100644 --- a/examples/Authentications/Legacy_Token/Legacy_Token.ino +++ b/examples/Authentications/Legacy_Token/Legacy_Token.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Authentications/Reset_Password/Reset_Password.ino b/examples/Authentications/Reset_Password/Reset_Password.ino index b025070b..c839364a 100644 --- a/examples/Authentications/Reset_Password/Reset_Password.ino +++ b/examples/Authentications/Reset_Password/Reset_Password.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ @@ -27,7 +27,7 @@ /** 3. Define the API key * * The API key can be obtained since you created the project and set up - * the Authentication in Firebase conssole. + * the Authentication in Firebase console. * * You may need to enable the Identity provider at https://console.cloud.google.com/customer-identity/providers * Select your project, click at ENABLE IDENTITY PLATFORM button. diff --git a/examples/Authentications/Send_Verification/Send_Verification.ino b/examples/Authentications/Send_Verification/Send_Verification.ino index aff69dc4..8d021955 100644 --- a/examples/Authentications/Send_Verification/Send_Verification.ino +++ b/examples/Authentications/Send_Verification/Send_Verification.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ @@ -32,7 +32,7 @@ /** 3. Define the API key * * The API key can be obtained since you created the project and set up - * the Authentication in Firebase conssole. + * the Authentication in Firebase console. * * You may need to enable the Identity provider at https://console.cloud.google.com/customer-identity/providers * Select your project, click at ENABLE IDENTITY PLATFORM button. @@ -41,7 +41,7 @@ */ #define API_KEY "WEB_API_KEY" -/* 4. Define the user Email and password that alreadey registerd or added in your project */ +/* 4. Define the user Email and password that already registerd or added in your project */ #define USER_EMAIL "USER_EMAIL" #define USER_PASSWORD "USER_PASSWORD" diff --git a/examples/Authentications/Signup/Signup.ino b/examples/Authentications/Signup/Signup.ino index fce2468c..eddc7d8d 100644 --- a/examples/Authentications/Signup/Signup.ino +++ b/examples/Authentications/Signup/Signup.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ @@ -30,7 +30,7 @@ /** 3. Define the API key * * The API key can be obtained since you created the project and set up - * the Authentication in Firebase conssole. + * the Authentication in Firebase console. * * You may need to enable the Identity provider at https://console.cloud.google.com/customer-identity/providers * Select your project, click at ENABLE IDENTITY PLATFORM button. diff --git a/examples/AutomaticPlantWatering/AutomaticPlantWatering.ino b/examples/AutomaticPlantWatering/AutomaticPlantWatering.ino index 61dbc500..bf0c2b7c 100644 --- a/examples/AutomaticPlantWatering/AutomaticPlantWatering.ino +++ b/examples/AutomaticPlantWatering/AutomaticPlantWatering.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Backup_and_Restore_flash_memory/Backup_and_restore_flash_memory.ino b/examples/Backup_and_Restore_flash_memory/Backup_and_restore_flash_memory.ino index 3f9a02d3..0ce39103 100644 --- a/examples/Backup_and_Restore_flash_memory/Backup_and_restore_flash_memory.ino +++ b/examples/Backup_and_Restore_flash_memory/Backup_and_restore_flash_memory.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Backup_and_Send_Email/Backup_and_Send_Email.ino b/examples/Backup_and_Send_Email/Backup_and_Send_Email.ino index ce7a41da..1d65f602 100644 --- a/examples/Backup_and_Send_Email/Backup_and_Send_Email.ino +++ b/examples/Backup_and_Send_Email/Backup_and_Send_Email.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Backup_and_restore/Backup_and_restore.ino b/examples/Backup_and_restore/Backup_and_restore.ino index f290d03a..44a4e5d1 100644 --- a/examples/Backup_and_restore/Backup_and_restore.ino +++ b/examples/Backup_and_restore/Backup_and_restore.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Basic/Basic.ino b/examples/Basic/Basic.ino index 1ea7c733..72d43354 100644 --- a/examples/Basic/Basic.ino +++ b/examples/Basic/Basic.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Basic_with_cert/Basic_with_cert.ino b/examples/Basic_with_cert/Basic_with_cert.ino index 4b05385e..012eb272 100644 --- a/examples/Basic_with_cert/Basic_with_cert.ino +++ b/examples/Basic_with_cert/Basic_with_cert.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Beginner_start_here/Beginner_start_here.ino b/examples/Beginner_start_here/Beginner_start_here.ino index 22084e20..096fe274 100644 --- a/examples/Beginner_start_here/Beginner_start_here.ino +++ b/examples/Beginner_start_here/Beginner_start_here.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Blob/Blob.ino b/examples/Blob/Blob.ino index 2bb58885..4b394db9 100644 --- a/examples/Blob/Blob.ino +++ b/examples/Blob/Blob.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Blynk/Blynk.ino b/examples/Blynk/Blynk.ino index df7a6903..72e0778e 100644 --- a/examples/Blynk/Blynk.ino +++ b/examples/Blynk/Blynk.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Cloud_Messaging/Cloud_Messaging.ino b/examples/Cloud_Messaging/Cloud_Messaging.ino index fa1c6cab..af2cfd28 100644 --- a/examples/Cloud_Messaging/Cloud_Messaging.ino +++ b/examples/Cloud_Messaging/Cloud_Messaging.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Data_filter/Data_filter.ino b/examples/Data_filter/Data_filter.ino index d745a8d2..b9681a8f 100644 --- a/examples/Data_filter/Data_filter.ino +++ b/examples/Data_filter/Data_filter.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Different_objects_stream/Different_objects_stream.ino b/examples/Different_objects_stream/Different_objects_stream.ino index be2390bf..ec07a866 100644 --- a/examples/Different_objects_stream/Different_objects_stream.ino +++ b/examples/Different_objects_stream/Different_objects_stream.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Dynamic_FirebaseData/Dynamic_FirebasseData.ino b/examples/Dynamic_FirebaseData/Dynamic_FirebasseData.ino index 73d9eeec..b1f51a06 100644 --- a/examples/Dynamic_FirebaseData/Dynamic_FirebasseData.ino +++ b/examples/Dynamic_FirebaseData/Dynamic_FirebasseData.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/ETag/ETag.ino b/examples/ETag/ETag.ino index 0a034b0b..1d7dd1b6 100644 --- a/examples/ETag/ETag.ino +++ b/examples/ETag/ETag.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/File/File.ino b/examples/File/File.ino index 2b3e1c11..e5034b59 100644 --- a/examples/File/File.ino +++ b/examples/File/File.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/File_flash_memory/File_flash_memory.ino b/examples/File_flash_memory/File_flash_memory.ino index 679a6e5e..3b8e6140 100644 --- a/examples/File_flash_memory/File_flash_memory.ino +++ b/examples/File_flash_memory/File_flash_memory.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/FirebaseJson/examples/basic/basic.ino b/examples/FirebaseJson/examples/basic/basic.ino index f802c746..003d8a03 100644 --- a/examples/FirebaseJson/examples/basic/basic.ino +++ b/examples/FirebaseJson/examples/basic/basic.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/FirebaseJson/examples/nest/nest.ino b/examples/FirebaseJson/examples/nest/nest.ino index f4e0f55d..de893722 100644 --- a/examples/FirebaseJson/examples/nest/nest.ino +++ b/examples/FirebaseJson/examples/nest/nest.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Get_set_database_rules/Get_set_database_rules.ino b/examples/Get_set_database_rules/Get_set_database_rules.ino index 0d05bebd..596f21dd 100644 --- a/examples/Get_set_database_rules/Get_set_database_rules.ino +++ b/examples/Get_set_database_rules/Get_set_database_rules.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Line_notify/Line_notify.ino b/examples/Line_notify/Line_notify.ino index 79802bca..4a279c0e 100644 --- a/examples/Line_notify/Line_notify.ino +++ b/examples/Line_notify/Line_notify.ino @@ -1,3 +1,4 @@ + /** * Created by K. Suwatchai (Mobizt) * @@ -5,17 +6,20 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ -//Example showed how to pause Firebase and use shared WiFi Client to send Line message. - -//Required Line Notify Library for ESP8266 https://github.com/mobizt/Line-Notify-ESP8266 +/* + * This shows how to pause the Firbase and send LINE Notify. + * Install Line Notify Arduino library for ESP8266 and ESP32 https://github.com/mobizt/ESP-Line-Notify + * + * More about Line Notify service https://notify-bot.line.me/en/ + */ #include #include -#include +#include #define WIFI_SSID "WIFI_AP" #define WIFI_PASSWORD "WIFI_PASSWORD" @@ -27,11 +31,8 @@ */ #define FIREBASE_AUTH "DATABASE_SECRET" -//Define Firebase Data object FirebaseData fbdo; -LineNotifyHTTPClient net; - String path = "/Test"; unsigned long sendDataPrevMillis = 0; @@ -40,6 +41,15 @@ unsigned long sendMessagePrevMillis = 0; uint16_t count = 0; +/* Define the LineNotifyClient object */ +LineNotiFyClient client; + +/* Function to print the sending result via Serial (optional) */ +void LineNotifyResult(LineNotifySendingResult result); + +/* The sending callback function (optional) */ +void LineNotifyCallback(LineNotifySendingResult result); + void printResult(FirebaseData &data); void setup() @@ -61,19 +71,9 @@ void setup() Serial.println(WiFi.localIP()); Serial.println(); - - lineNotify.init(&net, LINE_TOKEN); - - Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); Firebase.reconnectWiFi(true); - //Set the size of WiFi rx/tx buffers in the case where we want to work with large data. - fbdo.setBSSLBufferSize(1024, 1024); - - //Set the size of HTTP response buffers in the case where we want to work with large data. - fbdo.setResponseSize(1024); - Serial.println("------------------------------------"); Serial.println("Begin stream..."); if (!Firebase.beginStream(fbdo, path + "/Stream/String")) @@ -101,87 +101,49 @@ void loop() Serial.println("------------------------------------"); Serial.println("Set Data..."); - if (Firebase.set(fbdo, path + "/Stream/String", "Hello World! " + String(count))) + if (Firebase.setString(fbdo, path + "/Stream/String", "Hello World! " + String(count))) { Serial.println("PASSED"); Serial.println("PATH: " + fbdo.dataPath()); Serial.println("TYPE: " + fbdo.dataType()); Serial.print("VALUE: "); printResult(fbdo); - Serial.println("------------------------------------"); + Serial.println("--------------------------------"); Serial.println(); } else { Serial.println("FAILED"); Serial.println("REASON: " + fbdo.errorReason()); - Serial.println("------------------------------------"); + Serial.println("--------------------------------"); Serial.println(); } - if (fbdo.pauseFirebase(true)) - { + //pause Firebase + fbdo.pauseFirebase(true); - Serial.println("------------------------------------"); - Serial.println("Send Line Message..."); + Serial.println("------------------------------------"); - //Pause Firebase and use WiFiClient accessed through fbdo.http - uint8_t status = lineNotify.sendLineMessage("Instant sending message after call!"); - if (status == LineNotifyESP8266::LineStatus::SENT_COMPLETED) - { - Serial.println("send Line message completed"); - Serial.println("Text message limit: " + String(lineNotify.textMessageLimit())); - Serial.println("Text message remaining: " + String(lineNotify.textMessageRemaining())); - Serial.println("Image message limit: " + String(lineNotify.imageMessageLimit())); - Serial.println("Image message remaining: " + String(lineNotify.imageMessageRemaining())); - } - else if (status == LineNotifyESP8266::LineStatus::SENT_FAILED) - Serial.println("Send image data was failed!"); - else if (status == LineNotifyESP8266::LineStatus::CONNECTION_FAILED) - Serial.println("Connection to LINE sevice faild!"); - Serial.println(); + client.reconnect_wifi = true; - //Unpause Firebase - fbdo.pauseFirebase(false); - } - else - { - Serial.println("Could not pause Firebase"); - Serial.println(); - } - } + Serial.println("Sending Line Notify message..."); - if (millis() - sendMessagePrevMillis > 60000) - { - sendMessagePrevMillis = millis(); - if (fbdo.pauseFirebase(true)) - { + client.token = "Your Line Notify Access Token"; + client.message = "Hello world"; - Serial.println("------------------------------------"); - Serial.println("Send Line Message..."); + //Assign the Line Notify Sending Callback function. + client.sendingg_callback = LineNotifyCallback; - uint8_t status = lineNotify.sendLineMessage("Schedule message sending!"); - if (status == LineNotifyESP8266::LineStatus::SENT_COMPLETED) - { - Serial.println("send Line message completed"); - Serial.println("Text message limit: " + String(lineNotify.textMessageLimit())); - Serial.println("Text message remaining: " + String(lineNotify.textMessageRemaining())); - Serial.println("Image message limit: " + String(lineNotify.imageMessageLimit())); - Serial.println("Image message remaining: " + String(lineNotify.imageMessageRemaining())); - } - else if (status == LineNotifyESP8266::LineStatus::SENT_FAILED) - Serial.println("Send image data was failed!"); - else if (status == LineNotifyESP8266::LineStatus::CONNECTION_FAILED) - Serial.println("Connection to LINE sevice faild!"); - Serial.println(); + LineNotifySendingResult result = LineNotify.send(client); - //Unpause Firebase - fbdo.pauseFirebase(false); - } - else - { - Serial.println("Could not pause Firebase"); - } + //Print the Line Notify sending result. + LineNotifyResult(result); + + Serial.println("--------------------------------"); + Serial.println(); + + //resume Firebase + fbdo.pauseFirebase(false); } if (!Firebase.readStream(fbdo)) @@ -296,8 +258,52 @@ void printResult(FirebaseData &data) Serial.println(jsonData.stringValue); } } - else +} + +/* Function to print the sending result via Serial */ +void LineNotifyResult(LineNotifySendingResult result) +{ + if (result.status == LineNotify_Sending_Success) + { + Serial.printf("Status: %s\n", "success"); + Serial.printf("Text limit: %d\n", result.quota.text.limit); + Serial.printf("Text remaining: %d\n", result.quota.text.remaining); + Serial.printf("Image limit: %d\n", result.quota.image.limit); + Serial.printf("Image remaining: %d\n", result.quota.image.remaining); + Serial.printf("Reset: %d\n", result.quota.reset); + } + else if (result.status == LineNotify_Sending_Error) + { + Serial.printf("Status: %s\n", "error"); + Serial.printf("error code: %d\n", result.error.code); + Serial.printf("error msg: %s\n", result.error.message.c_str()); + } +} + +/* The sending callback function (optional) */ +void LineNotifyCallback(LineNotifySendingResult result) +{ + if (result.status == LineNotify_Sending_Begin) + { + Serial.println("Sending begin"); + } + else if (result.status == LineNotify_Sending_Upload) + { + Serial.printf("Uploaded %s, %d%s\n", result.file_name.c_str(), (int)result.progress, "%"); + } + else if (result.status == LineNotify_Sending_Success) + { + Serial.println("Sending success\n\n"); + Serial.printf("Text limit: %d\n", result.quota.text.limit); + Serial.printf("Text remaining: %d\n", result.quota.text.remaining); + Serial.printf("Image limit: %d\n", result.quota.image.limit); + Serial.printf("Image remaining: %d\n", result.quota.image.remaining); + Serial.printf("Reset: %d\n", result.quota.reset); + } + else if (result.status == LineNotify_Sending_Error) { - Serial.println(data.payload()); + Serial.println("Sending failed\n\n"); + Serial.printf("error code: %d\n", result.error.code); + Serial.printf("error msg: %s\n", result.error.message.c_str()); } } diff --git a/examples/MultiPath_stream/MultiPath_stream.ino b/examples/MultiPath_stream/MultiPath_stream.ino index 8908f500..5e9e2f8f 100644 --- a/examples/MultiPath_stream/MultiPath_stream.ino +++ b/examples/MultiPath_stream/MultiPath_stream.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Priority/Priority.ino b/examples/Priority/Priority.ino index cdbfd4bf..38d0897d 100644 --- a/examples/Priority/Priority.ino +++ b/examples/Priority/Priority.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Retry_and_queue/Retry_and_queue.ino b/examples/Retry_and_queue/Retry_and_queue.ino index 9e6c78c5..378231e1 100644 --- a/examples/Retry_and_queue/Retry_and_queue.ino +++ b/examples/Retry_and_queue/Retry_and_queue.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Shallowed_data/Shallowed_data.ino b/examples/Shallowed_data/Shallowed_data.ino index 7652bb46..49312e38 100644 --- a/examples/Shallowed_data/Shallowed_data.ino +++ b/examples/Shallowed_data/Shallowed_data.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Stream/Stream.ino b/examples/Stream/Stream.ino index 4a975b17..1d686d48 100644 --- a/examples/Stream/Stream.ino +++ b/examples/Stream/Stream.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Stream_callback/Stream_callback.ino b/examples/Stream_callback/Stream_callback.ino index f1598053..2235cc00 100644 --- a/examples/Stream_callback/Stream_callback.ino +++ b/examples/Stream_callback/Stream_callback.ino @@ -5,7 +5,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/Timestamp/Timestamp.ino b/examples/Timestamp/Timestamp.ino index 474acf18..c088341e 100644 --- a/examples/Timestamp/Timestamp.ino +++ b/examples/Timestamp/Timestamp.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/jsonArray/jsonArray.ino b/examples/jsonArray/jsonArray.ino index 0d4f6b60..948e6afd 100644 --- a/examples/jsonArray/jsonArray.ino +++ b/examples/jsonArray/jsonArray.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/examples/jsonObject/jsonObject.ino b/examples/jsonObject/jsonObject.ino index ec6f5f8d..4e02dfa8 100644 --- a/examples/jsonObject/jsonObject.ino +++ b/examples/jsonObject/jsonObject.ino @@ -6,7 +6,7 @@ * * Github: https://github.com/mobizt * - * Copyright (c) 2020 mobizt + * Copyright (c) 2021 mobizt * */ diff --git a/library.properties b/library.properties index f3ae188f..405d2dc3 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=Firebase ESP8266 Client -version=3.1.7 +version=3.1.8 author=Mobizt diff --git a/src/FirebaseESP8266.cpp b/src/FirebaseESP8266.cpp index ccfdc48f..4966cd55 100644 --- a/src/FirebaseESP8266.cpp +++ b/src/FirebaseESP8266.cpp @@ -1,10 +1,10 @@ /** - * Google's Firebase Realtime Database Arduino Library for ESP8266, version 3.1.8 + * Google's Firebase Realtime Database Arduino Library for ESP8266, version 3.1.9 * - * March 30, 2021 + * April 3, 2021 * * Updates: - * - Fix the pushArray, setArray and pathExist bugs. + * - Allows other Firebase calls inside the stream and multipath stream callback function. * * This library provides ESP8266 to perform REST API by GET PUT, POST, PATCH, DELETE data from/to with Google's Firebase database using get, set, update * and delete calls. diff --git a/src/FirebaseESP8266.h b/src/FirebaseESP8266.h index bcae2fdd..7e0b8975 100644 --- a/src/FirebaseESP8266.h +++ b/src/FirebaseESP8266.h @@ -1,10 +1,10 @@ /** - * Google's Firebase Realtime Database Arduino Library for ESP8266, version 3.1.7 + * Google's Firebase Realtime Database Arduino Library for ESP8266, version 3.1.8 * - * March 30, 2021 + * April 3, 2021 * * Updates: - * - Fix the pushArray, setArray and pathExist bugs. + * - Allows other Firebase calls inside the stream and multipath stream callback function. * * This library provides ESP8266 to perform REST API by GET PUT, POST, PATCH, DELETE data from/to with Google's Firebase database using get, set, update * and delete calls. diff --git a/src/README.md b/src/README.md index 3d593176..74e672a4 100644 --- a/src/README.md +++ b/src/README.md @@ -1,7 +1,7 @@ # Firebase Realtime Database Arduino Library for ESP8266 -Google's Firebase Realtime Database Arduino Library for ESP8266 v 3.1.7 +Google's Firebase Realtime Database Arduino Library for ESP8266 v 3.1.8 ## Global functions diff --git a/src/Utils.h b/src/Utils.h index f4b61181..af0881e0 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -1,9 +1,9 @@ /** - * Google's Firebase Util class, Utils.h version 1.0.8 + * Google's Firebase Util class, Utils.h version 1.0.9 * * This library supports Espressif ESP8266 and ESP32 * - * Created March 23, 2021 + * Created March 31, 2021 * * This work is a part of Firebase ESP Client library * Copyright (c) 2021 K. Suwatchai (Mobizt) @@ -1576,10 +1576,22 @@ class UtilsClass return (ob == cb && os == cs); } + bool ethLinkUp() + { + bool ret = false; +#if defined(ESP32) + char *ip = strP(fb_esp_pgm_str_548); + if (strcmp(ETH.localIP().toString().c_str(), ip) != 0) + ret = ETH.linkUp(); + delS(ip); +#endif + return ret; + } + bool reconnect(unsigned long dataTime) { - bool status = WiFi.status() == WL_CONNECTED; + bool status = WiFi.status() == WL_CONNECTED || ethLinkUp(); if (dataTime > 0) { @@ -1599,7 +1611,7 @@ class UtilsClass } } - status = WiFi.status() == WL_CONNECTED; + status = WiFi.status() == WL_CONNECTED || ethLinkUp(); } return status; diff --git a/src/rtdb/FB_RTDB.cpp b/src/rtdb/FB_RTDB.cpp index e9917b83..940ca2b4 100644 --- a/src/rtdb/FB_RTDB.cpp +++ b/src/rtdb/FB_RTDB.cpp @@ -1,9 +1,9 @@ /** - * Google's Firebase Realtime Database class, FB_RTDB.cpp version 1.0.8 + * Google's Firebase Realtime Database class, FB_RTDB.cpp version 1.0.9 * * This library supports Espressif ESP8266 and ESP32 * - * Created March 30, 2021 + * Created April 3, 2021 * * This work is a part of Firebase ESP Client library * Copyright (c) 2021 K. Suwatchai (Mobizt) @@ -3625,11 +3625,15 @@ int FB_RTDB::sendRequest(FirebaseData *fbdo, struct fb_esp_rtdb_request_info_t * bool FB_RTDB::waitResponse(FirebaseData *fbdo) { #if defined(ESP32) + + //if currently perform stream payload handling process, skip it. if (Signer.getCfg()->_int.fb_processing && fbdo->_ss.con_mode == fb_esp_con_mode_rtdb_stream) return true; - + + //set the blocking flag Signer.getCfg()->_int.fb_processing = true; bool ret = handleResponse(fbdo); + //reset the blocking flag Signer.getCfg()->_int.fb_processing = false; return ret; @@ -4272,6 +4276,9 @@ bool FB_RTDB::handleResponse(FirebaseData *fbdo) void FB_RTDB::sendCB(FirebaseData *fbdo) { + //to allow other subsequence request which can be occurred in the user stream callback + Signer.getCfg()->_int.fb_processing = false; + if (fbdo->_dataAvailableCallback) { StreamData s; @@ -4290,7 +4297,7 @@ void FB_RTDB::sendCB(FirebaseData *fbdo) if (fbdo->_ss.rtdb.resp_data_type == fb_esp_data_type::d_blob) { s.sif->blob = fbdo->_ss.rtdb.blob; - //Free ram in case of the callback data was used + //Free memory in case of the callback blob data was used fbdo->_ss.rtdb.blob.clear(); } fbdo->_dataAvailableCallback(s); diff --git a/src/rtdb/FB_RTDB.h b/src/rtdb/FB_RTDB.h index 2befc763..ccce6f27 100644 --- a/src/rtdb/FB_RTDB.h +++ b/src/rtdb/FB_RTDB.h @@ -1,9 +1,9 @@ /** - * Google's Firebase Realtime Database class, FB_RTDB.h version 1.0.8 + * Google's Firebase Realtime Database class, FB_RTDB.h version 1.0.9 * * This library supports Espressif ESP8266 and ESP32 * - * Created March 30, 2021 + * Created April 3, 2021 * * This work is a part of Firebase ESP Client library * Copyright (c) 2021 K. Suwatchai (Mobizt) diff --git a/src/session/FB_Session.cpp b/src/session/FB_Session.cpp index e7f61bf4..ed8179c6 100644 --- a/src/session/FB_Session.cpp +++ b/src/session/FB_Session.cpp @@ -1,9 +1,9 @@ /** - * Google's Firebase Data class, FB_Session.cpp version 1.0.6 + * Google's Firebase Data class, FB_Session.cpp version 1.0.7 * * This library supports Espressif ESP8266 and ESP32 * - * Created March 29, 2021 + * Created March 31, 2021 * * This work is a part of Firebase ESP Client library * Copyright (c) 2021 K. Suwatchai (Mobizt) @@ -115,7 +115,7 @@ void FirebaseData::setResponseSize(uint16_t len) bool FirebaseData::pauseFirebase(bool pause) { - if (WiFi.status() != WL_CONNECTED) + if (WiFi.status() != WL_CONNECTED && !ut->ethLinkUp()) return false; if (httpClient.connected() && pause != _ss.rtdb.pause) @@ -561,7 +561,7 @@ int FirebaseData::httpCode() void FirebaseData::closeSession() { - if (WiFi.status() == WL_CONNECTED) + if (WiFi.status() == WL_CONNECTED || !ut->ethLinkUp()) { //close the socket and free the resources used by the BearSSL data if (_ss.connected || httpClient.stream()) @@ -585,7 +585,7 @@ void FirebaseData::closeSession() bool FirebaseData::reconnect(unsigned long dataTime) { - bool status = WiFi.status() == WL_CONNECTED; + bool status = WiFi.status() == WL_CONNECTED || ut->ethLinkUp(); if (dataTime > 0) { @@ -616,7 +616,7 @@ bool FirebaseData::reconnect(unsigned long dataTime) } } - status = WiFi.status() == WL_CONNECTED; + status = WiFi.status() == WL_CONNECTED || ut->ethLinkUp(); } return status; diff --git a/src/session/FB_Session.h b/src/session/FB_Session.h index e4db57f7..c728ff02 100644 --- a/src/session/FB_Session.h +++ b/src/session/FB_Session.h @@ -1,9 +1,9 @@ /** - * Google's Firebase Data class, FB_Session.h version 1.0.6 + * Google's Firebase Data class, FB_Session.h version 1.0.7 * * This library supports Espressif ESP8266 and ESP32 * - * Created March 29, 2021 + * Created March 31, 2021 * * This work is a part of Firebase ESP Client library * Copyright (c) 2021 K. Suwatchai (Mobizt) diff --git a/src/signer/Signer.cpp b/src/signer/Signer.cpp index 70bf552c..649764c9 100644 --- a/src/signer/Signer.cpp +++ b/src/signer/Signer.cpp @@ -1,9 +1,9 @@ /** - * Google's Firebase Token Generation class, Signer.cpp version 1.0.6 + * Google's Firebase Token Generation class, Signer.cpp version 1.0.7 * * This library supports Espressif ESP8266 and ESP32 * - * Created March 25, 2021 + * Created March 31, 2021 * * This work is a part of Firebase ESP Client library * Copyright (c) 2021 K. Suwatchai (Mobizt) @@ -474,7 +474,7 @@ bool Firebase_Signer::refreshToken() if (config->_int.fb_reconnect_wifi) ut->reconnect(0); - if (WiFi.status() != WL_CONNECTED) + if (WiFi.status() != WL_CONNECTED && !ut->ethLinkUp()) return false; delay(0); @@ -766,7 +766,7 @@ bool Firebase_Signer::handleTokenResponse() if (config->_int.fb_reconnect_wifi) ut->reconnect(0); - if (WiFi.status() != WL_CONNECTED) + if (WiFi.status() != WL_CONNECTED && !ut->ethLinkUp()) return false; struct server_response_data_t response; @@ -825,7 +825,7 @@ bool Firebase_Signer::handleTokenResponse() if (config->_int.fb_reconnect_wifi) ut->reconnect(0); - if (WiFi.status() != WL_CONNECTED) + if (WiFi.status() != WL_CONNECTED && !ut->ethLinkUp()) { if (stream) if (stream->connected()) @@ -1286,7 +1286,7 @@ bool Firebase_Signer::getIdToken(bool createUser, const char *email, const char if (config->_int.fb_reconnect_wifi) ut->reconnect(0); - if (WiFi.status() != WL_CONNECTED) + if (WiFi.status() != WL_CONNECTED && !ut->ethLinkUp()) return false; config->signer.signup = false; @@ -1485,7 +1485,7 @@ bool Firebase_Signer::requestTokens() if (config->_int.fb_reconnect_wifi) ut->reconnect(0); - if (WiFi.status() != WL_CONNECTED) + if (WiFi.status() != WL_CONNECTED && !ut->ethLinkUp()) return false; delay(0); @@ -1674,7 +1674,7 @@ bool Firebase_Signer::handleEmailSending(const char *payload, fb_esp_user_email_ if (config->_int.fb_reconnect_wifi) ut->reconnect(0); - if (WiFi.status() != WL_CONNECTED) + if (WiFi.status() != WL_CONNECTED && !ut->ethLinkUp()) return false; delay(0); diff --git a/src/signer/Signer.h b/src/signer/Signer.h index d482f6f2..58310932 100644 --- a/src/signer/Signer.h +++ b/src/signer/Signer.h @@ -1,9 +1,9 @@ /** - * Google's Firebase Token Generation class, Signer.h version 1.0.6 + * Google's Firebase Token Generation class, Signer.h version 1.0.7 * * This library supports Espressif ESP8266 and ESP32 * - * Created March 25, 2021 + * Created March 31, 2021 * * This work is a part of Firebase ESP Client library * Copyright (c) 2020, 2021 K. Suwatchai (Mobizt)