コード例 #1
0
def get_env_temp_offset():
    logger.network_logger.debug("* Environment Temperature Offset sent to " + str(request.remote_addr))
    original_temp = sensor_access.get_environment_temperature(temperature_correction=False)
    adjusted_temp = sensor_access.get_environment_temperature()
    temp_offset = 0.0
    if original_temp is not None and adjusted_temp is not None:
        temp_offset = round(adjusted_temp[db_v.env_temperature] - original_temp[db_v.env_temperature], 5)
    return str(temp_offset)
コード例 #2
0
def _add_env_temp_and_offset(sensor_dic):
    try:
        reading = sa.get_environment_temperature()
        if reading is not None:
            sensor_dic.update(reading)
            reading2 = sa.get_environment_temperature(
                temperature_correction=False)
            final_reading = round(
                reading[db_v.env_temperature] - reading2[db_v.env_temperature],
                5)
            sensor_dic.update({db_v.env_temperature_offset: final_reading})
    except Exception as error:
        log_msg = "Interval Recording - Adding Env Temp & Offset Sensor Data to Dictionary: "
        logger.primary_logger.warning(log_msg + str(error))
    return sensor_dic
コード例 #3
0
def _bme280():
    try:
        temperature = sensor_access.get_environment_temperature()
        if temperature is not None:
            temperature = temperature[database_variables.env_temperature]
        pressure = sensor_access.get_pressure()
        if pressure is not None:
            pressure = pressure[database_variables.pressure] * 100

        humidity = sensor_access.get_humidity()
        if humidity is not None:
            humidity = humidity[database_variables.humidity]

        headers = {"X-PIN": "11",
                   "X-Sensor": "raspi-" + luftdaten_config.station_id,
                   "Content-Type": "application/json",
                   "cache-control": "no-cache"}

        post_reply = requests.post(url=luftdaten_config.luftdaten_url,
                                   json={"software_version": luftdaten_config.return_software_version,
                                         "sensordatavalues": [
                                             {"value_type": "temperature", "value": str(temperature)},
                                             {"value_type": "pressure", "value": str(pressure)},
                                             {"value_type": "humidity", "value": str(humidity)}]},
                                   headers=headers)
        if post_reply.ok:
            logger.network_logger.debug("Luftdaten - BME280 OK - Status Code: " + str(post_reply.status_code))
        else:
            log_msg = "Luftdaten - BME280 Failed - Status Code: " + str(post_reply.status_code) + " : "
            logger.network_logger.warning(log_msg + str(post_reply.text))
    except Exception as error:
        logger.network_logger.warning("Luftdaten - BME280 Failed: " + str(error))
コード例 #4
0
def get_env_temperature():
    logger.network_logger.debug("* Environment Temperature sent to " + str(request.remote_addr))
    return _get_filtered_reading(sensor_access.get_environment_temperature(), db_v.env_temperature)
コード例 #5
0
def get_weather_underground_readings():
    """
    Returns supported sensor readings for Weather Underground in URL format.
    Example:  &tempf=59.56&humidity=15.65
    """
    round_decimal_to = 5
    return_readings_str = ""

    temp_c = sensor_access.get_environment_temperature()
    if temp_c is not None:
        temp_c = temp_c[database_variables.env_temperature]
        try:
            temperature_f = (float(temp_c) * (9.0 / 5.0)) + 32.0
            if weather_underground_config.outdoor_sensor:
                return_readings_str += "&tempf=" + str(
                    round(temperature_f, round_decimal_to))
            else:
                return_readings_str += "&indoortempf=" + str(
                    round(temperature_f, round_decimal_to))
        except Exception as error:
            log_msg = "Weather Underground - Unable to calculate Temperature into fahrenheit: " + str(
                error)
            logger.sensors_logger.error(log_msg)

    humidity = sensor_access.get_humidity()
    if humidity is not None:
        humidity = humidity[database_variables.humidity]
        if weather_underground_config.outdoor_sensor:
            return_readings_str += "&humidity=" + str(
                round(humidity, round_decimal_to))
        else:
            return_readings_str += "&indoorhumidity=" + str(
                round(humidity, round_decimal_to))

    out_door_dew_point = sensor_access.get_dew_point()
    if out_door_dew_point is not None and weather_underground_config.outdoor_sensor:
        out_door_dew_point = out_door_dew_point[database_variables.dew_point]
        try:
            dew_point_f = (float(out_door_dew_point) * (9.0 / 5.0)) + 32.0
            return_readings_str += "&dewptf=" + str(
                round(dew_point_f, round_decimal_to))
        except Exception as error:
            log_msg = "Weather Underground - Unable to calculate Dew Point into fahrenheit: " + str(
                error)
            logger.sensors_logger.error(log_msg)

    pressure_hpa = sensor_access.get_pressure()
    if pressure_hpa is not None:
        pressure_hpa = pressure_hpa[database_variables.pressure]
        try:
            baromin = float(pressure_hpa) * 0.029529983071445
            return_readings_str += "&baromin=" + str(
                round(baromin, round_decimal_to))
        except Exception as error:
            logger.sensors_logger.error(
                "Weather Underground - Unable to calculate Pressure into Hg: "
                + str(error))

    ultra_violet = sensor_access.get_ultra_violet()
    if ultra_violet is not None:
        if database_variables.ultra_violet_index in ultra_violet:
            uv_index = ultra_violet[database_variables.ultra_violet_index]
            return_readings_str += "&UV=" + str(
                round(uv_index, round_decimal_to))

    pm_readings = sensor_access.get_particulate_matter()
    if pm_readings is not None:
        if database_variables.particulate_matter_2_5 in pm_readings:
            pm_2_5 = pm_readings[database_variables.particulate_matter_2_5]
            return_readings_str += "&AqPM2.5=" + str(
                round(pm_2_5, round_decimal_to))
        if database_variables.particulate_matter_10 in pm_readings:
            pm_10 = pm_readings[database_variables.particulate_matter_10]
            return_readings_str += "&AqPM10=" + str(
                round(pm_10, round_decimal_to))
    return return_readings_str
コード例 #6
0
def _open_sense_map_server():
    """ Sends compatible sensor readings to Open Sense Map every X seconds based on set Interval. """
    app_cached_variables.restart_open_sense_map_thread = False
    if osm_config.sense_box_id != "":
        url = osm_config.open_sense_map_main_url_start + "/" + osm_config.sense_box_id + "/data"
        url_header = {"content-type": "application/json"}

        while not app_cached_variables.restart_open_sense_map_thread:
            body_json = {}
            try:
                env_temperature = sensor_access.get_environment_temperature()
                if env_temperature is not None and osm_config.temperature_id != "":
                    body_json[osm_config.temperature_id] = env_temperature[
                        db_v.env_temperature]

                pressure_reading = sensor_access.get_pressure()
                if pressure_reading is not None and osm_config.pressure_id != "":
                    body_json[osm_config.pressure_id] = pressure_reading[
                        db_v.pressure]

                altitude_reading = sensor_access.get_altitude()
                if altitude_reading is not None and osm_config.altitude_id != "":
                    body_json[osm_config.altitude_id] = altitude_reading[
                        db_v.altitude]

                humidity_reading = sensor_access.get_humidity()
                if humidity_reading is not None and osm_config.humidity_id != "":
                    body_json[osm_config.humidity_id] = humidity_reading[
                        db_v.humidity]

                gas_readings = sensor_access.get_gas()
                if gas_readings is not None:
                    if db_v.gas_resistance_index in gas_readings and osm_config.gas_voc_id != "":
                        gas_voc = gas_readings[db_v.gas_resistance_index]
                        body_json[osm_config.gas_voc_id] = gas_voc
                    if db_v.gas_oxidising in gas_readings and osm_config.gas_oxidised_id != "":
                        gas_oxidised = gas_readings[db_v.gas_oxidising]
                        body_json[osm_config.gas_oxidised_id] = gas_oxidised
                    if db_v.gas_reducing in gas_readings and osm_config.gas_reduced_id != "":
                        gas_reduced = gas_readings[db_v.gas_reducing]
                        body_json[osm_config.gas_reduced_id] = gas_reduced
                    if db_v.gas_nh3 in gas_readings and osm_config.gas_nh3_id != "":
                        gas_nh3 = gas_readings[db_v.gas_nh3]
                        body_json[osm_config.gas_nh3_id] = gas_nh3

                lumen_reading = sensor_access.get_lumen()
                if lumen_reading is not None and osm_config.lumen_id != "":
                    body_json[osm_config.lumen_id] = lumen_reading[db_v.lumen]

                pm_readings = sensor_access.get_particulate_matter()
                if pm_readings is not None:
                    if db_v.particulate_matter_1 in pm_readings and osm_config.pm1_id != "":
                        pm1 = pm_readings[db_v.particulate_matter_1]
                        body_json[osm_config.pm1_id] = pm1
                    if db_v.particulate_matter_2_5 in pm_readings and osm_config.pm2_5_id != "":
                        pm2_5 = pm_readings[db_v.particulate_matter_2_5]
                        body_json[osm_config.pm2_5_id] = pm2_5
                    if db_v.particulate_matter_4 in pm_readings and osm_config.pm4_id != "":
                        pm4 = pm_readings[db_v.particulate_matter_4]
                        body_json[osm_config.pm4_id] = pm4
                    if db_v.particulate_matter_10 in pm_readings and osm_config.pm10_id != "":
                        pm10 = pm_readings[db_v.particulate_matter_10]
                        body_json[osm_config.pm10_id] = pm10

                colors = sensor_access.get_ems_colors()
                if colors is not None:
                    if db_v.red in colors and osm_config.red_id != "":
                        red = colors[db_v.red]
                        body_json[osm_config.red_id] = red
                    if db_v.orange in colors and osm_config.orange_id != "":
                        orange = colors[db_v.orange]
                        body_json[osm_config.orange_id] = orange
                    if db_v.yellow in colors and osm_config.yellow_id != "":
                        yellow = colors[db_v.yellow]
                        body_json[osm_config.yellow_id] = yellow
                    if db_v.green in colors and osm_config.green_id != "":
                        green = colors[db_v.green]
                        body_json[osm_config.green_id] = green
                    if db_v.blue in colors and osm_config.blue_id != "":
                        blue = colors[db_v.blue]
                        body_json[osm_config.blue_id] = blue
                    if db_v.violet in colors and osm_config.violet_id != "":
                        violet = colors[db_v.violet]
                        body_json[osm_config.violet_id] = violet

                uv_readings = sensor_access.get_ultra_violet()
                if uv_readings is not None:
                    if db_v.ultra_violet_index in uv_readings and osm_config.ultra_violet_index_id != "":
                        uv_index = uv_readings[db_v.ultra_violet_index]
                        body_json[osm_config.ultra_violet_index_id] = uv_index
                    if db_v.ultra_violet_a in uv_readings and osm_config.ultra_violet_a_id != "":
                        uv_a = uv_readings[db_v.ultra_violet_a]
                        body_json[osm_config.ultra_violet_a_id] = uv_a
                    if db_v.ultra_violet_b in uv_readings and osm_config.ultra_violet_b_id != "":
                        uv_b = uv_readings[db_v.ultra_violet_b]
                        body_json[osm_config.ultra_violet_b_id] = uv_b

                if len(body_json) > 0:
                    html_get_response = requests.post(url=url,
                                                      headers=url_header,
                                                      json=body_json)
                    status_code = str(html_get_response.status_code)
                    response_text = str(html_get_response.text)
                    if html_get_response.status_code == 201:
                        logger.network_logger.debug(
                            "Open Sense Map - Sent OK - Status Code: " +
                            status_code)
                    elif html_get_response.status_code == 415:
                        logger.network_logger.error(
                            "Open Sense Map: Invalid or Missing content type")
                    else:
                        log_msg = "Open Sense Map - Unknown Error " + status_code + ": " + response_text
                        logger.network_logger.error(log_msg)
                else:
                    log_msg = "Open Sense Map - No further updates will be attempted: " + \
                              "No Compatible Sensors or Missing Sensor IDs"
                    logger.network_logger.warning(log_msg)
                    while not app_cached_variables.restart_open_sense_map_thread:
                        sleep(5)
            except Exception as error:
                logger.network_logger.error(
                    "Open Sense Map - Error sending data")
                logger.network_logger.debug(
                    "Open Sense Map - Detailed Error: " + str(error))

            sleep_fraction_interval = 5
            sleep_total = 0
            while sleep_total < osm_config.interval_seconds and not app_cached_variables.restart_open_sense_map_thread:
                sleep(sleep_fraction_interval)
                sleep_total += sleep_fraction_interval