ESPMQTTROCNETSound DESCRIPTION

Network overview

The ESPMQTTROCNETSOUND code expects to work in a network where Rocrail is running and has a “ROCNET controller using to MQTT. (set Sub-Library to “MQTT”)

A MQTT broker, such as Mosquitto is also running on the network. (It can run on either the same PC as Rocrail or a different PC).

Rocrail needs to know the IP address of the MQTT broker, and this should be set in the Rocrail Rocnet Controller “Address” options with Port set to 1883 if using Mosquitto.

If using “MQTT Service Client” Which I use for a handheld controller (RocClientThrottle ), then you also need to identify the MQTT Service in the Rocrail Service Properties.


Operation

On power up the nodes each search IP sub addresses 3-49 in sequence to find the MQTT Broker (The range can be easily changed if your broker has a higher IP address).

Once the node finds the router it saves the MQTT Broker sub address and uses this on its next start up to save time.

The Nodes do not “know” where Rocrail is, nor do they need to. All communications are set via the MQTT broker.

Rocrail addresses each Node by its ROCNET ID, which is usually initially set to the nodes subIP for simplicity.

The system is therefore theoretically limited to about 250 ESPMQTT nodes, depending on what else the WiFI router is connecting.

esp_network.jpg

As they start up and connect to the WiFi router, each ESPMQTTROCNETSound Node will be given an IP address by the router.Provided that the Router SSID and password have been properly set in the “Secrets” file in the code.

There is an option to use “WiFi manager” available, (#define _Use_Wifi_Manager). If this option is used, the node will search for a previously connected SSID first, but if this is not found it will set up a hotspot to which you can connect and then let it know which SSID (and passwords) it should use. I added this feature to allow the nodes to be “easily” used at new sites, but in practice I think it is simpler not to use this option, and I stick to the “preset” settings set in the secrets.h file.

When first setting up each node I would recommend that the define ”#define _ForceRocnetNodeID_to_subIPL” is set to force the Rocnet “ID” address to the IP sub address. I also force set the eeprom settings by using ”#define _ForceDefaultEEPROM”. This prevents confusion over what is initially set and any ID clashes.

After running the node once, I then reprogram the node with these directives commented out so the Rocnode ID can be set using the Rocnet programming options (if desired), and changes to eeprom settings can be made (and saved) via Rocrail.

Each node can now be individually seen and modified by Rocrail. Every node provides 8 universal i/o pins. “D1-D8”. Each I/O is effectively a virtual Pi02 channel with added Pi03 capabilities. Rocview programming is used to set the functionality of each port.

esp_node.jpg—-

PROVIDED that the Pin is not being used for an AUDIO ouput or Motor drive or other pre-defined function, it can be set by Rocrail as an input or output, using the “Pi02 Port Setup”. This allows blinking, and inversion.

  • If the Pin is set as an OUTPUT, and if the PI03 channel is set to SERVO, the pin becomes a Servo drive output.
  • If the Pin is set as an OUTPUT, and if the PI03 channel is set to “Blink”, the output becomes a PWM output.
  • For both Servo and PWM outputs, the code uses the “left” and “right” Pi03 values for the PWM/Servo settings.
  • “Left Steps” and “Right Steps” and “delay” settings all work to slow down and control the left - right transitions.

"STANDARD" Port usage summary


Some “standard” port setups are selected by using the Static /Mobile options and Audio DAC/NoDAC definitions. These are shown below.

To select “Mobile” settings, use the ”#define _LOCO_SERVO_Driven_Port 1”. (This example sets D1 as the RC Servo drive, and also sets D2 and D5 as front and back light drivers).

To use Mobile “PWM” drive rather than Servo drive, use ”#define _LocoPWMDirPort 3 ” (If you do this then D3 (and D1 set above) are used to drive the PWM drive device).

Other pins are then “used up” by the various audio output options.

node_options3.jpg

User : Port is available for user to specify as Input or Output.

  • Port D4 is used for the onboad LED.
  • with “AudioNoDAC”, port D4 is LRC (set as output with LRC square wave sent by DAC) , but it can be reused (but is complicated)

Port usage shown above is “standard”, but all port numbers/use can be modified in the code “directives.h” file if required.

(Some additional #defines are set or ignored depending on the defines noted above) e.g:

#ifdef _LOCO_SERVO_Driven_Port
 #define BACKLight 2  // NodeMCU D2
 #define FRONTLight 5 // NodeMCU D5
 //  #define SteamOutputPin 6
#endif

First Time program

Just to be “safe”, I recommend that the first time you program you should also set:

#define _ForceRocnetNodeID_to_subIPL 
#define _ForceDefaultEEPROM //
#define _Force_Loco_Addr 3 

This will make sure that the eeprom is set to at least some semi sensible values, and that the Rocnet node addresses shuld not clash if you program more than one device.

After you have done this, comment out these defines and reprogram the unit so you can set and change things for your application.


Personal Tools