예제 #1
0
def bacnet_light_value(request, id):
    light = get_object_or_404(BACNetLight, pk=id)
    control = BacnetControl(settings.BACNET_BIN_DIR)
    if request.REQUEST.get('value', None):
        new_value = request.REQUEST.get('value', None)
        try:
            control.write_analog_output_int(light.device_id, light.property_id,
                                            new_value)
        except:
            logging.exception(
                'Could not write the posted value (%s) for bacnet device %s property %s'
                % (new_value, light.device_id, light.property_id))
            return HttpResponseServerError(
                'Could not write the posted value (%s) for bacnet device %s property %s\n\n%s'
                % (new_value, light.device_id, light.property_id,
                   sys.exc_info()[1]))
    try:
        value = float(
            control.read_analog_output(light.device_id, light.property_id)[1])
        return HttpResponse(value.__repr__(), content_type="text/plain")
    except:
        logging.exception(
            'Could not read the analog output for bacnet device %s property %s'
            % (light.device_id, light.property_id))
        return HttpResponseServerError(
            'Could not read the analog output for bacnet device %s property %s\n\n%s'
            % (light.device_id, light.property_id, sys.exc_info()[1]))
예제 #2
0
def bacnet_light(request, id):
    light = get_object_or_404(BACNetLight, pk=id)
    control = BacnetControl(settings.BACNET_BIN_DIR)
    if request.method == 'POST':
        light_control_form = LightControlForm(request.POST)
        if light_control_form.is_valid():
            new_value = light_control_form.cleaned_data['light_value']
            try:
                control.write_analog_output_int(light.device_id,
                                                light.property_id, new_value)
            except:
                logging.exception(
                    'Could not write the posted value (%s) for bacnet device %s property %s'
                    % (new_value, light.device_id, light.property_id))
                return HttpResponseServerError(
                    'Could not write the posted value (%s) for bacnet device %s property %s\n\n%s'
                    % (new_value, light.device_id, light.property_id,
                       sys.exc_info()[1]))
    try:
        light_value = control.read_analog_output(light.device_id,
                                                 light.property_id)[1]
        light_control_form = LightControlForm(
            data={'light_value': light_value})
    except:
        logging.exception(
            'Could not read the analog output for bacnet device %s property %s'
            % (light.device_id, light.property_id))
        light_value = None
        light_control_form = LightControlForm()
    return render_to_response('lighting/bacnet_light.html', {
        'light_value': light_value,
        'light_control_form': light_control_form,
        'light': light
    },
                              context_instance=RequestContext(request))
예제 #3
0
def bacnet_light_value(request, id):
	light = get_object_or_404(BACNetLight, pk=id)
	control = BacnetControl(settings.BACNET_BIN_DIR)
	if request.REQUEST.get('value', None):
		new_value = request.REQUEST.get('value', None)
		try:
			control.write_analog_output_int(light.device_id, light.property_id, new_value)
		except:
			logging.exception('Could not write the posted value (%s) for bacnet device %s property %s' % (new_value, light.device_id, light.property_id))
			return HttpResponseServerError('Could not write the posted value (%s) for bacnet device %s property %s\n\n%s' % (new_value, light.device_id, light.property_id, sys.exc_info()[1]))
	try:
		value = float(control.read_analog_output(light.device_id, light.property_id)[1])
		return HttpResponse(value.__repr__(), content_type="text/plain")
	except:
		logging.exception('Could not read the analog output for bacnet device %s property %s' % (light.device_id, light.property_id))
		return HttpResponseServerError('Could not read the analog output for bacnet device %s property %s\n\n%s' % (light.device_id, light.property_id, sys.exc_info()[1]))
예제 #4
0
def bacnet_light(request, id):
	light = get_object_or_404(BACNetLight, pk=id)
	control = BacnetControl(settings.BACNET_BIN_DIR)
	if request.method == 'POST':
		light_control_form = LightControlForm(request.POST)
		if light_control_form.is_valid():
			new_value = light_control_form.cleaned_data['light_value']
			try:
				control.write_analog_output_int(light.device_id, light.property_id, new_value)
			except:
				logging.exception('Could not write the posted value (%s) for bacnet device %s property %s' % (new_value, light.device_id, light.property_id))
				return HttpResponseServerError('Could not write the posted value (%s) for bacnet device %s property %s\n\n%s' % (new_value, light.device_id, light.property_id, sys.exc_info()[1]))
	try:
		light_value = control.read_analog_output(light.device_id, light.property_id)[1]
		light_control_form = LightControlForm(data={'light_value':light_value})
	except:
		logging.exception('Could not read the analog output for bacnet device %s property %s' % (light.device_id, light.property_id))
		light_value = None
		light_control_form = LightControlForm()
	return render_to_response('lighting/bacnet_light.html', {'light_value':light_value, 'light_control_form':light_control_form, 'light':light }, context_instance=RequestContext(request))
예제 #5
0
def device_property(request, device_id, property_id):
	control = BacnetControl(settings.BACNET_BIN_DIR)
	if request.method == 'POST' and request.POST.get('value', None):
		new_value = request.POST.get('value', None)
		if new_value.isdigit():
			try:
				return_code, value = control.write_analog_output_int(device_id, property_id, int(new_value))
				if return_code != 0: raise IOError(value)
			except:
				logging.exception('Could not write the posted value (%s) for bacnet device %s property %s' % (new_value, device_id, property_id))
				return HttpResponseServerError('Could not write the posted value (%s) for bacnet device %s property %s\n\n%s' % (new_value, device_id, property_id, sys.exc_info()[1]))
		else:
			return HttpResponseServerError('Could not write the posted value (%s) for bacnet device %s property %s: unsupported value format' % (new_value, device_id, property_id))
			
	try:
		return_code, value = control.read_analog_output(device_id, property_id)
		if return_code != 0: raise IOError(value)
	except:
		logging.exception('Could not read the analog output for bacnet device %s property %s' % (device_id, property_id))
		return HttpResponseServerError('Could not read the analog output for bacnet device %s property %s\n\n%s' % (device_id, property_id, sys.exc_info()[1]))

	return HttpResponse(('%s' % value).strip(), content_type="text/plain")