示例#1
0
文件: main.py 项目: tibor0991/obm-bob
def on_message(client, userdata, msg):
	#print msg.topic, str(msg.payload)
	#process the lights command
	if msg.topic == lights:
		sender.sendMessage('set lamp '+str(msg.payload))
		
	if msg.topic == log_request:
		#take the start and the end
		#send it as 'get log _start_ _end_ '
		log_req_dict = json.loads(str(msg.payload))
		log_message = sender.sendMessage('request-log '+log_req_dict['value_type']+' '+log_req_dict['start']+' '+log_req_dict['end'])
		client.publish(log_reply, log_message)
示例#2
0
    def _update(self, command):
        current_time = time.time()
        time_delta = current_time - self.last_update_time
        if time_delta < 1:
            self.trigger = False
        else:
            self.last_update_time = current_time
            self.alarm_line_index = (self.alarm_line_index + 1) % len(
                self.alarm_lines)
            self.view.lines[2] = self.alarm_lines[self.alarm_line_index]
            self.trigger = True

        if command == 'RESET':
            sender.sendMessage('reset-alarms')
            return IdleScreen(self.display)
        return self
示例#3
0
 def _update(self, command):
     self.trigger = True
     if command == 'BACK':
         return MenuScreen(self.display)
     elif command == 'UP':
         self.view.getSelectedSpinner().spinUp()
     elif command == 'DOWN':
         self.view.getSelectedSpinner().spinDown()
     elif command == 'LEFT':
         self.view.prevSpinner()
     elif command == 'RIGHT':
         self.view.nextSpinner()
     elif command == 'OK':
         sender.sendMessage('set setPoint ' +
                            self.view.getSelectedSpinner().getValue())
         return MenuScreen(self.display)
     else:
         self.trigger = False
     return self
示例#4
0
    def _update(self, command):
        self.view.lines[0] = time.strftime("%d/%m/%Y  %H:%M:%S")
        self.view.lines[1] = 'Temperature: %.1f C' % float(
            sender.sendMessage('get temp'))
        self.view.lines[2] = 'Humidity: %.0f %%' % float(
            sender.sendMessage('get hum'))
        fan_in = int(float(sender.sendMessage('get fan_in')) * 100) / 25
        fan_out = int(float(sender.sendMessage('get fan_out')) * 100) / 25
        self.view.lines[3] = 'Fan IN:' + '=' * fan_in + ' ' * (
            4 - fan_in) + ' OUT:' + '=' * fan_out
        if command == 'OK':
            return MenuScreen(self.display)
        elif command == 'UP':
            if sender.sendMessage('get lamp') == 'on':
                sender.sendMessage('set lamp off')
            else:
                sender.sendMessage('set lamp on')

        return self
示例#5
0
文件: main.py 项目: tibor0991/OBM-BOB
FAN_OUT = 15

GPIO.setup([BUZZER, PAD, LIGHTS, FAN_IN, FAN_OUT], GPIO.OUT, initial=GPIO.LOW)

buzzer = GPIO.PWM(BUZZER, 2)
fan_in = GPIO.PWM(FAN_IN, 30)
fan_in.start(0.5)
fan_out = GPIO.PWM(FAN_OUT, 30)
fan_out.start(0.5)

try:
	while True:
		#grab the data you need
		
		#check for the pad
		pad_status = sender.sendMessage('get pad')
		if pad_status == 'on':
			GPIO.output(PAD, GPIO.HIGH)
		else:
			GPIO.output(PAD, GPIO.LOW)
			
		#check for the lights
		lights_status = sender.sendMessage('get lamp')
		if lights_status == 'on':
			GPIO.output(LIGHTS, GPIO.HIGH)
		else:
			GPIO.output(LIGHTS, GPIO.LOW)
			
		#check for the buzzer
		alarm_status = sender.sendMessage('get alarms')
		if not alarm_status == '{}':
示例#6
0
FAN_OUT = 15

GPIO.setup([BUZZER, PAD, LIGHTS, FAN_IN, FAN_OUT], GPIO.OUT, initial=GPIO.LOW)

buzzer = GPIO.PWM(BUZZER, 2)
fan_in = GPIO.PWM(FAN_IN, 30)
fan_in.start(0.5)
fan_out = GPIO.PWM(FAN_OUT, 30)
fan_out.start(0.5)

try:
    while True:
        #grab the data you need

        #check for the pad
        pad_status = sender.sendMessage('get pad')
        if pad_status == 'on':
            GPIO.output(PAD, GPIO.HIGH)
        else:
            GPIO.output(PAD, GPIO.LOW)

        #check for the lights
        lights_status = sender.sendMessage('get lamp')
        if lights_status == 'on':
            GPIO.output(LIGHTS, GPIO.HIGH)
        else:
            GPIO.output(LIGHTS, GPIO.LOW)

        #check for the buzzer
        alarm_status = sender.sendMessage('get alarms')
        if not alarm_status == '{}':
示例#7
0
文件: main.py 项目: tibor0991/obm-bob
import socket
import paho.mqtt.client as mqtt
import sys
sys.path.append('.') #this is the path relative to bob_init.sh
from common.sender import sender
import time
import json


id = sender.sendMessage('get ip')
log_request = 'obm/bob/{}/logs/request'.format(id)
log_reply = 'obm/bob/{}/logs/reply'.format(id)
lights = 'obm/bob/{}/lights'.format(id)
alarm_topic = 'obm/bob/{}/alarms'.format(id)
status_topic = 'obm/bob/{}/values/status'.format(id)

def on_message(client, userdata, msg):
	#print msg.topic, str(msg.payload)
	#process the lights command
	if msg.topic == lights:
		sender.sendMessage('set lamp '+str(msg.payload))
		
	if msg.topic == log_request:
		#take the start and the end
		#send it as 'get log _start_ _end_ '
		log_req_dict = json.loads(str(msg.payload))
		log_message = sender.sendMessage('request-log '+log_req_dict['value_type']+' '+log_req_dict['start']+' '+log_req_dict['end'])
		client.publish(log_reply, log_message)

client = mqtt.Client()
client.on_message = on_message
示例#8
0
文件: main.py 项目: tibor0991/obm-bob
from Adafruit_LED_Backpack import SevenSegment
import socket
import time
import sys
sys.path.append('.') #this is the path relative to bob_init.sh
from common.sender import sender

setpoint_d = SevenSegment.SevenSegment(address=0x71, busnum=1)
temp_d = SevenSegment.SevenSegment(address=0x70, busnum=1)
setpoint_m = 'get setPoint'
temp_m = 'get temp'
setpoint_s = ''
temp_s = ''

setpoint = (setpoint_d, setpoint_m, setpoint_s)
temp = (temp_d, temp_m, temp_s)
list = [ setpoint, temp ]

for d, __, __ in list:
	d.begin()
	d.clear()
	d.write_display()

while 1:
	for led, msg, ans in list:
		ans = sender.sendMessage(msg)
		led.print_float(float(ans))
		led.write_display()
	time.sleep(1)
示例#9
0
文件: main.py 项目: tibor0991/obm-bob
import sys
sys.path.append('.')  #this is the path relative to bob_init.sh
from common.sender import sender

if __name__ == '__main__':
    cursor = '>> '
    command = ''
    exit = False
    print 'OBM BOB Command line interface: insert a command or write quit to exit'
    while not exit:
        command = raw_input(cursor)
        if command == 'quit':
            exit = True
        else:
            print sender.sendMessage(command)
示例#10
0
from display_i2c import i2c_lcd
from buttons import ButtonReader
import screen
import sys
sys.path.append('.')  #this is the path relative to bob_init.sh
from common.sender import sender

if __name__ == '__main__':
    main_screen = i2c_lcd(0x27, 1, 2, 1, 0, 4, 5, 6, 7, 3)
    main_screen.backLightOn()
    main_screen.clear()
    main_screen.home()
    main_screen.command(0x0C)  #disables the cursor

    idle = screen.IdleScreen(main_screen)
    currentScreen = idle

    br = ButtonReader()

    while True:
        alarms = sender.sendMessage('get alarms')
        if alarms != '{}' and type(currentScreen) is not screen.AlarmScreen:
            currentScreen = screen.AlarmScreen(main_screen, alarms)
        pressed = br.getButton()
        currentScreen = currentScreen.updateScreen(pressed)