mqtt-io
mqtt-io copied to clipboard
hcsr04 ultrasonic sensor error
- [ Y] I have read the README.md file and visited the Documentation to see if the information there helps.
Describe the bug It always shows me the same error indicating that the configuration is incorrect. I've checked many times and can't find the fault.
Expected behavior mqtt-io connect to the sensor hcsr04 and send values to mqtt server
Error messages and traceback
pi@server:~ $ python3 -m mqtt_io config.yml
2022-07-08 09:59:30 mqtt_io.__main__ [ERROR] MqttIo crashed!
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.9/site-packages/mqtt_io/__main__.py", line 107, in main
mqtt_gpio.run()
File "/home/pi/.local/lib/python3.9/site-packages/mqtt_io/server.py", line 1230, in run
self._init_sensor_modules()
File "/home/pi/.local/lib/python3.9/site-packages/mqtt_io/server.py", line 255, in _init_sensor_modules
self.sensor_modules[sens_config["name"]] = _init_module(
File "/home/pi/.local/lib/python3.9/site-packages/mqtt_io/server.py", line 122, in _init_module
module_config = validate_and_normalise_config(module_config, module_schema)
File "/home/pi/.local/lib/python3.9/site-packages/mqtt_io/config/__init__.py", line 105, in validate_and_normalise_config
raise ConfigValidationFailed(
mqtt_io.exceptions.ConfigValidationFailed: Config did not validate:
burst:
- unknown field
pin_echo:
- unknown field
pin_trigger:
- unknown field
Traceback (most recent call last):
File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/pi/.local/lib/python3.9/site-packages/mqtt_io/__main__.py", line 115, in <module>
main()
File "/home/pi/.local/lib/python3.9/site-packages/mqtt_io/__main__.py", line 107, in main
mqtt_gpio.run()
File "/home/pi/.local/lib/python3.9/site-packages/mqtt_io/server.py", line 1230, in run
self._init_sensor_modules()
File "/home/pi/.local/lib/python3.9/site-packages/mqtt_io/server.py", line 255, in _init_sensor_modules
self.sensor_modules[sens_config["name"]] = _init_module(
File "/home/pi/.local/lib/python3.9/site-packages/mqtt_io/server.py", line 122, in _init_module
module_config = validate_and_normalise_config(module_config, module_schema)
File "/home/pi/.local/lib/python3.9/site-packages/mqtt_io/config/__init__.py", line 105, in validate_and_normalise_config
raise ConfigValidationFailed(
mqtt_io.exceptions.ConfigValidationFailed: Config did not validate:
burst:
- unknown field
pin_echo:
- unknown field
pin_trigger:
- unknown field
Config
mqtt:
host: 192.168.2.254
port: 1883
topic_prefix: watertank
ha_discovery:
enabled: yes
# Sensors
sensor_modules:
- name: ds18b20
module: ds18b
type: DS18B20
address: 00000026df4e
- name: hcsr04
module: hcsr04
burst: 10
pin_trigger: 20
pin_echo: 21
sensor_inputs:
- name: temp_exterior
module: ds18b20
interval: 60
digits: 2
- name: distance
module: hcsr04
interval: 10 # take a measurement every 10s
digits: 1
Hardware
- Platform: Raspberry Pi
- Connected hardware: DS18B20, HCSR04
System:
- OS: Raspbian 11
- Python version: Python 3.9.2
- User you're running as: pi
- Using a virtualenv?: no
Additional context I have tried reinstalling versions 2.2.6 and 2.2.7 with the same results.
Nobody? Please I need help with this.
This is the working configuration I use
sensor_modules:
- name: hcsr04_sensor
module: hcsr04
sensor_inputs:
- name: distance
module: hcsr04_sensor
interval: 300
digits: 2
pin_echo: 17
pin_trigger: 13
burst: 3
Hi @baryonicnonsense,
I tried your configuration but show me the followint error:
Traceback (most recent call last):
File "/home/pi/mqtt-io/mqtt_io/server.py", line 561, in poll_sensor
value = await get_sensor_value()
File "/home/pi/.local/lib/python3.9/site-packages/backoff/_async.py", line 133, in retry
ret = await target(*args, **kwargs)
File "/home/pi/.local/lib/python3.9/site-packages/backoff/_async.py", line 66, in retry
ret = await target(*args, **kwargs)
File "/home/pi/mqtt-io/mqtt_io/server.py", line 556, in get_sensor_value
return await sensor_module.async_get_value(sens_conf)
File "/home/pi/mqtt-io/mqtt_io/modules/sensor/__init__.py", line 57, in async_get_value
return await loop.run_in_executor(ThreadPoolExecutor(), self.get_value, sens_conf)
File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/pi/mqtt-io/mqtt_io/modules/sensor/hcsr04.py", line 131, in get_value
return self.sensors[sens_conf["name"]].measure_range()
File "/home/pi/mqtt-io/mqtt_io/modules/sensor/hcsr04.py", line 100, in measure_range
raise RuntimeError(
RuntimeError: Unable to measure range on HC-SR04 sensor 'distance'
```
My config is ::
sensor_modules:
- name: hcsr04_sensor
module: hcsr04
sensor_inputs:
- name: distance
module: hcsr04_sensor
interval: 10
digits: 20
pin_echo: 21
pin_trigger: 20
burst: 3
That looks like an issue with the sensor itself. I'd double check that everything is wired up correctly, the echo and trigger pins are properly set, and that the distance you are attempting to measure is within the capabilities of the sensor.
Hi @baryonicnonsense,
It's working perfectly! It was a misconfiguration with the pins of the raspberry!
Thanks!