I try to implement a data fetching protocol to my system. The thing is I can succesfully retrieve data, I can see it in the Mycodo logs. But when I try to set this data to return_dict it just doesn’t. I don’t understand why, if someone can help me out I’d really appreciate it. And if there is anything I’m missing please let me know. Thanks
Here is the get_measurement function:
def get_measurement(self):
self.logger.info(f"Is enabled: {self.is_enabled(0)}")
self.return_dict = copy.deepcopy(measurements_dict)
try:
response = self.read_do(address)
if response:
response_dict = json.loads(response)
self.logger.info(f"Received response as dict: {response_dict} at {time.strftime('%H:%M:%S')}")
if match_address(response_dict,address):
try:
response_value = extract_value_if_sensor_exists(response_dict)
self.logger.info(f"Setting value: {response_value}")
self.value_set(0, float(response_value))
return self.return_dict
except ValueError:
self.logger.debug("Failed to convert the response to float.")
return None
else:
self.logger.info(f"Response dict: {response_dict}, address: {address}")
self.logger.debug("Response doesn't match with the sensor.")
self.logger.info("Response doesn't match with the sensor.")
return None
else:
self.logger.debug("No valid response received.")
return None
except Exception as msg:
self.logger.exception(f"Input read failure: {msg}")
return None
And here is the Mycodo logs:
2024-11-07 15:54:29,082 - INFO - mycodo.inputs.test_slave_3fb80327 - Command to send: sla1_do_r
2024-11-07 15:54:29,082 - INFO - mycodo.inputs.test_slave_3fb80327 - Command returned: {"sla1":[{"do":0.946}]}
2024-11-07 15:54:29,082 - INFO - mycodo.inputs.test_slave_3fb80327 - Received response as dict: {'sla1': [{'do': 0.946}]} at 15:54:29
2024-11-07 15:54:29,082 - INFO - mycodo.inputs.test_slave_3fb80327 - Setting value: 0.946
2024-11-07 15:54:43,823 - INFO - mycodo.inputs.test_slave_3fb80327 - Is enabled: True
2024-11-07 15:54:44,076 - INFO - mycodo.inputs.test_slave_3fb80327 - Command to send: sla1_do_r
2024-11-07 15:54:44,076 - INFO - mycodo.inputs.test_slave_3fb80327 - Command returned: {"sla1":[{"do":0.051}]}
2024-11-07 15:54:44,076 - INFO - mycodo.inputs.test_slave_3fb80327 - Received response as dict: {'sla1': [{'do': 0.051}]} at 15:54:44
2024-11-07 15:54:44,077 - INFO - mycodo.inputs.test_slave_3fb80327 - Setting value: 0.051