setting up simple Firebase database
Following some getting started webpages and a the tutorial video at the end, it was very simple to set up a webpage which can write to the database I made, save new fields, read fields when prompted, and then also lead new values in real time !!![webpage app talking to firebase database](./firebase_hello.jpg)
it's set up as an open database so anyone could access it for 30 days, which is why I didn't need to fuss with authentication of client and what not ~ this is what I'll do for the final cause it's not like I have super sensitive data anyway.
next up, I want to get the BNO055 sensor data saved to the firebase database and load it onto the hellowold page.
I think I should be able to send requests to firebase the same way that I was with the dweet from the esp32.
here are all of the API endpoint for the CLoud Firestore API ~ I just don't know how to choose between v1beta1, v1beta2, or v1. . . well, I'm on the right path cause posting from IoT devices is a use case for directly communicating with cloud firestore REST APIs! here
Note, there are error code that mean different things base on how well the data is being sent back - in final project, map these into LED signals from the chip to make sure that data is being sent out properly.
here's documentation on how to write to a firestore document.
making a new platfomio project for testing the ESP32 with firebase: esp32_firebase.
the platformio environment needs the following library dependencies:
- platformio lib install 31
- platformio lib install 506
- platformio lib install 798
I was running into a lot of errors trying to send a submit a http request from the ESP32. to identify exactly what's going on a tried a couple different ways of subnmitting requests.
Google has a API explorer in their RESP documentation that let me send messages following their preformatted input. I could successfully create documents and add field values and have those show up in the web app.
I tried sending the same message format to the ESP32, but was getting a generic 400 error. so I tested the request from curl because the API explorer included Google OAuth tokens, but these shouldn't matter for my databse becuase I have all the security turned off so I should be able to write to it from anything. I was right, it wasn't a permissions error because I could submit via curl without any special headers
![submit document with curl](./curl_test.jpg)
I tried to rewriting the http client from the esp32 code because the generic 400 error code is usually just a typo and hard to pin point, and finally I'm getting an error that I can work with . . .
![ssl error](./ssl_error.jpg)
the database can only receive requests from a device with SSL certificate. I need to use theSecure wifi library to connect, not the normal http. pulling form this tutorial
This looks like it's a much harder problem that I had been expecting . . . but at least well documented, article explaining ESP32 over secure encryption here.
ahhhh I just spent hours trying to solve this ssl error and the actual problem was that I was sending the request through port 80 which is plain text TCP port instead of the encrypted one 443. thank you medium article for giving a bit of background on all this stuff.
so I can get the esp32 sending data to firebase once, but then it fails on the second post every time. This seems ot be a known issue. Again, definitely a known issue with the esp32 specifically, similar problem
So, the problem can be solved by closing the wifi client after each request. I finally have data streaming from the ESP32 to my webpage!!
but it's really slow. because it's closing and reopening the wifi client for each request.
Brian shared this Firebase arduino library with me ~ which I now feel very dumb for not finding in the first place and potentially ahving wasted and entire day debugging https errors that never needed to be ahd in the first place :///
I'm going to spin up a quick helloworld with this library and see if it's faster at updating. If not, then I'll look in to sending more than one position per http post and maybe opening more than one http server client to send data more often . . .
yep . . . I wasted a day on http requests and SSL certificates. . . this library can very easily and very efficiently write to the firebase database. It's not the cloud firstore database that I had been using before, it's the older version of it! but I got it working and sending position data close enough to real time
OK, next step - time to get the actual UI set up.