Based on a 38 pin ESP 32 Dev-Kit v1.1 with Wi-Fi on board, I plan to hook as many IR sensors as possible via MQTT to my layout. The sketch I am working on, is configured for 16 sensors but more should be possible if special care is taken regarding the GPIO pins used.
The programming was quite straight forward after getting the MQTT signal thingy to work. The MQTT part is – more or less – reusable and registering whether a pin is high or low is not exactly rocket science. So after determining the so-called safe PINs for my NodeMCU ESP32 DevKit, I was pretty sure everything should work as desired.
I suspect the tricky part will be to make JMRI recognise what I’m doing.
The good news is, that if you know what JMRI is looking for, to read a sensor, you can tweak the MQTT part to deliver exactly that.
An MQTT aytached sensor is recognised by JMRI, if it publishes either „ACTIVE“ or „INACTIVE“ as its state into the topic „track/“, the subtopic „sensor/“ with its MQTT clientID.
This way, in the event of a detection, the state of the sensor BS1 (for Block Sensor 1) is publisted to:
track/sensor/BS1 = ACTIVE
JMRI recognises sensor by addressing their device identifier, which is composed of the MQTT connecion prefix (usually „M“), the sensor category prefix (usually „S“) and the actual sensor ID (here BS1).
So the above sensor would have the JMRI system name MSBS1, which automatically subscribes to all messages for „track/sensor/BS1“.
Neat, and a little update with all 13 sensors for the Test Layout connected to JMRI, via MQTT-Broker.