Ejemplo n.º 1
0
def set_device_params(req):
    """Sets the device parameters as per the arguments sent
        Takes mid,fan,heat as paramter 
        Returns status_code = 200, data={temp:temp of the device} if succesful
                else 
                status_code = 500 , data={error:errorMessage}
    """
    mid = int(req.POST.get('mid'))
    fan = int(req.POST.get('fan'))
    heat = int(req.POST.get('heat'))
    usb_path = settings.MID_PORT_MAP.get(mid, None)

    if usb_path is None:
        retVal = {"status_code": 400, "message": "Invalid MID"}
        return HttpResponse(json.dumps(retVal),
                            content_type='application/json')

    #trying to connect to device

    # check if SBHS device is connected
    if not os.path.exists(usb_path):
        retVal = {
            "status_code": 500,
            "message": "Device Not connected to defined USB Port"
        }
        return HttpResponse(json.dumps(retVal),
                            content_type='application/json')

    try:
        board = sbhs.Sbhs()
        board.machine_id = mid
        board.boardcon = serial.Serial(port=usb_path,
                                       baudrate=9600,
                                       bytesize=8,
                                       parity='N',
                                       stopbits=1,
                                       timeout=2)  #orignal stopbits = 1
        board.status = 1
        if board.setFan(fan) and board.setHeat(heat):
            retVal = {"status_code": 200, "message": board.getTemp()}
            return HttpResponse(json.dumps(retVal),
                                content_type='application/json')
        else:
            retVal = {
                "status_code": 500,
                "message": "Could not set the parameters.Try again."
            }
            return HttpResponse(json.dumps(retVal),
                                content_type='application/json')
    except serial.serialutil.SerialException:
        retVal = {
            "status_code": 500,
            "message": "Could not connect to the device.Try again."
        }
        return HttpResponse(json.dumps(retVal),
                            content_type='application/json')
Ejemplo n.º 2
0
def initiation(req):
    username = req.POST.get("username")
    password = req.POST.get("password")
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            user1 = Account.objects.select_related().filter(id=user.id)
            user1 = user1[0]
            filename = datetime.datetime.strftime(datetime.datetime.now(), "%Y%b%d_%H_%M_%S.txt")
            log_dir = os.path.join(settings.EXPERIMENT_LOGS_DIR, user.username)
            if not os.path.exists(log_dir):
                os.makedirs(log_dir)
            f = open(os.path.join(log_dir, filename), "a")
            f.close()

            """ Initialize Global Values """
            GlobalValues.instantaneous_time = 0
            GlobalValues.room_temp = 29 + random.uniform(-2, 2)
            GlobalValues.max_temp = 68 + random.uniform(-0.3, 0.3)

            LOGIN(req, user)
            e = Experiment()
            e.user = user
            e.log = os.path.join(log_dir, filename)
            e.save()

            boards = sbhs.Sbhs(user.coeff_ID)
            global boards

            STATUS = 1
            MESSAGE = filename
        else:
            STATUS = 0
            MESSAGE = "Your account is not activated yet. Please check your email for activation link."
    else:
        STATUS = 0
        MESSAGE = "Invalid username or password"

    return HttpResponse(json.dumps({"STATUS": STATUS, "MESSAGE": MESSAGE}))
Ejemplo n.º 3
0
    SBHS_ADMINS = (
        ("Amol Mandhane", "+91-9999999999", "*****@*****.**"),
        ("Amol Mandhane", "+91-9999999999", "*****@*****.**"),
    )
else:
    from sbhs_server.sbhs_admin_config import SBHS_ADMINS

SBHS_GLOBAL_LOG_DIR = os.path.join(BASE_DIR, 'log')

from sbhs_server import sbhs
boards = {}
with open(os.path.join(BASE_DIR, 'map_machine_ids.txt')) as f:
    for line in f:
        try:
            data = line.split("=")
            brd = sbhs.Sbhs()
            b = brd.connect(int(data[0]))
            assert b == True
            key = int(brd.getMachineId())
            assert key > 0
            brd.reset_board()
            boards[str(key)] = {"board": brd, "experiment_id": None}
        except:
            pass

online_mids = [int(i) for i in boards.keys()]

import sys
print >> sys.stderr, online_mids[1:33]  #srikant
#srikant
#f = open('/tmp/online_mids', 'w')