Issue with using micropython-firebase-firestore on Raspberry Pi Pico W

192 views Asked by At

I'm trying to use micropython-firebase-firestore library on my tiny Raspberry Pi Pico W microcontroller. And I have an issue with writing data on the Firestore database. I created the Firestore database and configured auth parameters. When I create the code for auth and read, I can successfully read data from Firestore database. But when I want to create new field or change the fields with firestore.get or firestore.patch command, I got an error on my code. I put the error message and my code below. Please help me about the solving this problem.

My Code:

import os
import network
import time
import ufirestore as firestore
from ufirestore.json import FirebaseJson
from firebase_auth import FirebaseAuth
from firebase_auth.firebase_auth import AuthSession

SSID = "WIFI"
password = "PASS"
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
    wlan.connect(SSID, password)
    print("Connecting to Wifi", end="...")
    while not wlan.isconnected():
        print(".", end="")
        time.sleep(1)
        print()

print("Wifi SSID: ", SSID , "IP: ", wlan.ifconfig()[0])

firestore.set_project_id("PROJECT_ID")

auth = FirebaseAuth("API_KEY")
print("Auth complete!")
auth.sign_in("MAIL", "PASS")
print("Sign in complete!")
print(auth.user)


firestore.set_access_token(auth.session.access_token)
print("Access token created!")
#====================================================================================
raw_doc = firestore.get("collection1/document1")
print("raw_doc : ", raw_doc)

doc = FirebaseJson.from_raw(raw_doc)

if doc["fields"].exists("value0"):
    print("The field value is: %s" % doc["fields"].get("value0"))
else:
    print("No Data!")
#====================================================================================

#============================ISSUE============================================
doc2 = FirebaseJson()
doc2.set("value1/stringValue", "Hello World!")

response = firestore.patch("collection1/document1", doc2, ["value1"], False)
print("Updated!")
#============================ISSUE============================================

auth.sign_out()

Error Messages:

Traceback (most recent call last):
  File "<stdin>", line 50, in <module>
  File "/lib/ufirestore/ufirestore.py", line 212, in patch
  File "/lib/ufirestore/ufirestore.py", line 75, in patch
  File "/lib/ufirestore/ufirestore.py", line 51, in send_request
  File "urequests.py", line 104, in request
AssertionError: 

I tried many ways to solve problem like changing the inside of "doc2.set()" and firestore.patch()

0

There are 0 answers