Exemple #1
0
def main():
    ''' main function '''

    #set a broadcasting thread
    broadcast_thread = BroadcastServerThread()
    broadcast_thread.setDaemon(True)
    broadcast_thread.start()

    #a led blink thread
##    blink_thread = LedBlinkThread(led.blue)
##    blink_thread.setDaemon(True)
##    blink_thread.start()

    print('Program started successfully')
    while True:

        try:
            g_temperature,g_humidity = getTemperatureHumidity()
            g_lumiance = getLumiance()
            led.flash(led.green)

            if g_temperature != None and g_humidity != None and g_lumiance != None:
                db.insertSensorValue(g_temperature,g_humidity,g_lumiance,'home')

##            time.sleep(60)
            for i in range(60):
                led.toggle(led.blue)
                time.sleep(1)
        except:
            print('Program exit with exception')
            raise
Exemple #2
0
def handle_request(method, uri):
    root_uri = '/'
    if uri != root_uri:
        return ''

    print('Handling request {} {}'.format(method, uri))

    if method == 'POST':
        led.toggle()

    led_status = 'Off'
    if led.is_on():
        led_status = 'On'

    return page.render(led_status=led_status)
Exemple #3
0
import ultraduo
import imaxb6
import charger

led.init()
led.blink()


c = ultraduo.UltraDuo()
p = '/dev/ttyUSB0'

#for charger in settings.chargers:
_thread.start_new_thread( seriallog.serial_server, (p, c) )
_thread.start_new_thread( upload.upload_server, (c, ) )
_thread.start_new_thread( webserver.start_webserver, (c, ) )
_thread.start_new_thread( nfc.nfc_server, () )

while True:
  if c.channels[0].newdata > 0:
    led.toggle(led.RED)
    c.channels[0].newdata = 0
  if (nfc.tag.new > 0):
    led.toggle(led.ORANGE)
    nfc.tag.new = 0
    print('Main: ', nfc.tag)
  if (upload.response == 200):
    led.toggle(led.GREEN)
    upload.response = 0
  time.sleep(0.25)

Exemple #4
0
KEY=''          # Network key
HOST = ''       # Use first available interface
PORT = 8000     # Arbitrary non-privileged port

led.off(led.RED)
led.off(led.BLUE)
led.on(led.GREEN)

# Init wlan module and connect to network
wlan.init()
wlan.connect(SSID, sec=wlan.WPA2, key=KEY)
led.off(led.GREEN)

# Wait for connection to be established
while (True):
    led.toggle(led.BLUE)
    time.sleep(250)
    led.toggle(led.BLUE)
    time.sleep(250)
    if wlan.connected():
        led.on(led.BLUE)
        break;

# We should have a valid IP now via DHCP
wlan.ifconfig()

# Create server socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)

# Set socket in blocking mode
s.setblocking(True)
Exemple #5
0
def switch_cb(line):
    global thermal_on
    if (line == 9):
        led.toggle(led.IR)
    if (line == 12):
        thermal_on = not thermal_on
Exemple #6
0
KEY = ''  # Network key
HOST = ''  # Use first available interface
PORT = 8000  # Arbitrary non-privileged port

led.off(led.RED)
led.off(led.BLUE)
led.on(led.GREEN)

# Init wlan module and connect to network
wlan.init()
wlan.connect(SSID, sec=wlan.WPA2, key=KEY)
led.off(led.GREEN)

# Wait for connection to be established
while (True):
    led.toggle(led.BLUE)
    time.sleep(250)
    led.toggle(led.BLUE)
    time.sleep(250)
    if wlan.connected():
        led.on(led.BLUE)
        break

# We should have a valid IP now via DHCP
wlan.ifconfig()

# Create server socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)

# Set socket in blocking mode
s.setblocking(True)
Exemple #7
0
 def run(self):
     while True:
         led.toggle(self.color)
         time.sleep(0.5)
Exemple #8
0
def switch_cb(line):
    global thermal_on
    if (line == 9):
        led.toggle(led.IR)
    if (line == 12):
        thermal_on = not thermal_on