Documentación disponible en español
Project created for Hacktoberfest 2022 to showcase how to use an Arduino (specifically an ESP8266) to retrieve data from an Appwrite Server. It includes an app that you can use to set the color.
To install this project, you will need:
- Yarn, the package manager
- A development environment compatible with Arduino IDE
- An Appwrite server
- An ESP8266, or equivalent, microchip.
And, if you plan to host this publicly
- A Railway account to trigger Appwrite function calls from a URL
After cloning this repository, you'll need to install its dependencies. I recommend doing it through Yarn, as the project uses Yarn workspaces. Install the dependencies by running:
yarnWithin Appwrite you'll need to create three things:
- A Project
- A Database
- A Collection
- A Function
Note: You might not need to use the appwrite function if executing this locally. I decided to use this as my endpoint is hosted within Vercel, which enforces HTTPS on all its web resources. Using HTTPs on an Arduino is hard. So if you're self hosting, or if you're hosting this on another server, you should be able to skip all the steps related to the Appwrite function and get the current colour through the Next.js getColour endpoint instead.
Save the ID for each one of these elements you just created, as we'll be using them in the following steps.
You'll also need to create an appwrite.json file. You can create one based on the appwrite.example.json file in the packages/functions directory.
Once you have created them, you can change the values for <ProjectId>, <CollectionId>, and <DatabaseId> into the ones you created previously. Once you have replaced these values, you can deploy the collection to your server by using:
cd packages/functions
appwrite deploy collectionsOnce deployed, you can deploy our Appwrite function to your server. You can use the helper script I've included in the packages/functions/package.json file. To execute it, first replace <Your-Function-Id> within that file with a proper value. Then run it using:
# If running this command from within the root of your project
yarn workspace functions run deploy
# Or if running it from within packages/functions
yarn run deployOr you can also deploy the function manually by using:
appwrite functions createDeployment --functionId=<Your-Function-Id> --activate=true --entrypoint='src/getColor.js' --code='.'Let's now set up our environment variables for both Next.js and our Appwrite function.
Note: In my deployment I used the same API key for both environments.
Copy the .env.local.example file included in the packages/frontend folder, and use it as a template for a new .env.local file within that same directory. This new file should have the following values:
| Value | Description | Example |
|---|---|---|
| APPWRITE_HOSTNAME | The URL for your project's API endpoint. | https://api.example.com/v1 |
| APPWRITE_PROJECTID | Your Project ID generated by Appwrite. You can get it from Your Project > Settings > Project ID (Screenshot) |
- |
| APPWRITE_APIKEY | An API Key with permissions for documents.read, documents.write, and execution.write. (api key permissions) |
- |
| APPWRITE_DATABASE_ID | The ID of a Database within your project (Screenshot) | - |
| APPWRITE_COLLECTION_ID | The ID of a collection that exists within your Database (Screenshot) | - |
Similar to the previous step, you'll need to set up the environment variables for your Appwrite function. Do so through your Appwrite Web interface by navigating to Your project > Functions > Your function's settings > Variables > Add variable. Add each one of the following values:
| Value | Description | Example |
|---|---|---|
| APPWRITE_HOSTNAME | The API route for your project's endpoint. | https://api.example.com/v1 |
| APPWRITE_APIKEY | An API Key with permissions for documents.read, documents.write, and execution.write. (api key permissions) |
- |
| APPWRITE_DATABASE_ID | The ID of a Database within your project (Screenshot) | - |
| APPWRITE_COLLECTION_ID | The ID of a collection that exists within your Database (Screenshot) | - |