Skip to content

sle314/arduino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arduino Flask project

=====================

A project based on M2M communication which runs a Flask web-server (Python) on the Arduino YUN Linino making it possible to communicate with the device through a REST interface, using HTTP.

The device and its sensors/actuators are registered on an Actility gateway. Their values and methods are stored on and can be viewed and used through the gateway without direct access to the device itself.

The project also provides a web-application for associating gateways with the device and its sensors and adding/removing sensors to the device. It currently uses a TinkerKit! shield and its modules, but it should be possible to use others as well.

The shield/modules and their methods need to be added to the app/settings/local.py configuration file alongside the TinkerKit! values which can be used as an example. The shield pins need to be associated with the arduino pins and the module methods need to be defined so they can be used on the arduino side of the YUN.

Alongside adding a shield to the Linino side of the YUN, the shield's modules and methods need to be defined in the sketch so they can be accessed over the Linino-arduino Bridge through the REST interface. The sketch (sketch_apr24a/sketch_apr24a.ino) which uses the TinkerKit! shield and its modules and methods, along with the native arduino ones, can serve as an example to how this should be done.

===================================================================================================

First you need to SSH into the device (this won't be explained here because there are plenty of tutorials which can be found through google). You should SSH as root with the password for the device. If you want to be able to login without using the password every time, you can add your public ssh key to the authorized_keys on the YUN. Since it uses dropbear, the keys aren't located in ~/.ssh/, but in the file /etc/dropbear/authorized_keys. Just add your key to the end of that file and you should be good to go.

Once you have successfully managed to SSH into the device, you can use opkg to install the needed packages. This can also be done through the advanced configuration panel by using the "Software" option under the "System" dropdown menu.

Shell installation commands:

opkg update
opkg install python-openssl
opkg install python-crypto
opkg install python-sqlite3
opkg install setuptools
pokg install fdisk
opkg install wget
opkg install e2fsprogs

Next we need to install virtualenv with easy_install:

/usr/bin/easy_install virtualenv

===================================================================================================

Insert your microSD card and format it if you haven't yet: umount -f /mnt/sda1 mkfs.ext4 -O ^has_journal,extent /dev/sda1

Take the card out and put it back in to mount it.

After installing the prerequisites, to use this project you need to follow these steps:

  1. create a new python virtual environment on the microSD card:

    /usr/bin/virtualenv --system-site-packages /mnt/sda1/python

  2. activate the environment with the source command and keep it activated while using the app:

    source /mnt/sda1/python/bin/activate

to deactivate it and use the system python just type:

deactivate
  1. copy the project contents into a folder of your choice (I use /mnt/sda1/dev/arduino/)

  2. install the requirements with pip

with the virtualenv activated enter: pip install -r /mnt/sda1/PROJECT_LOCATION/app/config/requirements.txt

  1. cd to /mnt/sda1/PROJECT_LOCATION/ and use fabric to access different application commands:

start the server and app (default port is 5000) fab start:port

empty the database fab drop_db

create and initialize (shield/module/pin configuration in local.py) the database fab create_db

back up the database fab backup_db

restore the database from a backup fab restore_db

  1. create the database with fab create_db if you already haven't (you should have an arduino.db sqlite3 empty database in app/db/)

copy the app/db/empty_arduino.db file to app/db/arduino.db

OR

to create the db, install sqlite3 on your computer through the terminal/command prompt with the commands: sqlite3 arduino.db (opens up the sqlite3 shell)

when in the shell enter: .tables (inits an empty db) .quit (exits)

copy the created arduino.db file to app/db/

  1. start the server and app with the command (you need to be located in /mnt/sda1/PROJECT_LOCATION/):

    fab start

  2. open up the web-application in your browser by visiting:

    arduino.local:PORT

if you haven't specified a PORT in fab start, the default one is 5000

if arduino.local doesn't work, try enterng ARDUINO_IP_ADDRESS:PORT in the address bar of your browser

installing the Apple Bonjour printing driver on Windows should solve this issue

  1. the web-application usage is pretty self-explanatory

===================================================================================================

STARTUP AND CRON:

The advanced configuration panel enables you to define commands which should be executed on device startup (System -> Startup in the menu, then scroll to the bottom of the page). If you want the server and app to start this way, enter the following lines before the exit 0 line:

cd /mnt/sda1/PROJECT_LOCATION/
source /mnt/sda1/python/bin/activate
fab start

To set the cron jobs go to System -> Scheduled tasks and enter:

*/30 * * * * curl http://localhost:PORT/ip_cron/
*/2 * * * * curl http://localhost:PORT/cron/

===================================================================================================

OPTIONAL BUT RECOMENDED:

If you want to edit the source in your preffered text editor while it is on the YUN, you need to enable sshfs and mount the yun file system as a device/mount point via SSH. To do this you need to install the package openssh-sftp-server on the yun. You can do this through the advanced configuration panel as mentioned before, or by SSH-ing into to YUN and executing the following commands:

opkg update
opkg install openssh-sftp-server

On windows you can use WIN-SSHFS (https://code.google.com/p/win-sshfs/).

SSH login with public keys doesn't work so just use the password

On Linux you can use Gigolo.

For the text editor I would recommend Sublime Text 2.

About

arduino project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published