Ejemplo n.º 1
0
def submit_changes(request):
    print 'inside plug load update device method'
    if request.POST:
        _data = request.raw_post_data
        print _data
        _data = json.loads(_data)
        print _data

        device_info = _data['device_info']
        #_data = {"status": _data['status']}
        _data.pop('device_info')
        print _data
        print device_info
        content_type = "application/json"
        fromUI = "UI"
        kwargs = {'subscribe_address': 'ipc:///tmp/volttron-lite-agent-subscribe',
                  'publish_address': 'ipc:///tmp/volttron-lite-agent-publish'}
        _zmq_pub = zmqPub(**kwargs)
        print "created instance of the zmqpub class"
        #wifi_3m50_update_send_topic = "/ui/zone1/lighting/lights001/update/lights001_01"
        plugload_update_send_topic = '/ui/agent/bemoss/'+device_info+'/update'
        _zmq_pub.sendToAgent(plugload_update_send_topic, _data, content_type, fromUI)
        print "success in sending message to agent"

    if request.is_ajax():
            return HttpResponse(json.dumps(_data), mimetype='application/json')
Ejemplo n.º 2
0
def submit_changes(request):
    print 'inside plug load update device method'
    if request.POST:
        _data = request.raw_post_data
        print _data
        _data = json.loads(_data)
        print _data

        device_info = _data['device_info']
        #_data = {"status": _data['status']}
        _data.pop('device_info')
        print _data
        print device_info
        content_type = "application/json"
        fromUI = "UI"
        kwargs = {
            'subscribe_address': 'ipc:///tmp/volttron-lite-agent-subscribe',
            'publish_address': 'ipc:///tmp/volttron-lite-agent-publish'
        }
        _zmq_pub = zmqPub(**kwargs)
        print "created instance of the zmqpub class"
        #wifi_3m50_update_send_topic = "/ui/zone1/lighting/lights001/update/lights001_01"
        plugload_update_send_topic = '/ui/agent/bemoss/' + device_info + '/update'
        _zmq_pub.sendToAgent(plugload_update_send_topic, _data, content_type,
                             fromUI)
        print "success in sending message to agent"

    if request.is_ajax():
        return HttpResponse(json.dumps(_data), mimetype='application/json')
Ejemplo n.º 3
0
def get_lighting_current_status(request):
    print "Getting current status of thermostat"
    if request.method == 'POST':
        data_recv = request.raw_post_data
        data_recv = json.loads(data_recv)
        # same as the thermostat load method
        info_required = "current status"
        lighting_update_send_topic = '/ui/agent/bemoss/' + data_recv['device_info'] + '/device_status'
        #wifi_3m50_update_send_topic = "/ui/zone1/wifithermo3m50/qaz3m50/device_status"
        kwargs = {'subscribe_address': 'ipc:///tmp/volttron-lite-agent-subscribe',
                        'publish_address': 'ipc:///tmp/volttron-lite-agent-publish'}
        _zmq_pub = zmqPub(**kwargs)
        _zmq_pub.requestAgent(lighting_update_send_topic, info_required, "text/plain", "UI")
        json_result = {'status': 'sent'}

        if request.is_ajax():
            return HttpResponse(json.dumps(json_result), mimetype='application/json')
Ejemplo n.º 4
0
def submit_values(request):
    if request.POST:
        _data = request.raw_post_data
        json_data = json.loads(_data)

        device_info = json_data['device_info']
        print device_info

        json_data.pop('device_info')
        print json_data

        device_id = device_info.split("/")
        device_id = device_id[2]

        override = json_data['override']
        device_obj = Thermostat.objects.get(thermostat_id=device_id)
        device_obj.override = override
        device_obj.save()
        json_data.pop('override')
        print json_data

        update_number = "wifi_3m50_01"

        ieb_topic = '/ui/agent/bemoss/' + device_info + '/update'
        print ieb_topic
        content_type = "application/json"
        fromUI = "UI"
        print "entering in sending message to agent"
        kwargs = {
            'subscribe_address': 'ipc:///tmp/volttron-lite-agent-subscribe',
            'publish_address': 'ipc:///tmp/volttron-lite-agent-publish'
        }
        _zmq_pub = zmqPub(**kwargs)
        print "created instance of the zmqpub class"
        _zmq_pub.sendToAgent(ieb_topic, json_data, content_type, fromUI)
        print json_data
        print "success in sending message to agent"

        a_dict = {'update_number': update_number}
        json_data.update(a_dict)
        print json_data

        if request.is_ajax():
            return HttpResponse(json.dumps(json_data),
                                mimetype='application/json')
Ejemplo n.º 5
0
def get_plugload_current_status(request):
    print "getting current status of plug load"
    if request.method == 'POST':
        data_recv = request.raw_post_data
        data_recv = json.loads(data_recv) 
        # same as the thermostat load method
        kwargs = {'subscribe_address': 'ipc:///tmp/volttron-lite-agent-subscribe',
                        'publish_address': 'ipc:///tmp/volttron-lite-agent-publish'}
        _zmq_pub = zmqPub(**kwargs)
     
        print "created instance of the zmqpub class"
        info_required = "Update Hue data"
        #wifi_3m50_update_send_topic = "/ui/zone1/lighting/lights001/device_status"
        plugload_update_send_topic = '/ui/agent/bemoss/' + data_recv['device_info'] + '/device_status'
        _zmq_pub.requestAgent(plugload_update_send_topic, info_required, "text/plain", "UI")
        jsonresult = {'status': 'sent'}
        if request.is_ajax():
            return HttpResponse(json.dumps(jsonresult), mimetype='application/json')
Ejemplo n.º 6
0
def submit_values(request):
    if request.POST:
        _data = request.raw_post_data
        json_data = json.loads(_data)

        device_info = json_data['device_info']
        print device_info

        json_data.pop('device_info')
        print json_data

        device_id = device_info.split("/")
        device_id = device_id[2]

        override = json_data['override']
        device_obj = Thermostat.objects.get(thermostat_id=device_id)
        device_obj.override = override
        device_obj.save()
        json_data.pop('override')
        print json_data

        update_number = "wifi_3m50_01"

        ieb_topic = '/ui/agent/bemoss/'+device_info+'/update'
        print ieb_topic
        content_type = "application/json"
        fromUI = "UI"
        print "entering in sending message to agent"
        kwargs = {'subscribe_address': 'ipc:///tmp/volttron-lite-agent-subscribe',
                    'publish_address': 'ipc:///tmp/volttron-lite-agent-publish'}
        _zmq_pub = zmqPub(**kwargs)
        print "created instance of the zmqpub class"
        _zmq_pub.sendToAgent(ieb_topic, json_data, content_type, fromUI)
        print json_data
        print "success in sending message to agent"

        a_dict = {'update_number': update_number}
        json_data.update(a_dict)
        print json_data

        if request.is_ajax():
            return HttpResponse(json.dumps(json_data), mimetype='application/json')
Ejemplo n.º 7
0
def get_plugload_current_status(request):
    print "getting current status of plug load"
    if request.method == 'POST':
        data_recv = request.raw_post_data
        data_recv = json.loads(data_recv)
        # same as the thermostat load method
        kwargs = {
            'subscribe_address': 'ipc:///tmp/volttron-lite-agent-subscribe',
            'publish_address': 'ipc:///tmp/volttron-lite-agent-publish'
        }
        _zmq_pub = zmqPub(**kwargs)

        print "created instance of the zmqpub class"
        info_required = "Update Hue data"
        #wifi_3m50_update_send_topic = "/ui/zone1/lighting/lights001/device_status"
        plugload_update_send_topic = '/ui/agent/bemoss/' + data_recv[
            'device_info'] + '/device_status'
        _zmq_pub.requestAgent(plugload_update_send_topic, info_required,
                              "text/plain", "UI")
        jsonresult = {'status': 'sent'}
        if request.is_ajax():
            return HttpResponse(json.dumps(jsonresult),
                                mimetype='application/json')
Ejemplo n.º 8
0
def update_device_light(request):
    print 'inside lighting update device method'
    if request.POST:
        _data = request.raw_post_data
        _data = json.loads(_data)
        device_info = _data['device_info']
        if 'color' in str(_data):
            lt_color = _data['color']
            if 'a(' in str(lt_color):
                lt_color = '(0,0,0)'
            lt_color = eval(lt_color)
            _data['color'] = lt_color

        _data.pop('device_info')
        content_type = "application/json"
        fromUI = "UI"
        kwargs = {'subscribe_address': 'ipc:///tmp/volttron-lite-agent-subscribe',
                        'publish_address': 'ipc:///tmp/volttron-lite-agent-publish'}
        _zmq_pub = zmqPub(**kwargs)
        lighting_update_send_topic = '/ui/agent/bemoss/'+device_info+'/update'
        _zmq_pub.sendToAgent(lighting_update_send_topic, _data, content_type, fromUI)

    if request.is_ajax():
            return HttpResponse(json.dumps(_data), mimetype='application/json')
Ejemplo n.º 9
0
from lighting.models import Lighting
from smartplug.models import Plugload
import httplib
import os
import time
import json
import urllib2
import logging
import settings

logger = logging.getLogger("views")

kwargs = {'subscribe_address': 'ipc:///tmp/volttron-lite-agent-subscribe',
                    'publish_address': 'ipc:///tmp/volttron-lite-agent-publish'}
             
zmq_pub = zmqPub(**kwargs)


def recursive_get_device_update(update_variable):
    #wifi_3m50_device_initial_update = SessionHelper.get_device_update_message(update_variable)
    wifi_3m50_device_initial_update = config_helper.get_device_update_message(update_variable)
    print wifi_3m50_device_initial_update
    if wifi_3m50_device_initial_update != '{empty_string}':
        vals = wifi_3m50_device_initial_update
        return vals
    else:
        recursive_get_device_update(update_variable)


@login_required(login_url='/login/')
def thermostat(request, mac):
Ejemplo n.º 10
0
def lighting(request, mac):
    print 'inside lighting view method'
    context = RequestContext(request)
    username = request.session.get('user')
    print username
    if request.session.get('last_visit'):
    # The session has a value for the last visit
        last_visit_time = request.session.get('last_visit')

        visits = request.session.get('visits', 0)

        if (datetime.now() - datetime.strptime(last_visit_time[:-7], "%Y-%m-%d %H:%M:%S")).days > 0:
            request.session['visits'] = visits + 1
    else:
        # The get returns None, and the session does not have a value for the last visit.
        request.session['last_visit'] = str(datetime.now())
        request.session['visits'] = 1
    
    mac = mac.encode('ascii', 'ignore')

    device_metadata = [ob.device_control_page_info() for ob in DeviceMetadata.objects.filter(mac_address=mac)]
    print device_metadata
    device_id = device_metadata[0]['device_id']
    controller_type = device_metadata[0]['device_model_id']
    controller_type = controller_type.device_model_id

    device_status = [ob.data_as_json() for ob in Lighting.objects.filter(lighting_id=device_id)]
    device_zone = device_status[0]['zone']['id']
    device_nickname = device_status[0]['nickname']
    zone_nickname = device_status[0]['zone']['zone_nickname']

    kwargs = {'subscribe_address': 'ipc:///tmp/volttron-lite-agent-subscribe',
                    'publish_address': 'ipc:///tmp/volttron-lite-agent-publish'}
    _zmq_pub = zmqPub(**kwargs)
 
    print "created instance of the zmqpub class"
    info_required = "Update Hue data"
    wifi_3m50_update_send_topic = '/ui/agent/bemoss/' + str(device_zone) + '/lighting/' + device_id + '/device_status'
    _zmq_pub.requestAgent(wifi_3m50_update_send_topic, info_required, "text/plain", "UI")

    json_file = open(os.path.join(settings.PROJECT_DIR, 'resources/page_load/page_load.json'), "r+")
    _json_data = json.load(json_file)
    if device_id not in _json_data['lighting']:
        _json_data['lighting'][device_id] = {"page_load": "{empty_string}"}

    json_file.seek(0)
    json_file.write(json.dumps(_json_data, indent=4, sort_keys=True))
    json_file.truncate()
    json_file.close()

    time.sleep(3)

    _data = _helper.get_page_load_data(device_id, 'lighting', controller_type)

    zones = [ob.as_json() for ob in Building_Zone.objects.all()]
    thermostats_sn = [ob.data_side_nav() for ob in Thermostat.objects.filter(network_status='ONLINE', thermostat_id__bemoss=True)]
    lighting_sn = [ob.data_side_nav() for ob in Lighting.objects.filter(network_status='ONLINE', lighting_id__bemoss=True)]
    plugload_sn = [ob.data_side_nav() for ob in Plugload.objects.filter(network_status='ONLINE', plugload_id__bemoss=True)]
    active_al = get_notifications()
    context.update({'active_al':active_al})
    context.update({
            'zones': zones, 'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn
            })

    return render_to_response(
        'lighting/lighting.html',
        {'type': controller_type, 'device_data': _data, 'device_id': device_id, 'device_zone': device_zone,
         'device_type': controller_type, 'mac_address': mac, 'zone_nickname': zone_nickname,
         'device_nickname': device_nickname, 'zones': zones, 'thermostat_sn': thermostats_sn,
         'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn}, context)
Ejemplo n.º 11
0
import httplib
import os
import time
import json
import urllib2
import logging
import settings

logger = logging.getLogger("views")

kwargs = {
    'subscribe_address': 'ipc:///tmp/volttron-lite-agent-subscribe',
    'publish_address': 'ipc:///tmp/volttron-lite-agent-publish'
}

zmq_pub = zmqPub(**kwargs)


def recursive_get_device_update(update_variable):
    #wifi_3m50_device_initial_update = SessionHelper.get_device_update_message(update_variable)
    wifi_3m50_device_initial_update = config_helper.get_device_update_message(
        update_variable)
    print wifi_3m50_device_initial_update
    if wifi_3m50_device_initial_update != '{empty_string}':
        vals = wifi_3m50_device_initial_update
        return vals
    else:
        recursive_get_device_update(update_variable)


@login_required(login_url='/login/')