コード例 #1
0
def IoT_to_Raspberry_Change_Power(ShadowPayload):
    global Power_Status
    # Desired = POWER change
    checkPlug()
    print(" I AM IN THE POWER CHANGE FUNCTION")
    print("ShadowPayload" + ShadowPayload)
    print("Power Status" + Power_Status)

    checkPlug()
    sp = SmartPlug('192.168.99.113','225564')
    if ( ShadowPayload == "ON" and Power_Status == "OFF"): #Check if machine is indeed OFF
        print("Power status is off and shadowpayload is on")
        sp.state = 'ON'
        print("Turned plug on")
        checkPlug()
        JSONPayload = '{ "state" : {'+\
                            '"reported": {'+\
                                '"Power": "' + Power_Status + '" '+\
                            '} '+\
                        '} '+\
                    '}'
        myDeviceShadow.shadowUpdate(JSONPayload, IoTShadowCallback_Update, 5) #Send the new status as REPORTED values

    elif ( ShadowPayload == "OFF" and Power_Status == "ON"): #Check if machine is indeed ON
        print("Power status is on and shadowpayload is off")
        sp.state = 'OFF'
        print("Turned plug off")
        checkPlug()
        JSONPayload = '{ "state" : {'+\
                            '"reported": {'+\
                                '"Power": "' + Power_Status + '" '+\
                            '}, '+\
                            '"desired": {'+\
                                '"Power": "' + Power_Status + '" '+\
                            '} '+\
                        '} '+\
                    '}'
        myDeviceShadow.shadowUpdate(JSONPayload, IoTShadowCallback_Update, 5) #Send the new status as REPORTED values
コード例 #2
0
#!python3
import sys

from pyW215.pyW215 import SmartPlug, ON, OFF

try:
    command = sys.argv[1]
    ip = sys.argv[2]
    password = sys.argv[3]
except:
    print('smart plug: action (on or off), IP, password required')
    exit(1)

sp = SmartPlug(ip, password)

# Get values if available otherwise return N/A
# print(sp.current_consumption)
# print(sp.temperature)
# print(sp.total_consumption)

# Turn switch on and off
if (command == 'on'):
    sp.state = ON
else:
    sp.state = OFF
コード例 #3
0
ファイル: views.py プロジェクト: viclope587/BiCS_Smart_web
def index(request):
    Staff = Group.objects.all()[0]
    Tech = Group.objects.all()[1]
    data = pd.read_csv("C:\\Users\\viclo\\Desktop\\BSP2\\The_project\\final_product\\project\\values.csv", sep=';')
    dic = datamin(data)

    #plugs
    dic_of_plug1 = {'BLAB-PLUG1':dic['BLAB-PLUG1']}
    dic_of_plug2 = {'BLAB-PLUG2':dic['BLAB-PLUG2']}
    on_or_off1 = dic['BLAB-PLUG1']
    on_or_off2 = dic['BLAB-PLUG2']

    #humidity
    dic_of_humid1 = {'BLAB-HUMID-AIR-1':dic['BLAB-HUMID-AIR-1']}
    dic_of_humid2 = {'BLAB-HUMID-SOIL-1':dic['BLAB-HUMID-SOIL-1']}
    dic_of_approx_hum1 = real_to_mod20(dic_of_humid1)
    dic_of_approx_hum2 = real_to_mod20(dic_of_humid2)

    #temeperature                
    dic_of_temp1 = {'BLAB-TEMP-AIR-1':dic['BLAB-TEMP-AIR-1']}
    dic_of_temp2 = {'BLAB-TEMP-AIR-2':dic['BLAB-TEMP-AIR-2']}
    dic_of_temp3 = {'BLAB-TEMP-SOIL-2':dic['BLAB-TEMP-SOIL-2']}                 
    dic_of_approx_temp1 = real_to_mod5(dic_of_temp1)
    dic_of_approx_temp2 = real_to_mod5(dic_of_temp2)
    dic_of_approx_temp3 = real_to_mod5(dic_of_temp3)

    #plug_control
    IP = 'Invalid Ip'
    Password = '******'
    state = ''
    temperature = 0
    consumption = 0
    total_cuns = 0
    form = ""
    
    if request.method == 'POST':
        # Create a form instance and populate it with data from the request (binding):
        form = plugs(request.POST)

        # Check if the form is valid:
        if form.is_valid():
            action = form.cleaned_data['choice_field']

            if (action == 'info_1'):
                IP = '10.212.232.12'
                Password = '******'
                sp = SmartPlug(str(IP), str(Password))
                state = sp.state
                temperature = sp.temperature
                consumption = sp.current_consumption
                total_cuns = sp.total_consumption
            elif (action == 'on_off_1'):
                IP = '10.212.232.12'
                Password = '******'
                sp = SmartPlug(str(IP), str(Password))
                if sp.state == 'OFF':
                    sp.state = ON
                else:
                    sp.state = OFF
                state = sp.state
            elif (action == 'info_2'):
                IP = '10.212.232.11'
                Password = '******'
                sp = SmartPlug(str(IP), str(Password))
                state = sp.state
                temperature = sp.temperature
                consumption = sp.current_consumption
                total_cuns = sp.total_consumption
            elif (action == 'on_off_2'):
                IP = '10.212.232.11'
                Password = '******'
                sp = SmartPlug(str(IP), str(Password))
                if sp.state == 'OFF':
                    sp.state = ON
                else:
                    sp.state = OFF
                state = sp.state
                
    links = []
    for i in range(1,3):
        links += [img('https://messir.uni.lu/bicslab/blab-cam'+str(i)+'-snapshots/gallery-images/')]
    
    return render(request, 'index.html', {'dic_of_temp1':dic_of_temp1,
                                          'img1':links[0],
                                          'img2':links[1],
                                          'dic_of_approx_temp1':dic_of_approx_temp1,
                                          'dic_of_temp2':dic_of_temp2,
                                          'dic_of_approx_temp2':dic_of_approx_temp2,
                                          'dic_of_temp3':dic_of_temp3,
                                          'dic_of_approx_temp3':dic_of_approx_temp3,                                             'dic_of_humid1':dic_of_humid1,
                                          'dic_of_approx_hum1':dic_of_approx_hum1,
                                          'dic_of_humid2':dic_of_humid2,
                                          'dic_of_approx_hum2':dic_of_approx_hum2,
                                          'dic_of_plug1':dic_of_plug1,
                                          'dic_of_plug2':dic_of_plug2,
                                          'on_or_off1':on_or_off1,
                                          'on_or_off2':on_or_off2,
                                          'Staff':Staff,
                                          'Tech':Tech,
                                          'form':form,
                                          'state':state,
                                          'temeperature':temperature,
                                          'consumption':consumption,
                                          'total_cuns':total_cuns
                                               })