Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Webserver

Wojtek Siudzinski edited this page Apr 19, 2014 · 4 revisions

Webserver is a Python/Django application which is the brain of Open Home.

It provides following parts:

  • Admin panel for management at http://127.0.0.1:9876/admin/
  • Browsable API at http://127.0.0.1:9876/api/v1/
  • Worker used to send Tri-State commands along with pulse length via serial port to Arduino with loaded Transceiver sketch
  • Simple webapp for turning on/off device groups

Usage

As webserver requires external packages, it's best to create separate virtualenv for it and install the packages:

$ virtualenv $HOME/.webserver
$ ln -s open-home/Python/webserver $HOME/.webserver/
$ cd $HOME/.webserver
$ source bin/activate
$ pip install -r webserver/requirements.txt

Now setup local database and add admin user:

$ python webserver/manage.py syncdb
$ python webserver/manage.py migrate

If you want to send data to Arduino (which you probably want) first list available serial ports (with Arduino connected):

$ python webserver/manage.py list_ports
/dev/cu.Bluetooth-Serial-1
/dev/cu.Bluetooth-Serial-2
/dev/cu.Bluetooth-Modem
/dev/cu.Bluetooth-PDA-Sync
/dev/cu.usbmodemfd131

It looks like Arduino is connected to /dev/cu.usbmodemfd131, so create local_settings.py file side-by-side webserver/webserver/settings.py with following contents:

SERIAL_DEVICE = '/dev/cu.usbmodemfd131'

Start webserver by running:

$ python webserver/manage.py runserver 0.0.0.0:9876

Now point your browser to: http://127.0.0.1:9876

To send commands you need to have worker running, to do this open new terminal and type:

$ cd $HOME/.webserver
$ source bin/activate
$ cd webserver
$ celery -A webserver --concurrency=1 worker

Customization

After setup, there is only one default group and no devices. You can add all devices to the default group or add more logic groups (i.e. bedroom, living room) to switch whole group with one command.

Adding a device requires two parameters which are set in Payload section and are JSON encoded:

{
	"pulse_length": 229,
	"tri_state_code": "00F0FFFF10"
}

You can get pulse_length and tri_state_code by Recording codes. Warning: tri_state_code in this JSON is missing two last digits on purpose. Remove them too.

Clone this wiki locally