mqTrains/getting/ready HowWhatWhen

Okay, we are getting closer to the release, so you might want to start getting some parts and install some software! We might just release the binary files first, in which case you would need to read up on PlatformIO, or if we just want you to get lost in all the details, we will upload all the code into github or gitlab to use with the Arduino IDE.

So, starting with the latter, the Arduino IDE (we recommend at least version 1.8.12) is needed with the tool set to compile and upload the code (ESP8266 Community version 2.7.4 recommended), as well as the little tool to upload the file system (at least version 2.6.0) with the web pages and .json configuration files (how to here).

And then you are going to need all the libraries installed required to make this work. You should be able to download and install most of them within the Arduino IDE, just make sure that the ESPAsyncWebServer is also installed, even though it might come from another package when you do the search in Manage Libraries… (Ctrl+Shift+I). If not, just as easy to download and unzip the code from here:

Here is the list with the versions required:

  • Wire at version 1.0
  • LittleFS at version 0.1.0
  • JSON
    • ArduinoJSON by Bernoit Blanchon 6.17.2 (was 6.15.2)
  • Queue
    • ArduinoQueue by Einar Arnason, version 1.2.3
  • i2c IO
    • Adafruit_MCP23017_Arduino_Library at version 1.1.0
  • i2c pwm servos:
    • Adafruit PWM Servo Driver Library at version 2.4.0
  • MQTT
    • PubSubClient by Nick O’Leary Version 2.8.0
  • WebServer:
    • ESPAsyncWebServer at version 1.2.3
    • ESPAsyncTCP at version 1.2.2
      • cd libraries && git clone *
  • mDNS:
    • esp8266_mdns at version 1.1.7
  • Hash at version 1.0

Ok, now that you have all the software tools under control, here is the minimum Hardware needed:

  • Computer to run all the software above on, and that includes operating systems like Windows, Linux and Mac, even Raspbian.
  • A USB connector for a USB cable to go to the ESP8266 programmer
  • An ESP8266 programmer board that makes USB into RX/TX, provides 3v3 to the ESP and has a switch or button to pull the GPIO low on ESP power up, to put it in boot mode.
  • And ESP8266, and this can be any NodeMCU variant, but in order to make this as inexpensive as possible, and limit the growth in software, an ESP-01 is sufficient to connect to the i2c modules or the 1-wire LEDs for the first round
  • A PCA9685 PWM driver module, with a 5V power supply capable of enough Amps to control all you 16 servos from anywhere to anywhere else, even at startup, when they all will consume power!
  • Or a MCP23017 module with the 16 I/O pins to read sensors or control ouputs (3.3V at this point)
  • Or a whole bunch of WS2811 or WS2812b devices to control LEDs on one looooong wire.
  • We are in the process of making the interface hardware between the Modules and ESP01, but if you can solder 4 wires (3v3, GND, SCL and SDA) on top of the ESP01 (or to the NodeMCU) you are ready.

Debugging/your/MQTT help!

Starting mosquitto from the command line, you can use the ‘-v’ (or ‘–verbose’) option for showing verbose messages…this will override the logtype option in the config file. So first step, when something is not going right, start the MQTT server manually with mosquitto -v and watch what the server does while you debug the problem.

If you don’t have direct access to the Broker/Server, you can also check out MQTTBox, works on most platforms…great tip from David B., thank you.

Create a new MQTT Client, with some unique MQTT Client Name (MeBox will work), select the protocol you are using in your application, and enter the hostname or IP address for the Host. Enter Username and Password, if used, and check or uncheck all the other boxes that are application to your setup. Then click Save and selecting the “MeBox” client in the list, will allow you to add Publishers to Publish to a Topic, or Subscribers to Subscribe to one or more Topics, with the wildcards (Single Level ‘+’ and Multilevel ‘#’) , as usual.

Very easy to monitor and interact with the MQTT Server: a Published message has a “Publish again” arrow, avoiding quite a but of typing.; restarting MQTTBox will automatically connect (if the option was selected), but you will need to click the Subscribe button in each Subscriber window.


Uploading/code/to/ESP8266/with mqTrainsIO.ino.bin

Monitoring the verbose output in the debug window in the Arduino 1.8.12 IDE, we see:

C:\Users\name\AppData\Local\Arduino15\packages\esp8266\tools\python3\3.7.2-post1/python3 C:\Users\name\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.0/tools/ --chip esp8266 --port COM4 --baud 115200 --before default_reset --after hard_reset write_flash 0x0 mqTrainsIO.ino.bin v2.8
Serial port COM4

Enable verbose output with Settings (Ctrl+Comma). File -> Preferences -> Show verbose output during: [ x ] compilation [ x ] upload


Setting/up/MQTT/Broker mosquitto


mosquitto-1.6.12a-install-windows-x64.exe (example)

Select Files and Service

To start the service, Computer Management (right-click on My Computer, Manage) -> Services and Applications->Services->Mosquitto Broker->right click->Start

(You can also set the service to Automatic in right click on the service->Properties->Startup type)

If not run as a service, you can start it with
C:\”Program Files”\mosquitto\mosquitto.exe -v -c “C:\Program Files\mosquitto\mosquitto.conf”

To test, run:
C:\Program Files\mosquitto\mosquitto_sub -h localhost -v -t “TxNamib/#”

If the service is not running or accessible, the error wil show:
Error: No connection could be made because the target machine actively refused it.

Else, you will only see a message if it was “retained”, or you publish something to TxNamib now
C:\”Program Files”\mosquitto\mosquitto_pub -h localhost -t “TxNamib/servo.2003/03” -r -m “CLOSED”
C:\”Program Files”\mosquitto\mosquitto_pub -h localhost -t “TxNamib/servo.2003/03” -r -m “THROWN”

Ubuntu and Raspberry Pi (3, 4, 400 and Zero W):
sudo apt-get install mosquitto


snap install mosquitto

Older versions of Ubuntu:
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update


We/are/live TRUE

Welcome to the mqTrains WordPress site. This is our first post!