Before you get started you will want to have your Yun connected to your wireless network, and be familiar with connecting to the Yun over SSH. Check out the following links for more information on these topics:
Once the sketch is running it will wait for an internal connection on port 5678 of the Yun's Linux-based processor. When a client connects to this port, the Yun will start sending volume measurements continuously (about 5 times a second) over the connection. You can SSH to the Yun and execute the telnet localhost 5678 command to see this behavior for yourself (press Ctrl-C to quit telnet).
To send the volume data to a web page, a server will be run on the Yun which both serves a web page, and volume data read from port 5678.
Flask web application framework as a server on the Arduino Yun. Flask is a simple python framework for running web applications. The web page for this guide is written using Flask because of its support for streaming data through HTML5 server sent events. Don't worry if you aren't familiar with Flask or web development, you can still follow the steps below to setup the server and web page.
First make sure the SD card is connected to the Yun, then connect to the Yun using SSH. Once connected execute the following commands to install pip, a python package manager:
opkg install distribute
opkg install python-openssl
Next execute the following command to create a directory on the SD card for storing python packages:
This folder will be used to install Flask and other python dependencies. By storing these dependencies on the SD card, there's less concern about using up the very limited storage space on the Yun (only 16 megabytes for the entire Linux installation!).
Finally execute the following command to install Flask:
pip install --target /mnt/sda1/python-packages flask
Now copy the YunSmartMeasuringCupServer folder from the software download onto the SD card of the Yun. You can use a file manager like Cyberduck to transfer files to the Yun, or if on Mac or Linux execute a command like:
scp -r YunSmartMeasuringCupServer [email protected]:/mnt/sda1
Note that the above command should be executed on your computer and from the directory where the software was unzipped. The command also assumes the Yun is using the default name 'arduino'.
You should see a message such as the following which indicates Flask is now listening on port 5000:
* Running on http://0.0.0.0:5000/
* Restarting with reloader
If you see an error or other failure, carefully check that all the above steps were followed.
With the server running, open a web browser to http://arduino.local:5000/ (or change the arduino.local to the appropriate name of your Yun). If you're running from a device without mDNS support (like Android or Windows), replace arduino.local with the IP address of the Yun.
Once the web page loads you should see it connect to the server and start displaying volume measurements. Try adding liquid to the container to see the measurement update in real time! Note that only one person can be connected to the server at a time.
When you're done running the server, on the Yun SSH connection that started the server press Ctrl-C to stop Flask.
If you want the server to run automatically on boot, edit the /etc/rc.local file on the Yun and add this line:
Enjoy using your smart measuring cup!