roscoe81/enviro-monitor

UnboundLocalError: local variable 'parsed_config_parameters' referenced before assignment

rsun0525 opened this issue · 2 comments

When I run the following, I get this error:

pi@raspberrypienviro:~/enviro-monitor $ python Northcliff_AQI_Monitor_Gen.py
2022-01-24 11:09:08.579 INFO Northcliff_Environment_Monitor.py - Pimoroni Enviro+ with noise measurement (and optional SGP30) sensor capture and display.
Supports external sensor capture and Luftdaten, mqtt and Adafruit IO Updates
Disclaimer: The noise measurement is not to be used for accurate sound level measurements.

#Note: you'll need to register with Luftdaten at:
#https://meine.luftdaten.info/ and enter your Raspberry Pi
#serial number that's displayed on the Enviro plus LCD along
#with the other details before the data appears on the
#Luftdaten map.

6.11 - Gen
Config Retrieval Failed
Traceback (most recent call last):
File "/home/pi/enviro-monitor/Northcliff_AQI_Monitor_Gen.py", line 190, in
outdoor_mqtt_topic, indoor_mqtt_topic, city_name, time_zone, custom_locations) = retrieve_config()
File "/home/pi/enviro-monitor/Northcliff_AQI_Monitor_Gen.py", line 85, in retrieve_config
temp_offset = parsed_config_parameters['temp_offset']
UnboundLocalError: local variable 'parsed_config_parameters' referenced before assignment

The only thing I updated in your Northcliff_AQI_Monitor_Gen.py is the config file location:

def retrieve_config():
try:
with open('/home/pi/enviro-monitor/Config', 'r') as f:
parsed_config_parameters = json.loads(f.read())
print('Retrieved Config', parsed_config_parameters)

This is what I have in the config.json set to:

{"version": "Base-6.10a",
"temp_offset": 0,
"altitude": 2,
"enable_display": true,
"enable_adafruit_io": false,
"aio_user_name": "",
"aio_key": "",
"aio_feed_window": 0,
"aio_feed_sequence": 0,
"aio_household_prefix": "",
"aio_location_prefix": "",
"aio_package": "",
"enable_send_data_to_homemanager": false,
"enable_receive_data_from_homemanager": false,
"enable_indoor_outdoor_functionality": false,
"outdoor_source_type": "Enviro",
"outdoor_source_id": {},
"enable_noise": false,
"mqtt_broker_name": "<>",
"mqtt_username": "",
"mqtt_password": "",
"enable_luftdaten": true,
"enable_luftdaten_noise": false,
"disable_luftdaten_sensor_upload": "None",
"enable_climate_and_gas_logging": false,
"enable_particle_sensor": true,
"enable_eco2_tvoc": false,
"gas_daily_r0_calibration_hour": 3,
"reset_gas_sensor_calibration": false,
"incoming_temp_hum_mqtt_topic": "",
"incoming_temp_hum_mqtt_sensor_name": "",
"incoming_barometer_mqtt_topic": "",
"incoming_barometer_sensor_id": 0,
"indoor_outdoor_function": "Outdoor",
"mqtt_client_name": "",
"outdoor_mqtt_topic": "",
"indoor_mqtt_topic": "",
"city_name": "Newark",
"time_zone": "America/New_York",
"custom_locations": ["Townsville, Australia, Queensland, -19.26639, 146.80569", "Thredbo, Australia, Sydney, -36.4999989, 148.2999988", "Romsey, Australia, Victoria, -37.3581082, 144.7365582"]}

Is there a mistake I made in the config.json file that's causing the error? Or is there a bug in the python script? The city_name I'm using is listed in the database already https://astral.readthedocs.io/en/latest/#additional-locations

If you have the config file named and located like this: "home/pi/enviro-monitor/config.json", you'll need to have line 80 as "with open('/home/pi/enviro-monitor/config'.json, 'r') as f:"
It looks like your line 80 is "with open('/home/pi/enviro-monitor/Config', 'r') as f:" and that might be your problem.

Thank you for your prompt response! That did the trick.