Skip to content

Inputs

Page: Setup -> Input

For a full list of supported Inputs, see Supported Input Devices.

Inputs, such as sensors, ADC signals, or even a response from a command, enable measuring conditions in the environment or elsewhere, which will be stored in a time-series database (InfluxDB). This database will provide measurements for Dashboards, LCDs, PID Controllers, Conditional Statements, and other parts of Mycodo to operate from. Add, configure, and activate inputs to begin recording measurements to the database and allow them to be used throughout Mycodo.

Custom Inputs~

See Building a Custom Input Module Wiki page.

There is a Custom Input import system in Mycodo that allows user-created Inputs to be created an used in the Mycodo system. Custom Inputs can be uploaded and imported from the [Gear Icon] -> Configure -> Custom Inputs page. After import, they will be available to use on the Setup -> Input page.

If you develop a working Input module, please consider creating a new GitHub issue or pull request, and it may be included in the built-in set.

Open any of the built-in modules located in the directory Mycodo/mycodo/inputs for examples of the proper formatting.

There are also example Custom Inputs in the directory Mycodo/mycodo/inputs/examples

Additionally, I have another github repository devoted to Custom Modules that are not included in the built-in set, at kizniche/Mycodo-custom.

Input Actions~

Input Actions are functions within the Input module that can be executed from the Web UI. This is useful for things such as calibration or other functionality specific to the input. By default, there is at least one action, Acquire Measurements Now, which will cause the input to acquire measurements rather than waiting until the next Period has elapsed.

Note

Actions can only be executed while the Input is active.

Input Options~

In addition to several supported sensors and devices, a Linux command may be specified that will be executed and the return value stored in the measurement database to be used throughout the Mycodo system.

Setting Description
Activate After the sensor has been properly configured, activation begins acquiring measurements from the sensor. Any activated conditional statements will now being operating.
Deactivate Deactivation stops measurements from being acquired from the sensor. All associated conditional statements will cease to operate.
Save Save the current configuration entered into the input boxes for a particular sensor.
Delete Delete a particular sensor.
Acquire Measurements Now Force the input to conduct measurements and them in the database.
Up/Down Move a particular sensor up or down in the order displayed.
Power Output Select a output that powers the sensor. This enables powering cycling (turn off then on) when the sensor returns 3 consecutive errors to attempt to fix the issue. Transistors may also be used instead of a relay (note: NPN transistors are preferred over PNP for powering sensors).
Location Depending on what sensor is being used, you will need to either select a serial number (DS18B20 temperature sensor), a GPIO pin (in the case of sensors read by a GPIO), or an I2C address. or other.
I2C Bus The bus to be used to communicate with the I2C address.
Period (seconds) After the sensor is successfully read and a database entry is made, this is the duration of time waited until the sensor is measured again.
Measurement Unit Select the unit to save the measurement as (only available for select measurements).
Pre Output If you require a output to be activated before a measurement is made (for instance, if you have a pump that extracts air to a chamber where the sensor resides), this is the output number that will be activated. The output will be activated for a duration defined by the Pre Duration, then once the output turns off, a measurement by the sensor is made.
Pre Output Duration (seconds) This is the duration of time that the Pre Output runs for before the sensor measurement is obtained.
Pre Output During Measurement If enabled, the Pre Output stays on during the acquisition of a measurement. If disabled, the Pre Output is turned off directly before acquiring a measurement.
Command A linux command (executed as the user 'root') that the return value becomes the measurement
Command Measurement The measured condition (e.g. temperature, humidity, etc.) from the linux command
Command Units The units of the measurement condition from the linux command
Edge Edge sensors only: Select whether the Rising or Falling (or both) edges of a changing voltage are detected. A number of devices to do this when in-line with a circuit supplying a 3.3-volt input signal to a GPIO, such as simple mechanical switch, a button, a magnet (reed/hall) sensor, a PIR motion detector, and more.
Bounce Time (ms) Edge sensors only: This is the number of milliseconds to bounce the input signal. This is commonly called debouncing a signal [1] and may be necessary if using a mechanical circuit.
Reset Period (seconds) Edge sensors only: This is the period of time after an edge detection that another edge will not be recorded. This enables devices such as PIR motion sensors that may stay activated for longer periods of time.
Measurement Analog-to-digital converter only: The type of measurement being acquired by the ADC. For instance, if the resistance of a photocell is being measured through a voltage divider, this measurement would be "light".
Units Analog-to-digital converter only: This is the unit of the measurement. With the above example of "light" as the measurement, the unit may be "lux" or "intensity".
BT Adapter The Bluetooth adapter to communicate with the input.
Clock Pin The GPIO (using BCM numbering) connected to the Clock pin of the ADC
CS Pin The GPIO (using BCM numbering) connected to the CS pin of the ADC
MISO Pin The GPIO (using BCM numbering) connected to the MISO pin of the ADC
MOSI Pin The GPIO (using BCM numbering) connected to the MOSI pin of the ADC
RTD Probe Type Select to measure from a PT100 or PT1000 probe.
Resistor Reference (Ohm) If your reference resistor is not the default (400 Ohm for PT100, 4000 Ohm for PT1000), you can manually set this value. Several manufacturers now use 430 Ohm resistors on their circuit boards, therefore it's recommended to verify the accuracy of your measurements and adjust this value if necessary.
Channel Analog-to-digital converter only: This is the channel to obtain the voltage measurement from the ADC.
Gain Analog-to-digital converter only: set the gain when acquiring the measurement.
Sample Speed Analog-to-digital converter only: set the sample speed (typically samples per second).
Volts Min Analog-to-digital converter only: What is the minimum voltage to use when scaling to produce the unit value for the database. For instance, if your ADC is not expected to measure below 0.2 volts for your particular circuit, set this to "0.2".
Volts Max Analog-to-digital converter only: This is similar to the Min option above, however it is setting the ceiling to the voltage range. Units Min Analog-to-digital converter only: This value will be the lower value of a range that will use the Min and Max Voltages, above, to produce a unit output. For instance, if your voltage range is 0.0 -1.0 volts, and the unit range is 1 -60, and a voltage of 0.5 is measured, in addition to 0.5 being stored in the database, 30 will be stored as well. This enables creating calibrated scales to use with your particular circuit.
Units Max Analog-to-digital converter only: This is similar to the Min option above, however it is setting the ceiling to the unit range.
Weighting The This is a number between 0 and 1 and indicates how much the old reading affects the new reading. It defaults to 0 which means the old reading has no effect. This may be used to smooth the data.
Pulses Per Rev The number of pulses for a complete revolution.
Port The server port to be queried (Server Port Open input).
Times to Check The number of times to attempt to ping a server (Server Ping input).
Deadline (seconds) The maximum amount of time to wait for each ping attempt, after which 0 (offline) will be returned (Server Ping input).
Number of Measurement The number of unique measurements to store data for this input.
Application ID The Application ID on The Things Network.
App API Key The Application API Key on The Things Network.
Device ID The Device ID of the Application on The Things Network.
  1. Debouncing a signal

The Things Network~

The Things Network (TTN) Input module enables downloading of data from TTN if the Data Storage Integration is enabled in your TTN Application. The Data Storage Integration will store data for up to 7 days. Mycodo will download this data periodically and store the measurements locally.

The payload on TTN must be properly decoded to variables that correspond to the "Variable Name" option under "Channel Options", in the lower section of the Input options. For instance, in your TTN Application, if a custom Payload Format is selected, the decoder code may look like this:

function Decoder(bytes, port) {
    var decoded = {};
    var rawTemp = bytes[0] + bytes[1] * 256;
    decoded.temperature = sflt162f(rawTemp) * 100;
    return decoded;
}

function sflt162f(rawSflt16) {
    rawSflt16 &= 0xFFFF;
    if (rawSflt16 === 0x8000)
        return -0.0;
    var sSign = ((rawSflt16 & 0x8000) !== 0) ? -1 : 1;
    var exp1 = (rawSflt16 >> 11) & 0xF;
    var mant1 = (rawSflt16 & 0x7FF) / 2048.0;
    return sSign * mant1 * Math.pow(2, exp1 - 15);
}

This will decode the 2-byte payload into a temperature float value with the name "temperature". Set "Number of Measurements" to "1", then set the "Variable Name" for the first channel (CH0) to "temperature" and the "Measurement Unit" to "Temperature: Celsius (°C)".

Upon activation of the Input, data will be downloaded for the past 7 days. The latest data timestamp will be stored so any subsequent activation of the Input will only download new data (since the last known timestamp).

This Input also allows multiple measurements to be stored. You merely have to change "Number of Measurements" to a number larger than 1, save, and there will now be multiple variable names and measurement units to set.

There are several example Input modules that, in addition to storing the measurements of a sensor in the influx database, will write the measurements to a serial device. This is useful of you have a LoRaWAN transmitter connected via serial to receive measurement information from Mycodo and transmit it to a LoRaWAN gateway (and subsequently to The Things Network). The data on TTN can then be downloaded elsewhere with the TTN Input. These example Input modules are located in the following locations:

~/Mycodo/mycodo/inputs/examples/bme280_ttn.py

~/Mycodo/mycodo/inputs/examples/k30_ttn.py

For example, the following excerpt from bme_280.py will write a set of comma-separated strings to the user-specified serial device with the first string (the letter "B") used to denote the sensor/measurements, followed by the actual measurements (humidity, pressure, and temperature, in this case).

string_send = 'B,{},{},{}'.format(
    return_dict[1]['value'],
    return_dict[2]['value'],
    return_dict[0]['value'])
self.serial_send = self.serial.Serial(self.serial_device, 9600)
self.serial_send.write(string_send.encode())

This is useful if multiple data strings are to be sent to the same serial device (e.g. if both bme280_ttn.py and k30_ttn.py are being used at the same time), allowing the serial device to distinguish what data is being received.

The full code used to decode both bme280_ttn.py and k30_ttn.py, with informative comments, is located at ~/Mycodo/mycodo/inputs/examples/ttn_data_storage_decoder_example.js.

These example Input modules may be modified to suit your needs and imported into Mycodo through the [Gear Icon] -> Configure -> Custom Inputs page. After import, they will be available to use on the Setup -> Input page.