$ cd firebase_directory$ firebase login
i Firebase optionally collects CLI and Emulator Suite usage and error reporting information to help improve our products. Data is collected in accordance with Google's privacy policy (https://policies.google.com/privacy) and is not used to identify you.
? Allow Firebase to collect CLI and Emulator Suite usage and error reporting information? Yes
i To change your data collection preference at any time, run `firebase logout` and log in again.
Visit this URL on this device to log in:
Waiting for authentication...
✔ Success! Logged in as xxx@gmail.com
初期化コマンドを入力し、それぞれの質問に回答します。
% firebase init functions
######## #### ######## ######## ######## ### ###### ########
## ## ## ## ## ## ## ## ## ## ##
###### ## ######## ###### ######## ######### ###### ######
## ## ## ## ## ## ## ## ## ## ##
## #### ## ## ######## ######## ## ## ###### ########
You're about to initialize a Firebase project in this directory:
/Users/user/firebase
=== Project Setup
First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.
? Please select an option: Use an existing project
? Select a default Firebase project for this directory: temperature-measurement---test (Temperature measurement - test)
i Using project temperature-measurement---test (Temperature measurement - test)
=== Functions Setup
Let's create a new codebase for your functions.
A directory corresponding to the codebase will be created in your project
with sample code pre-configured.
See https://firebase.google.com/docs/functions/organize-functions for
more information on organizing your functions using codebases.
Functions can be deployed with firebase deploy.
? What language would you like to use to write Cloud Functions? JavaScript
? Do you want to use ESLint to catch probable bugs and enforce style? Yes
✔ Wrote functions/package.json
✔ Wrote functions/.eslintrc.js
✔ Wrote functions/index.js
✔ Wrote functions/.gitignore
? Do you want to install dependencies with npm now? Yes
added 588 packages, and audited 589 packages in 58s
66 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
i Writing configuration info to firebase.json...
i Writing project information to .firebaserc...
i Writing gitignore file to .gitignore...
✔ Firebase initialization complete!
$ firebase deploy --only functions
=== Deploying to 'temperature-measurement---test'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> lint
> eslint .
✔ functions: Finished running predeploy script.
i functions: preparing codebase default for deployment
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔ functions: required API cloudbuild.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
✔ artifactregistry: required API artifactregistry.googleapis.com is enabled
i functions: Loading and analyzing source code for codebase default to determine what to deploy
Serving at port 8504
i functions: preparing functions directory for uploading...
i functions: packaged /Users/user/program/firebase/functions (146.31 KB) for uploading
i functions: ensuring required API run.googleapis.com is enabled...
i functions: ensuring required API eventarc.googleapis.com is enabled...
i functions: ensuring required API pubsub.googleapis.com is enabled...
i functions: ensuring required API storage.googleapis.com is enabled...
✔ functions: required API eventarc.googleapis.com is enabled
✔ functions: required API pubsub.googleapis.com is enabled
✔ functions: required API run.googleapis.com is enabled
✔ functions: required API storage.googleapis.com is enabled
i functions: generating the service identity for pubsub.googleapis.com...
i functions: generating the service identity for eventarc.googleapis.com...
✔ functions: functions folder uploaded successfully
i functions: updating Node.js 18 (2nd Gen) function xxx(us-central1)...
✔ functions[xxx(us-central1)] Successful update operation.
Function URL (xxx(us-central1)): https://xxx-pfv42ema6a-uc.a.run.app
i functions: cleaning up build files...
✔ Deploy complete!
Project Console: https://console.firebase.google.com/project/temperature-measurement---test/overview
$ ampy --port /dev/tty.usbserial-0001 run /Users/user/micropython/main.py
unique_id : 08d1f9e822ec
mac_id type : <class 'str'>
mac_id : 08d1f9e822ec
Found DS18B20 sensors: [bytearray(b'(\xf5\tC\xd4\xe1<7')]
rom : bytearray(b'(\xf5\tC\xd4\xe1<7')
temperature : 25.0 度
temperature type : <class 'float'>
temperature : 25.0
Wi-Fiに接続しました
Sending payload: {'macAddress': '08d1f9e822ec', 'temperature': 25.0}
Data sent. Response: {'error': 'Invalid input: Temperature is not a number'}
{
"error": "7 PERMISSION_DENIED: Cloud Firestore API has not been used in project temperature-measurement---test before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/firestore.googleapis.com/overview?xxx then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."
}
conda install -c conda-forge firebase-admin
Channels:
- conda-forge
- defaults
Platform: osx-arm64
Collecting package metadata (repodata.json): done
Solving environment: failed
PackagesNotFoundError: The following packages are not available from current channels:
- firebase-admin
Current channels:
- https://conda.anaconda.org/conda-forge
- defaults
To search for alternate channels that may provide the conda package you're
looking for, navigate to
✔ functions: Loaded functions definitions from source: xxx.
✔ functions[us-central1-xxx]: http function initialized (http://127.0.0.1:5001/xxx/us-central1/xxx).
上記より取得したCloud Run URL、「http://127.0.0.1:5001/xxx/us-central1/xxx」をPythonプログラムに追加します。それで試すと、
Sending payload: {'temperature': 29.5, 'macAddress': '08d1f9e822ec'}
Data sent. Response: {'error': 'error: 7, 7 PERMISSION_DENIED: Cloud Firestore API has not been used in project xxx before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/firestore.googleapis.com/overview?project=temperature-measurement-b3fcd then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.'}
というエラーが出ました。ここでAPIの設定を行ってリトライします。
Sending payload: {'temperature': 29.5, 'macAddress': '08d1f9e822ec'}
Data sent. Response: {'error': 'error: 5, 5 NOT_FOUND: The database (default) does not exist for project temperature-measurement-b3fcd Please visit https://console.cloud.google.com/datastore/setup?project=xxx to add a Cloud Datastore or Cloud Firestore database. '}
$ firebase deployi functions: Loading and analyzing source code for codebase default to determine what to deploy
Serving at port 8225i functions: updating Node.js 18 (2nd Gen) function addTemperatureData(us-central1)...
Could not create or update Cloud Run service addtemperaturedata, Container Healthcheck failed. Revision 'addtemperaturedata-00003-geb' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.Logs URL: https://console.cloud.google.com/...
For more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-startFunctions deploy had errors with the following functions:
xxx(us-central1)
i functions: cleaning up build files...Error: There was an error deploying functions
emulators: The Emulator UI is not starting, either because none of the running emulators have a UI component or the Emulator UI cannot determine the Project ID. Pass the --project flag to specify a project.
$ firebase emulators:start
i emulators: Starting emulators: functions, firestore, database, hosting, extensions
⚠ firestore: Port 8080 is not open on localhost (127.0.0.1,::1), could not start Firestore Emulator.
⚠ firestore: To select a different host/port, specify that host/port in a firebase.json config file:
{
// ...
"emulators": {
"firestore": {
"host": "HOST",
"port": "PORT"
}
}
}
i emulators: Shutting down emulators.
⚠ ui: Emulator UI unable to start on port 4000, starting on 4001 instead.
⚠ hosting: Hosting Emulator unable to start on port 5000, starting on 5002 instead.Error: Could not start Firestore Emulator, port taken.