summaryrefslogtreecommitdiff
path: root/switch_onn.py
blob: 2cb66369fe2825a02babf71e4f266a4b4746d7d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys
import serial
import time
import os

# os.environ.setdefault('DJANGO_SETTINGS_MODULE','sbhs_server.settings')

# import django
# django.setup()

# try:
#     ser.close()
# except:
#     pass

ser = serial.Serial('/dev/ttyACM0')
def switchOnn(args):    
    try:
        for i in range(1,17):
            time.sleep(1)
            arg = str(i).zfill(2)
            ser.write(b'F'+arg)
        # ser.close()
    except:
        print 'Error: Cannot connect to device ',args

    os.environ.setdefault('DJANGO_SETTINGS_MODULE','sbhs_server.settings')

    import django
    django.setup()

    
    from sbhs_server.tables.models import Board

    for i in range(1,17):
        b = Board.objects.get(id = i)
        b.power_status = 1
        b.save()

if __name__ == '__main__':
    switchOnn(sys.argv)