You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/courses/hello-world/1.5-data-logging.md
+23-77
Original file line number
Diff line number
Diff line change
@@ -27,111 +27,54 @@ Chemistry and materials research data is precious. By making your data **F**inda
27
27
28
28
For storing our data, we will be using [MongoDB](https://www.mongodb.com/), a popular ["NoSQL"](https://www.mongodb.com/nosql-explained) database. It's important to note that MongoDB is just one of many excellent choices for databases (e.g., [PostgreSQL](https://www.postgresql.org/) for relational databases, which can be [hosted via AWS](https://aws.amazon.com/rds/postgresql/), and [Neo4j](https://neo4j.com/) for graph-based databases). MongoDB is a document-oriented database, which means it stores data in JSON-like documents. MongoDB is a popular choice for internet-of-things (IoT) applications due to its ease of setup, use, and scalability. Unfortunately, MongoDB Atlas suddenly deprecated their [Data API](https://docs.atlas.mongodb.com/data-api/) that allowed for direct reading and writing of data from devices like microcontrollers. Instead, we'll use something called AWS Lambda as an intermediary. AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers. It's a nice choice for creating lightweight APIs and handling intermittent requests, which works well for our microcontroller application.
29
29
30
-
For the purposes of this tutorial, we have set up a free-tier test database through MongoDB Atlas and an AWS Lambda function. We provide the necessary credentials which would normally be kept private. To prevent potential misuse from distributing a public API key (which is generally not a good practice), we have granted only write permissions for this tutorial, and the database is configured to automatically delete entries once a certain storage threshold is reached. The [companion notebook](./1.5.1-pymongo.ipynb) has a similar setup, where only read permissions are granted.
30
+
For the purposes of this tutorial, we have set up a free-tier test database through MongoDB Atlas and an AWS Lambda function. We provide the necessary credentials which would normally be kept private. To prevent potential misuse from distributing a public API key (which is generally not a good practice), we have granted only write permissions for this tutorial, and the database is configured to automatically delete entries once a certain storage threshold is reached. The [companion notebook](./1.5.1-pymongo.ipynb) has a similar setup, where only read permissions are granted, which you will run later.
31
31
32
-
✅ Copy the following code into a new file on the microcontroller called `write_mongodb.py` and run the file. Note that you will need [`netman.py`](https://github.com/sparks-baird/self-driving-lab-demo/blob/main/src/public_mqtt_sdl_demo/lib/netman.py)[[permalink](https://github.com/sparks-baird/self-driving-lab-demo/blob/0ff0adec3e997c096990de594844d73a9ce18fd6/src/public_mqtt_sdl_demo/lib/netman.py)] and a file named `my_secrets.py` with your WiFi credentials, course ID, and Lambda function URL.
32
+
✅ Copy the following code into a new file on the microcontroller called `write_mongodb.py` and run the file. Note that you will need [`netman.py`](https://github.com/sparks-baird/self-driving-lab-demo/blob/main/src/public_mqtt_sdl_demo/lib/netman.py)[[permalink](https://github.com/sparks-baird/self-driving-lab-demo/blob/0ff0adec3e997c096990de594844d73a9ce18fd6/src/public_mqtt_sdl_demo/lib/netman.py)] and a file named `my_secrets.py` with your WiFi credentials, course ID, and the Lambda function URL (see [[1](https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html)] and [[2](https://docs.aws.amazon.com/lambda/latest/dg/python-handler.html)]) you'll be using. For this tutorial, a function URL is provided for you. You will need to create your own for the assignment.
✅ Run the code from [the companion notebook](./1.5.1-pymongo.ipynb) to read data from a MongoDB database. Note that this also has a section about how to upload data via PyMongo (preferred when you're able to install PyMongo on e.g., a Raspberry Pi 5 or a Windows machine, which wasn't possible for the Pico W microcontroller).
133
-
134
-
<!-- ✅ Copy the following code into a new file called `read_mongodb.py`and run it on the microcontroller. -->
77
+
✅ Run the code from [the companion notebook](./1.5.1-pymongo.ipynb) to read data from a MongoDB database. Note that this companion notebook also has a section about how to upload data via PyMongo (preferred when you're able to install PyMongo on e.g., a Raspberry Pi 5 or a Windows machine, which wasn't possible for the Pico W microcontroller). That way, you wouldn't need to use AWS Lambda as an intermediate layer.
135
78
136
79
### Reading Material
137
80
@@ -150,6 +93,9 @@ The output should look something like the following (MAC address and IP address
150
93
- [@sgbaird's list of materials databases](https://github.com/stars/sgbaird/lists/materials-databases)
151
94
- Misc. [`awesome-materials-informatics`](https://github.com/tilde-lab/awesome-materials-informatics) (search for"database"), [`Materials-Databases` (no longer maintained)](https://github.com/blaiszik/Materials-Databases), [`awesome-chemistry-datasets`](https://github.com/kjappelbaum/awesome-chemistry-datasets)
152
95
- [`awesome-self-driving-labs` research data management section](https://github.com/AccelerationConsortium/awesome-self-driving-labs#research-data-management)
96
+
- [Create simple REST API (GET&POST method) withAWS Lambda Function URL](https://medium.com/@g.bharthvajan/create-simple-get-post-rest-api-with-aws-lambda-function-url-7fa962197fa8)
97
+
- [Access json request from python in python AWSlambda function](https://stackoverflow.com/questions/63310567/access-json-request-from-python-in-python-aws-lambda-function)
98
+
- [Insert Python Dictionary in PostgreSQL using Psycopg2](https://www.geeksforgeeks.org/insert-python-dictionary-in-postgresql-using-psycopg2/)
153
99
154
100
As a side note, MongoDB has a "serverless" option (i.e., pay only for what you use) that exceeds the free-tier limits andis more flexible than the shared and dedicated clusters, which may seem appealing at first. HOWEVER, [costs will escalate quickly if the database isnot optimized](https://www.mongodb.com/developer/products/atlas/serverless-instances-billing-optimize-bill-indexing/) (e.g., the database isnot indexed). If you decide to go with MongoDB Atlas for a project and need more than the 512MB of free-tier storage, we recommend first considering the shared (e.g., M2, M5) and dedicated options, hosting your own MongoDB instance, or looking to other ecosystems. Beware of serverless. Looking to other ecosystems could be either a full replacement or a supplement (e.g., using AWSfor storing large files and adding links to those files into MongoDB).
0 commit comments