When first programming your ESP8266, uncomment the directives:
#define _Force_Loco_Addr 8 (or use 3!)
Program the ESP using Arduino IDE, Then, monitor the arduino serial monitor. You should see the code looking for your Router SSID, logging in, then trying to connect to your MQTT broker. The MQTT part will sequentially try IP addresses on your router between 0 and 50 (set in MQTT:reconnect(). ). It should connect and then throw up a table showing how the IO is organised.
At this point, you know the code is working so note the IP address of the hardware and comment out the three directives above. RE-program the device and again watch as it starts up. It should connect to the router with the same IP address as before and will again look for the MQTT broker. But this time it will save these values un EEPROM so that subsequent start ups will be quicker. You can now modify the IO settings using Rocrail. If you set the hardware as a loco, the Arduino Serial monitor should show something like this
This shows a decoder that is set for a Rocrail “Node” of 28, and is also a Loco at DCC address 7.
The code tries to show if any ports are “FIXED” and being used for special purposes, such as the Loco Motor, or front and back lights etc.
Here I have set pins 6 as input and 8 as servo. If this was a Stationary node, the display would be similar, but all ports would be usable.
ESPMQTT Rocnet Sound uses the "Pi02" interface to determine if pins are Inputs or Outputs.
Use the Pi02 settings to set if the pin is an input or output. The Pi02 settings can also select the pin phase ("Invert") and if the pin is expected to flash ("Blink").
If the pin is an OUTPUT, the code additionally uses the Pi03 settings to determine if the in is a "Digital Output" "PWM Output" or "Servo Output".
If you use PWM or Servo, then the Left and Right boxes show the to PWM or servo positions that the unit will switch to.
The code updates the servo/pwm positions at a rate determined by the Delay *10ms field. It changes its output by "left or right steps" every time. a step or delay of "0" is instantaneous movement. A step of 1 every "10" (== 100ms) results in slow servo movement.
Go to Rocrail and press "Programming / Rocnet / Setup" and then “Query”.
This will bring up a page that shows all the nodes connected to the MQTT broker.
(Note this does not update actively so may show nodes that are currently off or not powered up).
The decoder we want to work with is ID 28, and has the nickname “NoDAC”.
The Roc Node address was set initially to the last byte of the IP address because of the _ForceRocnetNodeID_to_subIPL directive. This prevents nodes being on the same “node” address. Once the unit has the "_ForceRocnetNodeID_to_subIPL" directive disabled, you can set the Node Address via the Rocrail “Rocnet” ID interface, and also set the node “nickname or “UID-Name” as Rocrail calls it.I would recommend leaving the Node ID as the IP address as it may help debugging later..
If you highlight a node in this tab ad press "Show", the selected node will flash its built in LED slowly. This helps find the node if you have many on your desk or layout.
If we now highlight this node, and Click “Pi02 Port Setup”, it will show us how the various ports are set up:
Port 6 is an input, but all others are outputs.
If any of the Pi02 ports were set with “Blink”, they will blink/flash with a delay set by the Delay setting.
“Invert” would invert the port phase.
Note Rocrail does not know that some ports are “FIXED”, but if you try to modify them they will revert to their “FIXED” settngs.
Pressing “Pi03 Channel Setup” shows further information about our 8 io pins:
Here we see that Pin 1 and 8 are defined as a servos.. Pin 1 is actually the “FIXED” Motor drive servo, and is a special case where Left Right, Left steps Right steps etc are defined by CV values so these values cannot be changed here.
Pin 5 has Blink set, so will be a PWM output, switching between the Left and Right PWM settings of 160 and 600.
Pin 8 is a “normal” Servo output and will switch between positions 236 and 457. Note that in Rocrail, Min and Max positions for a servo are 150 and 600.