MQTTInterface
A program to interface between JMRI and digital inputs, digital outputs and servos. Designed to run on a Wemos D1 Mini.
Functions
- Provides three types of software objects - servos, inputs, and outputs - which equate to the JMRI tables - Turnouts, Sensors and Lights.
- A web server is included which displays a multipage interface for configuration and testing.
Library Dependants
- Nick O'Leary's PubSubClient libary is required to handle the MQTT communications.
- Markus Sattler's WebSockets library is required to support the communication between web server and client.
- Adafruit's PWM Servo Driver Library is required to interface to the PCA9685 servo driver IC.
- Adafruit's MCP23017 Arduino Library is required to interface to the MCP23107 digital input/output IC.
Software Items
MQTTContainer
This single object contains MQTTInput, MQTTOutput and MQTTServo objects. The following methods are available for configuration;-
- setBroker(). This allows the name of the MQTT Broker to be set. Defaults to "raspberrypi".
- setPort(). This allows the port of the MQTT Broker to be set. Defaults to 1883.
- setStartupTopic(). This allows the startup topic to be set. Defaults to "events". This is the MQTT topic used to announce that the program has started and the message published to this topic gives information about the program's configuration.
MQTTInput
Objects of this class can be added to the container by the use of the container's addInput() method. The parameters to this method are;-
- pinNumber. This is the port number on the MCP23017 or the GPIO port on the 8266.
- inputTopic. This is the MQTT topic to which messages are published for this input object.
- mcp. Optional. If specified then pinNumber refers to the port on the MCP23017. If not, then it is a GPIO port on the 8266.
The following methods are available for configuration;-
There are no methods available for configuration.
MQTTServo
Objects of this class can be added to the container by the use of the container's addServo() method. The parameters to this method are;-
- pinNumber. This is the port number on the PWM servo driver.
- servoTopic. This is the MQTT topic to which the servo object subscribes.
- pwm. This is the PWM servo driver.
The following methods are available for configuration;-
- setTimeFromClosedToThrown_mS. This time is the same regardless of how far the servo has to move.
- setTimeFromThrownToClosed_mS. This time is the same regardless of how far the servo has to move.
- setThrownTopic. If this value is set the software will publish an MQTT message to this topic when the servo reaches the thrown angle.
- setClosedTopic. If this value is set the software will publish an MQTT message to this topic when the servo reaches the closed angle.
- setMidPointTopic. If this value is set the software will publish an MQTT message to this topic when the servo reaches the mid point angle.
Blink
Use of a Blink object allows multiple LEDs to blink in phase. Objects of this class can be added to the container by the use of the container's addBlink() method. The parameters to this method are;-
- onTime_mS. This is the time in milliseconds where the controlled LED will show the on colour.
- offTime_mS. This is the time in milliseconds where the controlled LED will show the off colour.
An example of use follows;-
- Blink* fastBlink = container.addBlink(500, 500);
MQTT_RGB_LED
Objects of this class can be added to the container by the user of the container's addRGB_LED() method. The parameters to this method are;-
- ledNumber. The zero based number of the LED in the string of individually addressable RGB LEDs.
- ledTopic. This is the MQTT topic to which the RGB LED object subscribes.
- rgb. This is the RGB LED controller object.
The following are examples of use;-
- MQTT_RGB_LED* led1_WHITE = container.addRGB_LED(0, "trains/track/light/LED1", rgb);
This will create an LED which will display the default on colour (white) when an ON message is received and the default off colour (black) when an OFF message is received.
- MQTT_RGB_LED* led1_RED = container.addRGB_LED(0, "trains/track/light/LED1_Red", rgb);
led1_RED->setOnColour(CRGB::Red);
led1_RED->setOffColour(CRGB::Black);
This will create an LED which will display red when an ON message is received and black when an OFF message is received.
- MQTT_RGB_LED* led1_WHITE = container.addRGB_LED(0, "trains/track/light/L002", rgb);
led1_WHITE->setBlink(fastBlink);
This will create an LED which will blink showing the default on colour (white) for 500mS and then the default off colour (black) for 500mS when an ON message is received. The LED will show the default off colour (black) when an OFF message is received.