Welcome to MattzoBricks Forums MattzoTrainController for Bluetooth (MTC4BT) First configuration of MTC4BT – how connect to the Lego hub?

Viewing 17 reply threads
  • Author
    Posts
    • #8069
      Mitja CernichMitja Cernich
      Participant

      Hello everyone!

      First of all, I would like to congratulate Mattzo and the entire team for this truly epic project! Having many LEGO trains at home, I wanted to build a layout in the garage with multiple levels and a hidden station, but I immediately had a doubt: how can I control all the trains simultaneously, and especially all the switches, so that no accidents occur? So, I started searching on the internet and came across this wonderful project on YouTube. Congratulations again to all of you, and keep up the great work!

      Back to the topic:
      I followed several tutorials on the website, the readme files, the forum, and GitHub, and I managed to flash the ESP32 with the MTC4BT firmware. I was able to connect to the home WiFi and the MQTT broker (which I installed on the PC running Rocrail), and I searched and finding the MAC address of a hub (I’m starting with just one hub – hub updated to the last Lego version). After entering the MAC address in the loco_simple.json file located in folder data/MTC4BT1, I uploaded the filesystem to the ESP32. I turned on the LEGO hub, but the white light blinks a couple of times and then turns off, as if it can’t connect to the ESP32. I can share all the steps I took, if that might help resolve the issue.

      Where am I going wrong? Thank you.

    • #8070
      Matthias RunteMatthias Runte
      Keymaster

      Hello Mitja,
      could you post your controller_config.json file and your my_platformio.ini file here?

      Thanks!

      Cheers,
      Mattze

    • #8072
      Mitja CernichMitja Cernich
      Participant

      Hi Mattzo, I’m attaching the configurations you requested. Thank you so much.
      controller_config.json:

      {
      “name”: “MTC4BT”,
      “espPins”: [],
      “locos”: [],
      “locoConfigs”: [
      “/loco_simple.json”
      ]
      }

      loco_simple.json:
      {
      “locos”: [
      {
      “address”: 1,
      “name”: “60197”,
      “bleHubs”: [
      {
      “type”: “PU”,
      “address”: “90:84:2b:cf:81:47”,
      “channels”: [
      {
      “channel”: “A”,
      “attachedDevice”: “motor”
      },
      {
      “channel”: “B”,
      “attachedDevice”: “motor”,
      “direction”: “reverse”
      }
      ]
      }
      ]
      }
      ]
      }

      platformio.ini:

      ; PlatformIO Project Configuration File
      ;
      ; Build options: build flags, source filter
      ; Upload options: custom upload port, speed and extra flags
      ; Library options: dependencies, extra library storages
      ; Advanced options: extra scripting
      ;
      ; Please visit documentation for the other options and examples
      ; https://docs.platformio.org/page/projectconf.html

      [platformio]
      extra_configs = my_platformio.ini

      [common]
      platform = espressif32
      framework = arduino
      board_build.filesystem = spiffs
      lib_deps =
      knolleary/PubSubClient@^2.8
      h2zero/NimBLE-Arduino@^1.4.3
      bblanchon/ArduinoJson@^7.3.0
      arcao/Syslog@^2.0.0
      arduino-libraries/Ethernet@^2.0.2
      build_flags =
      -DCONFIG_BT_NIMBLE_MAX_CONNECTIONS=9
      -DARDUINOJSON_ENABLE_COMMENTS=1
      -Iinclude
      monitor_speed = 115200

      [env]
      platform = ${common.platform}
      board_build.filesystem = ${common.board_build.filesystem}
      framework = ${common.framework}
      lib_deps = ${common.lib_deps}
      monitor_speed = ${common.monitor_speed}
      upload_port = ${common.upload_com_port}
      build_flags = ${common.additional_build_flags} ${common.build_flags}

      [env:esp32doit-devkit-v1]
      board = esp32doit-devkit-v1

    • #8073
      Matthias RunteMatthias Runte
      Keymaster

      Okay, please also post the my_platformio.ini file.

      The configuration in your Eurostar is two PU train motors attached to one PU hub, correct?

      What do you see in the serial log? Does it say that the controller is looking for one hub?

    • #8075
      Mitja CernichMitja Cernich
      Participant

      Correct configuration: 2 PU train motors attached to one PU HUB.

      my_platformio.ini file:

      [platformio]
      default_envs = esp32doit-devkit-v1

      ; This controller must be configured through config files in the folder you define below.
      ; Configure your network in the network_config.json file.
      ; Configure the controller in the controller_config.json file.
      ; See the /data_example folder for example configuration files.
      ; Run platformio.exe run --target uploadfs to upload the data-folder content to the ESP32.
      ; moved to my_platformio.ini
      ; for Linux you have to add a / before $PROJECT_DIR
      data_dir = /$PROJECT_DIR/data/MTC4BT1

      [common]
      ; To show memory usage every minute, uncomment the line -DTICKER=1
      ; To use w5500 module for wired connections, uncomment the line -DWIRED
      ; To see what the hubs report back on not cached messages uncomment the lines,
      ; this is for debugging only and should only be used if instructed to do so
      ; To reduce the delays in the BLE driver loops change the value of DRIVERTASKDELAY,
      ; changing this yourself without a hint of the developers may cause strange behaviors
      ; and even crashes!
      additional_build_flags =
      ; -DWIRED
      ; -DTICKER=1
      ; -DDEBUGNOTIFYBUWIZZ2
      ; -DDEBUGNOTIFYPU
      ; -DDEBUGNOTIFYPUREMOTE
      ; -DDRIVERTASKDELAY=250
      ; -DPUFREELISTACTIONDELAY=100
      upload_com_port = /dev/cu.usbserial-0001
      ; for macOS, just as example
      ;upload_com_port = /dev/tty.usb

      [env:esp32doit-devkit-v1]

      ; Use either the ‘upload_port’ line above if the ESP32 is connected to your PC’s USB port or enable/configure the three lines below to use OTA updates.
      ; The IP address should match that of the controller on your network.
      ; The <otaPassword> should match the current password from the network_config.json you previously uploaded to the controller.
      ;upload_protocol = espota
      ;upload_port = 192.168.x.y
      ;upload_flags = –auth=<ota password>

      **the data_dir has “/” in front of $PROJECT_DIR/data/MTC4BT1 because I use a macbook**

      serial log:
      [0008] [1] [INFO] Setup: Initializing BLE…
      [0009] [1] [INFO] Setup: MattzoTrainController for BLE running.
      [0010] [1] [INFO] Setup: Number of locos to discover hubs for: 1
      [0011] [1] [INFO] Setup: Number of remotes to discover hubs for: 0

    • #8076
      Matthias RunteMatthias Runte
      Keymaster

      I haven’t compiled the MTC4BT on a Mac yet, but basically everything seems to be alright. In the serial log it also shows that you have configured one hub, so that’s very likely okay if you point with the data_dir variable to the directory where your controller_config.json etc. is in. For validation, you could add another hub for testing, the you should see 2 hubs in the serial log.

      It is possible that the PU hub does not connect on first try. Try a couple of times in a row.

      Other possible causes:
      – The ESP32 hardware is broken. Try another one. I had that a couple of times in the post myself.
      – The MAC address is wrong. The beginning looks great, though. 90:84:2b:**:**:** is a typical start for a PU hub.

    • #8077
      Mitja CernichMitja Cernich
      Participant

      loco_simple.json:

      {
      “locos”: [
      {
      “address”: 1,
      “name”: “60197”,
      “bleHubs”: [
      {
      “type”: “PU”,
      “address”: “90:84:2b:cf:81:47”,
      “channels”: [
      {
      “channel”: “A”,
      “attachedDevice”: “motor”
      },
      {
      “channel”: “B”,
      “attachedDevice”: “motor”,
      “direction”: “reverse”
      }
      ]
      }
      ]
      },
      {
      “address”: 2,
      “name”: “60051”,
      “bleHubs”: [
      {
      “type”: “PU”,
      “address”: “”,
      “channels”: [
      {
      “channel”: “A”,
      “attachedDevice”: “motor”
      },
      {
      “channel”: “B”,
      “attachedDevice”: “motor”,
      “direction”: “reverse”
      }
      ]
      }
      ]
      }

      ]
      }

      However, I notice that the output log is as follows:

      [0008] [1] [INFO] Setup: Initializing BLE…
      [0009] [1] [INFO] Setup: MattzoTrainController for BLE running.
      [0010] [1] [INFO] Setup: Number of locos to discover hubs for: 1
      [0011] [1] [INFO] Setup: Number of remotes to discover hubs for: 0

      The output log is identical to the configuration from before, with just one hub. I made a mistake writing the file loco_simple.json?

    • #8078
      Matthias RunteMatthias Runte
      Keymaster

      The root cause of your problem is that data_dir is pointing to the wrong directory, or that you have the wrong files in that directory. If you solve this issue, it should work.

    • #8079
      Mitja CernichMitja Cernich
      Participant

      Ok thank you, but if this were the problem, neither the controller_config.json file nor the network_config.json file should work. Correct?

    • #8080
      Mitja CernichMitja Cernich
      Participant

      If I change the destination route in the controller_config.json file and add a route that doesn’t exist, the log always returns the same data:

      [0008] [1] [INFO] Setup: Initializing BLE…
      [0009] [1] [INFO] Setup: MattzoTrainController for BLE running.
      [0010] [1] [INFO] Setup: Number of locos to discover hubs for: 1
      [0011] [1] [INFO] Setup: Number of remotes to discover hubs for: 0

      controller_config.json:
      {
      “name”: “MTC4BT”,
      “espPins”: [],
      “locos”: [],
      “locoConfigs”: [
      “/loco_simplezzzz.json”
      ]
      }

    • #8082
      Matthias RunteMatthias Runte
      Keymaster

      Please check:
      – You uploaded the new configuration using the platform.io action “Upload Filesystem image” not “Upload”.

      Try adding a line break ahead of the data_dir line (I know, that’s a very far fetch).

      If this doesn’t help, it becomes difficult to help you from remote. But the problem is
      surely in this area where we are presently poking.

    • #8083
      Mitja CernichMitja Cernich
      Participant

      I always use ‘Upload Filesystem Image.’ It uploads all the configurations of all the files, including the loco_simple.json file, because if I delete the content of this file and upload again, the ESP starts searching for Bluetooth devices. So the upload works. The problem is in the part of the code in controller_config.json, specifically:

      “locoConfigs”: [ “/loco_simple.json” ]

      If I change the destination by entering one that doesn’t exist (like: “/loco_simplexxx.json”, it always returns the same log:
      0008] [1] [INFO] Setup: Initializing BLE…
      [0009] [1] [INFO] Setup: MattzoTrainController for BLE running.
      [0010] [1] [INFO] Setup: Number of locos to discover hubs for: 1
      [0011] [1] [INFO] Setup: Number of remotes to discover hubs for: 0

      However, if I delete the content of the destination, the ESP32 starts searching for Bluetooth devices.

    • #8084
      Mitja CernichMitja Cernich
      Participant

      I followed the same steps on a Windows PC, and I have the same issue. The path “/loco_simple.json” in the controller_config.json file doesn’t work…

    • #8085
      Matthias RunteMatthias Runte
      Keymaster

      To validate your finding, you should put the content of loco_simple into the controller_config.json file and test it. The file should look like this:

      {
      “name”: “MTC4BT”,
      “espPins”: [],
      “locos”: [
      {
      “address”: 1,
      “name”: “60197”,
      “bleHubs”: [
      {
      “type”: “PU”,
      “address”: “90:84:2b:cf:81:47”,
      “channels”: [
      {
      “channel”: “A”,
      “attachedDevice”: “motor”
      },
      {
      “channel”: “B”,
      “attachedDevice”: “motor”,
      “direction”: “reverse”
      }
      ]
      }
      ]
      },
      {
      “address”: 2,
      “name”: “60051”,
      “bleHubs”: [
      {
      “type”: “PU”,
      “address”: “”,
      “channels”: [
      {
      “channel”: “A”,
      “attachedDevice”: “motor”
      },
      {
      “channel”: “B”,
      “attachedDevice”: “motor”,
      “direction”: “reverse”
      }
      ]
      }
      ]
      }
      ],
      “locoConfigs”: []
      }

      • #8089
        Mitja CernichMitja Cernich
        Participant

        I followed your advice, and it works! Now the log shows 2 hubs, and the first configured hub, as soon as I turn it on, flashes twice and then the LED stays solid, so it connects successfully.

        controller_config.json:

        {
        “name”: “MTC4BT”,
        “espPins”: [],
        “locos”: [
        {
        “address”: 1,
        “name”: “60197”,
        “bleHubs”: [
        {
        “type”: “PU”,
        “address”: “90:84:2b:cf:81:47”,
        “channels”: [
        {
        “channel”: “A”,
        “attachedDevice”: “motor”
        },
        {
        “channel”: “B”,
        “attachedDevice”: “motor”,
        “direction”: “reverse”
        }
        ]
        }
        ]
        },
        {
        “address”: 2,
        “name”: “60051”,
        “bleHubs”: [
        {
        “type”: “PU”,
        “address”: “90:84:2b:cf:83:47”,
        “channels”: [
        {
        “channel”: “A”,
        “attachedDevice”: “motor”
        },
        {
        “channel”: “B”,
        “attachedDevice”: “motor”,
        “direction”: “reverse”
        }
        ]
        }
        ]
        }

        ]
        }

        Thank you to all!!!

    • #8086
      Matthias RunteMatthias Runte
      Keymaster

      Try it, but my guess is that this is not the problem, but somehow you upload the wrong configuration directory up to the controller.

    • #8087
      Matthias RunteMatthias Runte
      Keymaster

      .. and please check that you are not using special characters for the ‘”‘ characters. In JSON files, it needs to be ASCII characters 34 (decimal) which equals x22 (hexadecimal).

    • #8088
      Hilbert BHilbert B
      Keymaster

      There a two hubs defined, but only one has an address.

      
      [0010] [1] [INFO] Setup: Number of locos to discover hubs for: 1
      

      It is looking for one hub.

      And it will show BLE devices in the log that the ESP is “seeing”.

      Flashing two times means the hub is searching, it should turn solid if it is discovered by MTC4BT.

      The serial log should tell you something similar.

      Hilbert

    • #8090
      Matthias RunteMatthias Runte
      Keymaster

      Mitja,
      that’s great news! Happy to hear that it works now. Welcome to Mattzobricks!

      Cheers,
      Mattze

Viewing 17 reply threads
  • You must be logged in to reply to this topic.