Skip to content

Commit

Permalink
functional prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
carlisgg committed Apr 17, 2017
1 parent 28b9a7e commit be0ef66
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 10 deletions.
19 changes: 19 additions & 0 deletions .ftpconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"protocol": "sftp",
"host": "192.168.0.44",
"port": 22,
"user": "pi",
"pass": "raspberry",
"promptForPass": false,
"remote": "/home/pi/lcdtest",
"agent": "",
"privatekey": "",
"passphrase": "",
"hosthash": "",
"ignorehost": true,
"connTimeout": 10000,
"keepalive": 10000,
"keyboardInteractive": false,
"watch": [],
"watchTimeout": 500
}
10 changes: 10 additions & 0 deletions DisplaySystem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class DisplaySystem():

def __init__(self, config, nodes):
self.config = config
self.nodes = nodes

def update_temp(temp):
for node in self.nodes:
node.send('show_temp', temp)

66 changes: 61 additions & 5 deletions Executor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,69 @@
import Adafruit_DHT
import RPi.GPIO as GPIO

import Adafruit_Nokia_LCD as LCD
import Adafruit_GPIO.SPI as SPI


class LocalExecutor():

def execute(self, command):
def __init__(self):
GPIO.setup(17, GPIO.OUT)
# Raspberry Pi hardware SPI config:
DC = 23
RST = 24
SPI_PORT = 0
SPI_DEVICE = 0

# Hardware SPI usage:
disp = LCD.PCD8544(DC, RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=4000000))

# Initialize library.
disp.begin(contrast=60)

def power_on():
GPIO.output(17, True)

def power_off():
GPIO.output(17, False)

def read_temp():
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, 4)
return temperature

def display_temp(temp):
# Clear display.
disp.clear()
disp.display()

bool = False
image = Image.new('1', (LCD.LCDWIDTH, LCD.LCDHEIGHT))
draw = ImageDraw.Draw(image)
draw.rectangle((0,0,LCD.LCDWIDTH,LCD.LCDHEIGHT), outline=255, fill=255)

# Load default font.
font = ImageFont.truetype("/usr/share/fonts/truetype/roboto/Roboto-Regular.ttf", 30)
fontHumidity = ImageFont.truetype("/usr/share/fonts/truetype/roboto/Roboto-Regular.ttf", 16)
# Write some text.
draw.text((0,0), '{0:0.1f} C'.format(temp), font=font)
draw.text((5,30), '{0:0.1f} HUM'.format(humidity), font=fontHumidity)

disp.image(image)

disp.display()
return True


def execute(self, command, *args):
result = False
if (command == 'on'):
print('Execute on')
bool = True
result = True
elif (command == 'off'):
print('Execute off')
bool = True
return bool
result = True
elif (command == 'temp'):
result = read_temp()
elif (command == 'show_temp'):
result = display_temp(args[0])

return result
6 changes: 6 additions & 0 deletions HeaterSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ def start(self):
for node in self.nodes:
node.send('on')

def read_temp(self):
temp = []
for node in self.nodes:
temp.push(node.send('temp'))


def stop():
raise "Method stop() not implemented"
19 changes: 14 additions & 5 deletions Nodes.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
# -*- coding: utf-8 -*-
from Executor import LocalExecutor
import serial

class Node:
def send(self, command):
def send(self, command, *args):
return False

class BTNode(Node):
def send(self, command):
def __init__(self, port):
self.port = port
self.s = serial.Serial(port=port, baudrate=9600)

def send(self, command, *args):
self.s.write(command)
print self.s.readline()
# if (connected):
# result = btmanager.send(command)
print('connecting to BT node')
return True

class LocalNode(Node):
def __init__(self):
self.executor = LocalExecutor()

def send(self, command):
return self.executor.execute(command)
def send(self, command, *args):
return self.executor.execute(command, args)

node = BTNode('/dev/tty.HC-06-DevB')
node.send('on')
8 changes: 8 additions & 0 deletions Terminetor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from flask import Flask
app = Flask(__name__)
heaterSystem = HeaterSystem('config', [LocalNode(), BTNode()])
displaySystem = DisplaySystem('config', [LocalNode()])

@app.route('/')
def hello_world():
Expand All @@ -15,5 +16,12 @@ def start():
heaterSystem.start()
return 'OK'

@app.route('/refresh')
def refresh():
temp = heaterSystem.read_temp()
displaySystem.update_temp(temp)

return 'OK'

if __name__ == '__main__':
app.run(debug = True)
28 changes: 28 additions & 0 deletions architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
REST ->

heater.schedule_week(from, to, temp) - inform job (actor)
heater.on(timeout) -
heater.off()

report service -- (heater control nodes, sensor nodes)
getHeaterHistory
getTempHistory
getHumHistory
setInterval(minutes)



heater service -- (heater control node, sensor nodes, display nodes)
add schedule
get schedules
get status
set target temo
on (time: Optional)
off (num days: Optional)


QUEUE

heater control node - on, off, temp, status
sensor node - read temp, read hum, read lum
display node - show temp, show hum, show heater status, show target temp,
55 changes: 55 additions & 0 deletions lcd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import time

import RPi.GPIO as GPIO
import Adafruit_DHT

import Adafruit_Nokia_LCD as LCD
import Adafruit_GPIO.SPI as SPI

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont


# Raspberry Pi hardware SPI config:
DC = 23
RST = 24
SPI_PORT = 0
SPI_DEVICE = 0

# Hardware SPI usage:
disp = LCD.PCD8544(DC, RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=4000000))
GPIO.setup(17, GPIO.OUT)

relay_out = True

# Initialize library.
disp.begin(contrast=60)

def refresh_temp():
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, 4)

# Clear display.
disp.clear()
disp.display()

image = Image.new('1', (LCD.LCDWIDTH, LCD.LCDHEIGHT))
draw = ImageDraw.Draw(image)
draw.rectangle((0,0,LCD.LCDWIDTH,LCD.LCDHEIGHT), outline=255, fill=255)

# Load default font.
font = ImageFont.truetype("/usr/share/fonts/truetype/roboto/Roboto-Regular.ttf", 30)
fontHumidity = ImageFont.truetype("/usr/share/fonts/truetype/roboto/Roboto-Regular.ttf", 16)
# Write some text.
draw.text((0,0), '{0:0.1f} C'.format(temperature), font=font)
draw.text((5,30), '{0:0.1f} HUM'.format(humidity), font=fontHumidity)

disp.image(image)

disp.display()

while True:
time.sleep(5)
refresh_temp()
GPIO.output(17, relay_out)
relay_out = not relay_out

0 comments on commit be0ef66

Please sign in to comment.