Skip to content

Commit

Permalink
Add Input: Signal (Revolutions) (Alternative pigpio method), add shor…
Browse files Browse the repository at this point in the history
…t name for input display
  • Loading branch information
kizniche committed Apr 6, 2022
1 parent af7eeec commit 332a1dc
Show file tree
Hide file tree
Showing 43 changed files with 195 additions and 16 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 8.13.8 (Unreleased)

### Features

- Add Input: Signal (Revolutions) (Alternative pigpio method)

### Miscellaneous

- Add short name for input display


## 8.13.7 (2022-04-06)

### Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion mycodo/config_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@
'phrase': lazy_gettext('The number of pulses per revolution to calculate revolutions per minute (RPM)')},
'sample_time': {
'title': lazy_gettext('Sample Time'),
'phrase': lazy_gettext('The amount of time (seconds) to sample the input before caluclating the measurement')},
'phrase': lazy_gettext('The duration of time to sample')},
'scale_from_min': {
'title': lazy_gettext('Unscaled Unit Min'),
'phrase': lazy_gettext('Unscaled minimum unit')},
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/adafruit_i2c_soil.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'input_name_unique': 'ADAFRUIT_I2C_SOIL',
'input_manufacturer': 'Adafruit',
'input_name': 'I2C Capacitive Moisture Sensor',
'input_name_short': 'Capacitive Moisture',
'input_library': 'adafruit_seesaw',
'measurements_name': 'Moisture/Temperature',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/ads1115_analog_ph_ec.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def execute_at_modification(
'input_name_unique': 'ANALOG_PH_EC',
'input_manufacturer': 'Texas Instruments',
'input_name': 'ADS1115: Generic Analog pH/EC',
'input_name_short': 'ADS1115 pH/EC',
'input_library': 'Adafruit_CircuitPython_ADS1x15',
'measurements_name': 'Ion Concentration/Electrical Conductivity',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/ads1256_analog_ph_ec.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def execute_at_modification(
'input_name_unique': 'ADS1256_ANALOG_PH_EC',
'input_manufacturer': 'Texas Instruments',
'input_name': 'ADS1256: Generic Analog pH/EC',
'input_name_short': 'ADS1256 pH/EC',
'input_library': 'wiringpi, kizniche/PiPyADC-py3',
'measurements_name': 'Ion Concentration/Electrical Conductivity',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/adxl34x.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'input_name_unique': 'ADXL34x',
'input_manufacturer': 'Analog Devices',
'input_name': 'ADXL34x (343, 344, 345, 346)',
'input_name_short': 'ADXL34x',
'input_library': 'Adafruit_CircuitPython',
'measurements_name': 'Acceleration',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/ccs811.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'input_name_unique': 'CCS811',
'input_manufacturer': 'AMS',
'input_name': 'CCS811 (with Temperature)',
'input_name_short': 'CCS811 (w/ temp)',
'input_library': 'Adafruit_CCS811',
'measurements_name': 'CO2/VOC/Temperature',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/ccs811_CP.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'input_name_unique': 'CCS811_CP',
'input_manufacturer': 'AMS',
'input_name': 'CCS811 (without Temperature)',
'input_name_short': 'CCS881 (w/o temp)',
'input_library': 'Adafruit_CircuitPython_CCS811',
'measurements_name': 'CO2/VOC',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/examples/bme280_ttn.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
'input_name_unique': 'BME280_TTN',
'input_manufacturer': 'BOSCH',
'input_name': 'BME280 (->Serial->TTN)',
'input_name_short': 'BME280 TTN',
'input_library': 'Adafruit_BME280/pyserial',
'measurements_name': 'Pressure/Humidity/Temperature',
'measurements_dict': measurements_dict,
Expand Down
3 changes: 2 additions & 1 deletion mycodo/inputs/examples/example_all_options_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def constraints_pass_measure_range(mod_input, value):

# Descriptive information
'input_manufacturer': 'Company YY',
'input_name': 'Temp Sen01',
'input_name': 'Example Temperature Sensor 01',
'input_name_short': 'Ex. Temp. Sensor 01', # A shorter name for display purposes
'input_library': 'Library Name',

# Measurement information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def constraints_pass_measure_range(mod_input, value):

# Descriptive information
'input_manufacturer': 'Company YY',
'input_name': 'Temp Sen02',
'input_name': 'Example Temperature Sensor 02',
'input_name_short': 'Ex. Temp. Sensor 02', # A shorter name for display purposes
'input_library': 'Library Name',

# Measurement information
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/examples/k30_ttn.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'input_name_unique': 'K30_TTN',
'input_manufacturer': 'CO2Meter',
'input_name': 'K30 (->Serial->TTN)',
'input_name_short': 'K30 TTN',
'input_library': 'serial',
'measurements_name': 'CO2',
'measurements_dict': measurements_dict,
Expand Down
3 changes: 2 additions & 1 deletion mycodo/inputs/examples/minimal_humidity_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
INPUT_INFORMATION = {
'input_name_unique': 'TEST_00',
'input_manufacturer': 'AAA Company X',
'input_name': 'Dummy Input 00',
'input_name': 'Example Dummy Input 00',
'input_name_short': 'Ex. Dummy',
'input_library': 'random',
'measurements_name': 'Humidity/Temperature',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/hall_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'input_name_unique': 'HALL_FLOW',
'input_manufacturer': 'Generic',
'input_name': 'Hall Flow Meter',
'input_name_short': 'Hall Flow',
'input_library': 'pigpio',
'measurements_name': 'Flow Rate, Total Volume',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/linux_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'input_name_unique': 'LinuxCommand',
'input_manufacturer': 'Linux',
'input_name': 'Bash Command',
'input_name_short': 'Bash',
'measurements_name': 'Return Value',
'measurements_dict': measurements_dict,

Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/mcp342x.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'input_name_unique': 'MCP342x',
'input_manufacturer': 'Microchip',
'input_name': 'MCP342x (x=2,3,4,6,7,8)',
'input_name_short': 'MCP342x',
'input_library': 'MCP342x',
'measurements_name': 'Voltage (Analog-to-Digital Converter)',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/mqtt_paho.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'input_name_unique': 'MQTT_PAHO',
'input_manufacturer': 'MQTT',
'input_name': 'MQTT Subscribe (Value payload)',
'input_name_short': 'MQTT Value',
'input_library': 'paho-mqtt',
'measurements_name': 'Variable measurements',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/mqtt_paho_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'input_name_unique': 'MQTT_PAHO_JSON',
'input_manufacturer': 'MQTT',
'input_name': 'MQTT Subscribe (JSON payload)',
'input_name_short': 'MQTT JSON',
'input_library': 'paho-mqtt, jmespath',
'measurements_name': 'Variable measurements',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/rpi_cpu_gpu_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'input_name_unique': 'RPi',
'input_manufacturer': 'Raspberry Pi',
'input_name': 'CPU/GPU Temperature',
'input_name_short': 'CPU/GPU Temp',
'measurements_name': 'Temperature',
'measurements_dict': measurements_dict,
'measurements_use_same_timestamp': True,
Expand Down
5 changes: 4 additions & 1 deletion mycodo/inputs/rpi_signal_revolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
INPUT_INFORMATION = {
'input_name_unique': 'SIGNAL_RPM',
'input_manufacturer': 'Raspberry Pi',
'input_name': 'Signal (Revolutions)',
'input_name': 'Signal (Revolutions) (pigpio method #1)',
'input_name_short': 'Signal, RPM (#1)',
'input_library': 'pigpio',
'measurements_name': 'RPM',
'measurements_dict': measurements_dict,

'message': 'This calculates RPM from pulses on a pin using pigpio, but has been found to be less accurate than the method #2 module. This is typically used to measure the speed of a fan from a tachometer pin, however this can be used to measure any 3.3-volt pulses from a wire. Use a resistor to pull the measurement pin to 3.3 volts, set pigpio to the lowest latency (1 ms) on the Configure -> Raspberry Pi page. Note 1: Not setting pigpio to the lowest latency will hinder accuracy. Note 2: accuracy decreases as RPM increases.',

'options_enabled': [
'gpio_location',
'rpm_pulses_per_rev',
Expand Down
123 changes: 123 additions & 0 deletions mycodo/inputs/rpi_signal_revolutions_pigpio_callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# coding=utf-8
import time

import copy
from flask_babel import lazy_gettext

from mycodo.config_translations import TRANSLATIONS
from mycodo.inputs.base_input import AbstractInput
from mycodo.utils.constraints_pass import constraints_pass_positive_or_zero_value
from mycodo.utils.constraints_pass import constraints_pass_positive_value

# Measurements
measurements_dict = {
0: {
'measurement': 'revolutions',
'unit': 'rpm'
}
}

# Input information
INPUT_INFORMATION = {
'input_name_unique': 'SIGNAL_RPM_PIGPIO',
'input_manufacturer': 'Raspberry Pi',
'input_name': 'Signal (Revolutions) (pigpio method #2)',
'input_name_short': 'Signal, RPM (#2)',
'input_library': 'pigpio',
'measurements_name': 'RPM',
'measurements_dict': measurements_dict,

'message': 'This is an alternate method to calculate RPM from pulses on a pin using pigpio, and has been found to be more accurate than the method #1 module. This is typically used to measure the speed of a fan from a tachometer pin, however this can be used to measure any 3.3-volt pulses from a wire. Use a resistor to pull the measurement pin to 3.3 volts, set pigpio to the lowest latency (1 ms) on the Configure -> Raspberry Pi page. Note 1: Not setting pigpio to the lowest latency will hinder accuracy. Note 2: accuracy decreases as RPM increases.',

'options_enabled': [
'period',
'pre_output'
],
'options_disabled': ['interface'],

'dependencies_module': [
('internal', 'file-exists /opt/mycodo/pigpio_installed', 'pigpio'),
('pip-pypi', 'pigpio', 'pigpio==1.78')
],

'interfaces': ['GPIO'],

'custom_options': [
{
'id': 'pin',
'type': 'integer',
'default_value': None,
'required': False,
'constraints_pass': constraints_pass_positive_or_zero_value,
'name': lazy_gettext('GPIO Pin (BCM)'),
'phrase': 'The pin to measure pulses from'
},
{
'id': 'sample_time',
'type': 'float',
'default_value': 5.0,
'required': True,
'constraints_pass': constraints_pass_positive_value,
'name': f"{TRANSLATIONS['sample_time']['title']} ({lazy_gettext('seconds')})",
'phrase': TRANSLATIONS['sample_time']['phrase']
},
{
'id': 'pulse_factor',
'type': 'float',
'default_value': 15.8,
'required': True,
'constraints_pass': constraints_pass_positive_value,
'name': TRANSLATIONS['rpm_pulses_per_rev']['title'],
'phrase': TRANSLATIONS['rpm_pulses_per_rev']['phrase']
}
]
}


class InputModule(AbstractInput):
"""A sensor support class that monitors rpm."""

def __init__(self, input_dev, testing=False):
super().__init__(input_dev, testing=testing, name=__name__)

self.pigpio = None

self.pin = None
self.sample_time = None
self.pulse_factor = None

if not testing:
self.setup_custom_options(
INPUT_INFORMATION['custom_options'], input_dev)
self.try_initialize()

def initialize(self):
import pigpio

self.pigpio = pigpio

def get_measurement(self):
"""Gets the revolutions."""
pi = self.pigpio.pi()
if not pi.connected: # Check if pigpiod is running
self.logger.error("Could not connect to pigpiod. Ensure it is running and try again.")
return None

self.return_dict = copy.deepcopy(measurements_dict)

callback = pi.callback(self.pin)
start = time.time()
time.sleep(self.sample_time)
count = callback.tally()
end = time.time()
count_seconds = end - start
callback.cancel()
pi.stop()

rpm = int(float(count / self.pulse_factor) * 60 / count_seconds)

self.logger.debug(f"Counted {count} pulses in {count_seconds:.5f}s. Calculates to {rpm} RPM")

self.value_set(0, rpm)

return self.return_dict
3 changes: 2 additions & 1 deletion mycodo/inputs/scd4x_circuitpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
INPUT_INFORMATION = {
'input_name_unique': 'SCD4x_CIRCUITPYTHON',
'input_manufacturer': 'Sensirion',
'input_name': 'SCD-4x (SCD-40, SCD-41)',
'input_name': 'SCD-4x (40, 41)',
'input_name_short': 'SCD-4x',
'input_library': 'Adafruit-CircuitPython-SCD4x',
'measurements_name': 'CO2/Temperature/Humidity',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/sht31_smart_gadget.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def constraints_pass_logging_interval(mod_input, value):
'input_name_unique': 'SHT31_SMART_GADGET',
'input_manufacturer': 'Sensorion',
'input_name': 'SHT31 Smart Gadget',
'input_name_short': 'SHT31 SG',
'input_library': 'bluepy',
'measurements_name': 'Humidity/Temperature',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/sht3x.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'input_name_unique': 'SHT31',
'input_manufacturer': 'Sensirion',
'input_name': 'SHT3x (30, 31, 35)',
'input_name_short': 'SHT3x',
'input_library': 'Adafruit_SHT31',
'measurements_name': 'Humidity/Temperature',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/system_server_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'input_name_unique': 'SERVER_PING',
'input_manufacturer': 'Mycodo',
'input_name': 'Server Ping',
'input_name_short': 'Ping',
'input_library': 'ping',
'measurements_name': 'Boolean',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/system_server_port_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'input_name_unique': 'SERVER_PORT_OPEN',
'input_manufacturer': 'Mycodo',
'input_name': 'Server Port Open',
'input_name_short': 'Open Port',
'input_library': 'nc',
'measurements_name': 'Boolean',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/tasmota_outlet_energy_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
'input_name_unique': 'tasmota_outlet_energy_monitor',
'input_manufacturer': 'Tasmota',
'input_name': 'Tasmota Outlet Energy Monitor (HTTP)',
'input_name_short': 'Tasmota Energy Monitor',
'input_library': 'requests',
'measurements_name': 'Total Energy, Amps, Watts',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/th1x.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'input_name_unique': 'TH16_10_Generic',
'input_manufacturer': 'Sonoff',
'input_name': 'TH16/10 (Tasmota firmware) with AM2301/Si7021',
'input_name_short': 'TH16/10 + AM2301/Si7021',
'input_library': 'requests',
'measurements_name': 'Humidity/Temperature',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/th1x_am2301.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'input_name_unique': 'TH16_10',
'input_manufacturer': 'Sonoff',
'input_name': 'TH16/10 (Tasmota firmware) with AM2301',
'input_name_short': 'TH16/10 + AM2301',
'input_library': 'requests',
'measurements_name': 'Humidity/Temperature',
'measurements_dict': measurements_dict,
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/th1x_ds18b20.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'input_name_unique': 'TH16_10_DS18B20',
'input_manufacturer': 'Sonoff',
'input_name': 'TH16/10 (Tasmota firmware) with DS18B20',
'input_name_short': 'TH16/10 + DS18B20',
'input_library': 'requests',
'measurements_name': 'Temperature',
'measurements_dict': measurements_dict,
Expand Down
3 changes: 2 additions & 1 deletion mycodo/inputs/ttn_data_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def constraints_pass_positive_value(mod_input, value):
INPUT_INFORMATION = {
'input_name_unique': 'TTN_DATA_STORAGE',
'input_manufacturer': 'The Things Network',
'input_name': 'TTN Integration: Data Storage (TTN v2)',
'input_name': 'The Things Network: Data Storage (TTN v2)',
'input_name_short': 'TTN (v2) Data Storage',
'input_library': 'requests',
'measurements_name': 'Variable measurements',
'measurements_dict': measurements_dict,
Expand Down
3 changes: 2 additions & 1 deletion mycodo/inputs/ttn_data_storage_ttn_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def constraints_pass_positive_value(mod_input, value):
INPUT_INFORMATION = {
'input_name_unique': 'TTN_DATA_STORAGE_TTN_V3',
'input_manufacturer': 'The Things Network',
'input_name': 'TTN Integration: Data Storage (TTN v3, Payload Key)',
'input_name': 'The Things Network: Data Storage (TTN v3, Payload Key)',
'input_name_short': 'TTN (v3) Data Storage',
'input_library': 'requests',
'measurements_name': 'Variable measurements',
'measurements_dict': measurements_dict,
Expand Down
Loading

0 comments on commit 332a1dc

Please sign in to comment.