Library for Firebase, PUT, PATCH, POST, GET, DELETE operations supported, (others are available, todo). Based on Mbed's https-example. Tested on STM32F767 using ETHERNET and ESP8266 WIFI interfaces and STM32F446 using ESP8266 WIFI interface.
Revision 3:4d7c08734a91, committed 2020-05-10
- Comitter:
- star297
- Date:
- Sun May 10 08:08:23 2020 +0000
- Parent:
- 2:cde6181a8320
- Commit message:
- added PATCH function
Changed in this revision
| Firebase.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Firebase.h Sun Mar 08 14:49:02 2020 +0000
+++ b/Firebase.h Sun May 10 08:08:23 2020 +0000
@@ -50,12 +50,13 @@
strcat(FirebaseUrl, FirebaseAuth); // Firebase account authorisation key
*/
-/*
+
// set Firebase project information..
char FirebaseUrl[300]; // dimension to suit required character space
const char FirebaseID[100] = "https://projectID.firebaseio.com"; // project ID
const char FirebaseAuth[100]= "Web API key"; // web API key
-*/
+
+
char* getData;
int TLSfailText,httpfail;
@@ -154,6 +155,31 @@
}
}
+bool patchFirebase(char* FirebaseUrl, char *stringToProcess)
+{
+ //HttpsRequest* patch_req = new HttpsRequest(net, SSL_CA_PEM, HTTP_PATCH, FirebaseUrl); // non socket reuse function
+ HttpsRequest* patch_req = new HttpsRequest(socket, HTTP_PATCH, FirebaseUrl); // socket reuse function
+ patch_req->set_header("Content-Type", "application/json");
+ HttpResponse* patch_res = patch_req->send(stringToProcess, strlen(stringToProcess));
+ if (!patch_res) {
+ time_t seconds = time(NULL);
+ printf("Https PATCH failed (error code %d), %s", patch_req->get_error(), ctime(&seconds));
+ socket->close();
+ delete socket;
+ delete patch_req;
+ TLSSocket* socket = new TLSSocket();
+ startTLSreusesocket((char*)FirebaseID); // restart TLS reuse socket if failure
+ TLSfailText++;
+ httpfail=1;
+ return 0;
+ }
+ else{
+ // dump_response(put_res);
+ delete patch_req;
+ return patch_res;
+ }
+}
+
bool putFirebase(char* FirebaseUrl, char *stringToProcess)
{
//HttpsRequest* put_req = new HttpsRequest(net, SSL_CA_PEM, HTTP_PUT, FirebaseUrl); // non socket reuse function