Skip to content

Commit

Permalink
Merge pull request #47 from jaidenfe/develop
Browse files Browse the repository at this point in the history
Master code for beta testing phase
  • Loading branch information
henryohm authored Oct 23, 2017
2 parents bdc26d5 + fe2f5be commit 279cc3a
Show file tree
Hide file tree
Showing 432 changed files with 69,240 additions and 254 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,28 @@ This project aims to create a low cost home automation illumination device that

<h3>Compiling</h3>

To compile the entire project go the the top directory ```Lux/``` and type ```make```. This will compile everything and store it in the ```Lux/bin/``` directory.
The project is currently compiled by running the makefile in the tests/server folder.

make server_test

<h3>Execution</h3>

To execute a program from the top-most directory, type ```./bin/*name_of_program*``` and hit enter.
To execute the program:

*plug the Lux device into a light bulb socket and plug a light bulb into the female socket

*start the Lux device and connect to the ESP_XXXX website via localhost:8080

*provide the website with the IP address of your WiFi network

*start/connect a controller device (PC/Phone) to your WiFi

*compile and run the server_test.exe in the tests/server folder as instructed above

*push the RED button on the Lux device

*connect to the website at localhost:5000

*sign in on the website with username '[email protected]' and password 'admin'

*hit the submit button to turn the light on, sign in and hit it again to turn the light off
121 changes: 121 additions & 0 deletions src/app/LuxWebpage/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
from flask import Flask, request, jsonify, render_template
import socket, json

sock = None#socket
host = "127.0.0.1"#host address
port = 8080
buf_size = 1024#max message size
dict = None#last recieved message in map format
connected = False

REGISTER = 0
CONNECT = 1
STATUS_REQUEST = 2
STATUS = 3
UPDATE_REQUEST = 4
UPDATE = 5
DISCONNECT_REQUEST = 6
DISCONNECT = 7
UNREGISTER = 8
FORCE_DISCONNECT = 9
TEST = 10
REG_REQUEST = 11

app = Flask(__name__)

@app.route('/', methods=['GET'])
@app.route('/index.html', methods=['GET'])
def index():
return render_template('index.html')

@app.route('/about.html', methods=['GET'])
def about():
return render_template('about.html')

@app.route('/dashboard.html', methods=['GET'])
def dashboard():
connect()
return render_template('dashboard.html')

@app.route('/status_req', methods=['POST'])
def status_req():
rcvd = request.get_json()
resp = ""
if (rcvd != None):
command = STATUS_REQUEST
msg = '{"cmd":' + str(command) + ',"uuid":"0","serial":"0","data":{}}'
send(msg)#status_req

resp = '{"1" :' + read().decode('utf-8') + "}"#TODO read and return combined JSON once end delimiter/message is found (not yet implemented by server)

print(resp)
#render_template('dashboard.html')
return resp


@app.route('/update_req', methods=['POST'])
def update_req():
rcvd = request.get_json()
if (rcvd != None):
command = rcvd["cmd"]
uuid = rcvd["uuid"]
serial = rcvd["serial"]
name = rcvd["data"]["name"]
level = rcvd["data"]["level"]

msg = '{"cmd":' + str(command) + ',"uuid":"' + uuid + '","serial":"' + serial + '","data":{"name":"' + name + '","level":"' + str(level) + '"}}'
send(msg)

resp = read().decode('utf-8')
return resp#render_template('dashboard.html')

@app.route('/unregister', methods=['POST'])
def unregister():
rcvd = request.get_json()
if (rcvd != None):
command = UNREGISTER
uuid = "0"
serial = rcvd["serial"]
msg = '{"cmd":' + str(command) + ',"uuid": uuid ,"serial": serial ,"data":{}}'
connect()
send(msg)
disconnect()
return render_template('dashboard.html')

def connect():
global connected, sock
if (connected):
return#don't make a second connection
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setblocking(True)
sock.connect((host, port))
connected = True
print("Connection established.")

def disconnect():
global connected, sock
if (not connected):
return#not connected, don't try to d/c

msg = '{"cmd":"7","uuid":"0","serial":"0","data":{}}'
send(msg)#DISCONNECT -> client_exit();

sock.close()
sock = None
connected = False
print("Connection terminated.")

def send(msg):
global connected, sock
if (not connected or sock == None):
print("Attempted to send data without connection.")
return
sock.sendall(str.encode(msg))

def read():
msg = sock.recv(buf_size).split(b'\0', 1)[0]
return msg
#dict = json.loads(msg.decode("utf-8"))

if __name__ == "__main__":
app.run(debug=True)
2 changes: 2 additions & 0 deletions src/app/LuxWebpage/run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app.py
PAUSE
14 changes: 14 additions & 0 deletions src/app/LuxWebpage/static/bootstrap-4.0.0-beta/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"presets": [
[
"es2015",
{
"loose": true,
"modules": false
}
]
],
"plugins": [
"transform-es2015-modules-strip"
]
}
17 changes: 17 additions & 0 deletions src/app/LuxWebpage/static/bootstrap-4.0.0-beta/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.py]
indent_size = 4
3 changes: 3 additions & 0 deletions src/app/LuxWebpage/static/bootstrap-4.0.0-beta/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/*.min.js
**/vendor/*
**/dist/*
16 changes: 16 additions & 0 deletions src/app/LuxWebpage/static/bootstrap-4.0.0-beta/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Enforce Unix newlines
*.css text eol=lf
*.html text eol=lf
*.js text eol=lf
*.json text eol=lf
*.md text eol=lf
*.py text eol=lf
*.rb text eol=lf
*.scss text eol=lf
*.svg text eol=lf
*.yml text eol=lf
# Don't diff or textually merge source maps
*.map binary

bootstrap.css linguist-vendored=false
bootstrap.js linguist-vendored=false
Loading

0 comments on commit 279cc3a

Please sign in to comment.