This tutorial focus on helping the reader to connect your own coffee machine with an Android app. The project can be divided into three modules to specify the components required to develop it:
Android app: the user is able to control the coffee machine using an Android app (which code will be provided over this tutorial) connected to an AWS server.
- Requests manager: the requests made to AWS through the Android app are handled by a DragonBoard 410c and then transferred to the hardware control through Bluetooth Low Energy.
- Hardware control: this information is sent to the development board CSR1011 which controls a Mondial Coffee Machine C-08 and receives data from three sensors: water level, infrared and ultrasonic.
By following the next steps, you will be able to reproduce the project with your own coffee machine.
- The communication between app and DragonBoard 410c uses the protocol MQTT. Understanding this protocol is essential to understand the system operation.
- The minimum API required to run the app is 21, which means that devices under Android 5.0 will not be able to run it.
Step 1: Connecting the Android App to AWS
To create an Android app to communicate through AWS, please follow this instructable. It will guide you through the process of creating an Android app and setting your development environment to work with the AWS mobile SDK for Android. But instead of creating a new app, for this project, you can use the source code provided on the next steps. Follow them to download and import the Android project:
- Download the coffee machine Android project available at the end of this step.
- Open the Android Studio.
- If a project is already opened, click on File -> Close Project.
- Click on "Import project (Eclipse ADT, Gradle, etc.)".
- Select the downloaded project.
- Click on "OK".
After importing the project:
- Open the structure in the Project view.
- Go to the directory app/src/main/java/com/machine/coffee/Controller.
- Double-click the class AWSConnection to open it.
- Find the variables CUSTOMER_SPECIFIC_ENDPOINT, COGNITO_POOL_ID, AWS_IOT_POLICY_NAME and MY_REGION and set them according to the data provided on your Amazon account after setting the identity pool with Amazon Cognito.
By doing this steps your application is ready to communicate through AWS with the DragonBoard 410c.
Step 2: Connecting the DragonBoard to AWS
This step will guide you in how to connect the DragonBoard 410c to AWS.
The source code is available here. Download it and then to set up your development environment and understand the source code, follow this instructable. It will guide you through this process and make it easier to adapt the code to your AWS account.
Step 3: Setting Up the Communication Between DragonBoard 410c and CSR1011
This step will guide you in how to connect the DragonBoard 410c with CSR1011 using Bluetooth Low Energy. This is possible by using the PyGatt library, which intermediates the communication between the devices.
The instructions about how to set up this connection are available on this instructable. It will demonstrate how to discover and subscribe to a characteristic, show an example of how to send and read data content, and also provide a code example to facilitate the understanding. The code used for this project is available below and it also can be used for the next step, since it is related to the CSR.
Step 4: Connecting and Controlling the Sensors With CSR1011
This step will guide you in how to connect the relays and the sensors required to read data and control the coffee machine with CSR 1011. It is divided into 4 parts to facilitate the understanding:
Coffee machine control (turning on/off and ordering coffee)
After receiving data through Bluetooth Low Energy from the DragonBoard 410c, the CSR1011 processes it to control the coffee machine. The signal is sent through a Grove relay which works as a driver. The instructions about how to access the CSR's GPIOs and trigger this relay are available on this instructable.
Verification of the cup position
The verification of the cup position to notify the user if he will be able to order coffee is made with an infrared sensor. It has two circuits (transmitter and receiver) which are positioned side-by-side. The instructions about how to connect this sensor and read its data with CSR1011 are available on this instructable.
Water level reading
To measure the water reservoir, a water level sensor is used. This sensor works as a switch and the instructions about how to connect and read its data with CSR1011 are available on this instructable.
Coffee level reading
To measure the coffee reservoir, an ultrasonic sensor is used. This sensor emits a sound wave that reflects back towards its origin. The distance between the coffee level and the sensor can be calculated using the time needed to receive the signal back. The instructions about how to connect this sensor and read its data with CSR1011 are available on this instructable.
Step 5: Conclusion
By doing these steps and connecting the relays to the coffee machine circuit, you will be able to have your own coffee machine connected with an Android app. If you have any doubt about each part of the system, you can use the official documentation and support forums: