Skip to content
Permalink
Browse files

installation scripts added

  • Loading branch information...
emrahcom committed Aug 8, 2017
1 parent a267ddc commit 316f65e53f9adec9d33d841fd42fd480043f5907
Showing with 1,941 additions and 0 deletions.
  1. +8 −0 .gitignore
  2. BIN component/bcm2835/bcm2835-1.52.tar.gz
  3. +46 −0 component/web_interfaces/etc/nginx/sites-available/talia.conf
  4. +14 −0 component/web_interfaces/etc/uwsgi/apps-available/api.ini
  5. +14 −0 component/web_interfaces/etc/uwsgi/apps-available/gui.ini
  6. +92 −0 component/web_interfaces/home/pi/test/taliabee_tester.py
  7. +113 −0 component/web_interfaces/home/pi/test/taliabee_tester.sh
  8. +89 −0 component/web_interfaces/var/www/taliabee_web_interfaces/api/README.md
  9. +19 −0 component/web_interfaces/var/www/taliabee_web_interfaces/api/app/__init__.py
  10. +262 −0 component/web_interfaces/var/www/taliabee_web_interfaces/api/app/api.py
  11. +1 −0 component/web_interfaces/var/www/taliabee_web_interfaces/api/requirements.txt
  12. +4 −0 component/web_interfaces/var/www/taliabee_web_interfaces/api/run.py
  13. +22 −0 component/web_interfaces/var/www/taliabee_web_interfaces/gui/app/__init__.py
  14. +44 −0 component/web_interfaces/var/www/taliabee_web_interfaces/gui/app/gui.py
  15. +51 −0 component/web_interfaces/var/www/taliabee_web_interfaces/gui/app/static/css/style.css
  16. +25 −0 component/web_interfaces/var/www/taliabee_web_interfaces/gui/app/static/js/tools.js
  17. +140 −0 component/web_interfaces/var/www/taliabee_web_interfaces/gui/app/static/js/vue_gui.js
  18. +218 −0 component/web_interfaces/var/www/taliabee_web_interfaces/gui/app/storage/data.json
  19. +30 −0 component/web_interfaces/var/www/taliabee_web_interfaces/gui/app/storage/data.py
  20. +99 −0 component/web_interfaces/var/www/taliabee_web_interfaces/gui/app/templates/index.html
  21. +1 −0 component/web_interfaces/var/www/taliabee_web_interfaces/gui/config.py
  22. +1 −0 component/web_interfaces/var/www/taliabee_web_interfaces/gui/requirements.txt
  23. +4 −0 component/web_interfaces/var/www/taliabee_web_interfaces/gui/run.py
  24. +16 −0 doc/bcm2835.md
  25. +10 −0 host/etc/default/keyboard
  26. +19 −0 host/root/.vimrc
  27. +48 −0 host/root/.zshrc
  28. +5 −0 installer/.htaccess
  29. +103 −0 installer/install.sh
  30. +26 −0 installer/taliabee.conf
  31. +12 −0 installer_sub_scripts/000_source
  32. +54 −0 installer_sub_scripts/020_host.sh
  33. +82 −0 installer_sub_scripts/030_host_custom.sh
  34. +27 −0 installer_sub_scripts/100_bcm2835.sh
  35. +21 −0 installer_sub_scripts/101_pymedioex.sh
  36. +21 −0 installer_sub_scripts/102_taliabeeio.sh
  37. +82 −0 installer_sub_scripts/103_web_interfaces.sh
  38. +53 −0 installer_sub_scripts/104_zigbee.sh
  39. +36 −0 installer_sub_scripts/900_status.sh
  40. +16 −0 installer_sub_scripts/910_completed.sh
  41. +13 −0 installer_sub_scripts/999_delete_installer.sh
@@ -0,0 +1,8 @@
*~
*.sw?
*.log
*.pyc
**/__pycache__/
**/bootstrap/
**/jquery/
**/vue/
Binary file not shown.
@@ -0,0 +1,46 @@
server {
listen 80;
listen 443 ssl;
include snippets/snakeoil.conf;

server_name _;
access_log /var/log/nginx/access.talia.log;
error_log /var/log/nginx/error.talia.log;

root /var/www/taliabee_web_interfaces/gui/static;

location /.well-known/ {
root /var/www/html/; }

location /api/ {
try_files $uri @talia_api; }

location / {
try_files $uri @talia_gui; }

# -----------------------------------------------------------------------------
# UWSGI MODE
# -----------------------------------------------------------------------------
location @talia_api {
add_header Access-Control-Allow-Origin *;
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000; }

location @talia_gui {
add_header Access-Control-Allow-Origin *;
include uwsgi_params;
uwsgi_pass 127.0.0.1:8001; }

# -----------------------------------------------------------------------------
# FLASK TEST MODE
# -----------------------------------------------------------------------------
#location @talia_api {
# add_header Access-Control-Allow-Origin *;
# proxy_pass http://127.0.0.1:5000; }

#location @talia_gui {
# add_header Access-Control-Allow-Origin *;
# proxy_pass http://127.0.0.1:5000; }


} # server end
@@ -0,0 +1,14 @@
[uwsgi]
plugins = python
uid = root
gid = root
master = true
processes = 1
enable-threads = false
harakiri = 30
post-buffering = 8192
vacuum = true
socket = 127.0.0.1:8000
callable = app
wsgi-file = /var/www/taliabee_web_interfaces/api/run.py
chdir = /var/www/taliabee_web_interfaces/api/
@@ -0,0 +1,14 @@
[uwsgi]
plugins = python
uid = pi
gid = pi
master = true
processes = 8
enable-threads = false
harakiri = 30
post-buffering = 8192
vacuum = true
socket = 127.0.0.1:8001
callable = app
wsgi-file = /var/www/taliabee_web_interfaces/gui/run.py
chdir = /var/www/taliabee_web_interfaces/gui/
@@ -0,0 +1,92 @@
#!/usr/bin/python3

from taliabeeio import TaliaBeeIO
from time import sleep
from random import randrange

DELAY = 0.1

io = TaliaBeeIO()

try:
while True:
# reset
io.reset()

# read di
for i in range(1,17,2):
print('DI-%02d = %d' % (i, io.di_read(i)))
sleep(DELAY)

# read do
for i in range(1,13,2):
print('DO-%02d = %d' % (i, io.do_read(i)))
sleep(DELAY)

# set do
for i in range(1,13):
io.do_set(i)
print('DO-%02d set' % (i))
sleep(DELAY)

# set relay / read relay
for i in range(13,17):
io.ro_set(i)
print('RO-%02d set (%d)' % (i, io.ro_read(i)))
sleep(DELAY)

# read di
for i in range(2,17,2):
print('DI-%02d = %d' % (i, io.di_read(i)))
sleep(DELAY)

# read do
for i in range(2,13,2):
print('DO-%02d = %d' % (i, io.do_read(i)))
sleep(DELAY)

# reset do
for i in range(12,0,-1):
io.do_reset(i)
print('DO-%02d reset' % (i))
sleep(DELAY)

# reset ro
for i in range(16,12,-1):
io.ro_reset(i)
print('RO-%02d reset (%d)' % (i, io.ro_read(i)))
sleep(DELAY)

# write ao
io.ao1 = randrange(0,4095)
io.ao2 = randrange(0,4095)
io.ao3 = randrange(0,4095)
io.ao4 = randrange(0,4095)

# read ai / ao
print('AI-%02d = % 5d' % (1, io.ai1))
print('AI-%02d = % 5d' % (2, io.ai2))
print('AI-%02d = % 5d' % (3, io.ai3))
print('AI-%02d = % 5d' % (4, io.ai4))

print('A0-%02d = % 5d' % (1, io.ao1))
print('A0-%02d = % 5d' % (2, io.ao2))
print('A0-%02d = % 5d' % (3, io.ao3))
print('A0-%02d = % 5d' % (4, io.ao4))

# read temperature
print('Temperature = %s' % (io.temperature))

# status
print('STATUS')
print(io.status)
print()

# wait
for i in range(20):
v = i % 2
io.ro_write(13, v)
io.do_write(4, v)
sleep(0.25)
except KeyboardInterrupt:
io.reset()
@@ -0,0 +1,113 @@
#!/bin/bash

DELAY=0.1

while true
do
# reset
curl "http://127.0.0.1/api/reset"

# read di
for i in $(seq 1 2 16)
do
curl "http://127.0.0.1/api/di/$i/read"
sleep $DELAY
done

# read do
for i in $(seq 1 2 12)
do
curl "http://127.0.0.1/api/do/$i/read"
sleep $DELAY
done

# set do
for i in $(seq 1 12)
do
curl "http://127.0.0.1/api/do/$i/set"
sleep $DELAY
done

# set relay / read relay
for i in $(seq 13 16)
do
curl "http://127.0.0.1/api/ro/$i/set"
curl "http://127.0.0.1/api/ro/$i/read"
sleep $DELAY
done

# read di
for i in $(seq 2 2 16)
do
curl "http://127.0.0.1/api/di/$i/read"
sleep $DELAY
done

# read do
for i in $(seq 2 2 12)
do
curl "http://127.0.0.1/api/do/$i/read"
sleep $DELAY
done

# reset do
for i in $(seq 1 12)
do
curl "http://127.0.0.1/api/do/$i/reset"
sleep $DELAY
done

# reset relay
for i in $(seq 13 16)
do
curl "http://127.0.0.1/api/ro/$i/reset"
curl "http://127.0.0.1/api/ro/$i/read"
sleep $DELAY
done

# increment ao
for i in $(seq 0 50 4095)
do
curl "http://127.0.0.1/api/ao/1/write?val=$i"
curl "http://127.0.0.1/api/ao/2/write?val=$i"
curl "http://127.0.0.1/api/ao/3/write?val=$i"
curl "http://127.0.0.1/api/ao/4/write?val=$i"
done

# read ai / ao
for i in $(seq 1 4)
do
curl "http://127.0.0.1/api/ai/$i/read"
curl "http://127.0.0.1/api/ao/$i/read"
sleep $DELAY
done

# decrement ao
for i in $(seq 4095 -50 0)
do
curl "http://127.0.0.1/api/ao/1/write?val=$i"
curl "http://127.0.0.1/api/ao/2/write?val=$i"
curl "http://127.0.0.1/api/ao/3/write?val=$i"
curl "http://127.0.0.1/api/ao/4/write?val=$i"
done

# write relay
for i in $(seq 13 16)
do
curl "http://127.0.0.1/api/ro/$i/write?val=1"
sleep $DELAY
done

# write do
for i in $(seq 1 12)
do
curl "http://127.0.0.1/api/do/$i/write?val=1"
sleep $DELAY
done

# read temperature
curl "http://127.0.0.1/api/temperature/read"

# status
curl "http://127.0.0.1/api/status"
done
@@ -0,0 +1,89 @@
## Web Interface

The web interface contains no HTML templates. Just a simple API.

All endpoints implemented as a `GET` request. So you can use `curl` to test it quickly.

### Installing web interface
Clone the repository
```sh
git clone git@github.com:nejdetckenobi/medioex_interfaces.git
```

Go to `web` folder inside the repository.
```sh
cd medioex_interfaces/web
```

Run the installation script as root. That will download the required libs and install them.
```sh
sudo ./install.sh
```

### Running web interface

Go to `web` folder inside the repository and run it as root.

```sh
cd medioex_interfaces/web
sudo python3 run.py
```

### How to use

The interface contains 6 endpoints

- `/api/ai/<int:pin>/read`: This endpoint reads values from Analog Inputs.

- `/api/ao/<int:pin>/write`: This endpoint writes to Analog Outputs.
- `/api/ao/<int:pin>/read`: This endpoint reads values from Analog Outputs.
- `/api/ao/<int:pin>/set`: This endpoint writes '1' values from Analog Outputs.
- `/api/ao/<int:pin>/reset`: This endpoint writes '0' values from Analog Outputs.

- `/api/do/<int:pin>/write`: This endpoint writes to Digital Outputs.
- `/api/do/<int:pin>/read`: This endpoint reads values from Digital Outputs.
- `/api/do/<int:pin>/set`: This endpoint writes '1' values from Digital Outputs.
- `/api/do/<int:pin>/reset`: This endpoint writes '0' values from Digital Outputs.

- `/api/ro/<int:pin>/read`: This endpoint reads values from Relay Outputs.
- `/api/ro/<int:pin>/write`: This endpoint writes to Relay Outputs.
- `/api/ro/<int:pin>/set`: This endpoint writes '1' to Relay Outputs.
- `/api/ro/<int:pin>/reset`: This endpoint writes '0' to Relay Outputs.

- `/api/status`: This endpoint reads everything.
- `/api/reset`: This endpoint writes '0' to all Outputs.

- `/api/temperature/read`: This endpoint reads from the default temperature sensor on MedIOEx. Gives floating value. (Celsius)

These endpoints accepts the parameters below:

- `pin`: `[1-4]` for Analog Outputs and Analog Inputs, `[1-12]` for Digital Outputs, `[13-16]` for Relay Outputs, `[1-16]` for Digital Inputs.

- `val`: `[0-1]` for Digitals, `[0-4095]` for Analogs.

**Note**: `val` parameter is only for writing purposes. All endpoints return JSON.

### Quick Examples

Assume that your RaspberryPi's IP address is `192.168.1.23` and you're running the web interface with the port `5000`


Writing `0` to Digital Output `1`

`curl "192.168.1.23:5000/api/do/1/write?val=0"`

Reading from Digital Input 3

`curl "192.168.1.23:5000/api/di/3/write"`

Reading from Analog Input 2

`curl "192.168.1.23:5000/api/ai?pin=2"`

Writing `2035` to Analog Output 4

`curl "192.168.1.23:5000/api/ao?pin=4&val=2035"`

Getting the temperature

`curl "192.168.1.23:5000/api/temperature"`
Oops, something went wrong.

0 comments on commit 316f65e

Please sign in to comment.
You can’t perform that action at this time.