Willkommen bei MattzoBricks › Foren › MattzoTrainController for Bluetooth (MTC4BT) › First configuration of MTC4BT – how connect to the Lego hub?
- Dieses Thema hat 18 Antworten sowie 3 Teilnehmer und wurde zuletzt vor vor 8 Monaten, 2 Wochen von
Matthias Runte aktualisiert.
-
AutorBeiträge
-
-
Januar 14, 2025 um 09:04 Uhr #8069
Mitja Cernich
TeilnehmerHello 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.
-
Januar 14, 2025 um 09:23 Uhr #8070
Matthias Runte
AdministratorHello Mitja,
could you post your controller_config.json file and your my_platformio.ini file here?Thanks!
Cheers,
Mattze-
Diese Antwort wurde vor 8 Monaten, 2 Wochen von
Matthias Runte geändert.
-
Diese Antwort wurde vor 8 Monaten, 2 Wochen von
-
Januar 14, 2025 um 09:50 Uhr #8072
Mitja Cernich
TeilnehmerHi 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 -
Januar 14, 2025 um 09:58 Uhr #8073
Matthias Runte
AdministratorOkay, 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?
-
Diese Antwort wurde vor 8 Monaten, 2 Wochen von
Matthias Runte geändert.
-
Diese Antwort wurde vor 8 Monaten, 2 Wochen von
-
Januar 14, 2025 um 10:14 Uhr #8075
Mitja Cernich
TeilnehmerCorrect 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 thenetwork_config.json
file.
; Configure the controller in thecontroller_config.json
file.
; See the/data_example
folder for example configuration files.
; Runplatformio.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 -
Januar 14, 2025 um 10:25 Uhr #8076
Matthias Runte
AdministratorI 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. -
Januar 14, 2025 um 10:36 Uhr #8077
Mitja Cernich
Teilnehmerloco_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: 0The output log is identical to the configuration from before, with just one hub. I made a mistake writing the file loco_simple.json?
-
Januar 14, 2025 um 10:40 Uhr #8078
Matthias Runte
AdministratorThe 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.
-
Januar 14, 2025 um 10:43 Uhr #8079
Mitja Cernich
TeilnehmerOk thank you, but if this were the problem, neither the controller_config.json file nor the network_config.json file should work. Correct?
-
Januar 14, 2025 um 10:59 Uhr #8080
Mitja Cernich
TeilnehmerIf 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: 0controller_config.json:
{
“name”: “MTC4BT”,
“espPins”: [],
“locos”: [],
“locoConfigs”: [
“/loco_simplezzzz.json”
]
}-
Diese Antwort wurde vor 8 Monaten, 2 Wochen von
Mitja Cernich geändert.
-
Diese Antwort wurde vor 8 Monaten, 2 Wochen von
-
Januar 14, 2025 um 11:15 Uhr #8082
Matthias Runte
AdministratorPlease 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. -
Januar 14, 2025 um 11:24 Uhr #8083
Mitja Cernich
TeilnehmerI 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: 0However, if I delete the content of the destination, the ESP32 starts searching for Bluetooth devices.
-
Januar 14, 2025 um 12:01 Uhr #8084
Mitja Cernich
TeilnehmerI 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…
-
Januar 14, 2025 um 13:01 Uhr #8085
Matthias Runte
AdministratorTo 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”: []
}-
Januar 14, 2025 um 15:10 Uhr #8089
Mitja Cernich
TeilnehmerI 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!!!
-
-
Januar 14, 2025 um 13:02 Uhr #8086
Matthias Runte
AdministratorTry it, but my guess is that this is not the problem, but somehow you upload the wrong configuration directory up to the controller.
-
Januar 14, 2025 um 13:06 Uhr #8087
Matthias Runte
Administrator.. 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).
-
Januar 14, 2025 um 13:47 Uhr #8088
Hilbert B
AdministratorThere 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
-
Januar 14, 2025 um 17:46 Uhr #8090
Matthias Runte
AdministratorMitja,
that’s great news! Happy to hear that it works now. Welcome to Mattzobricks!Cheers,
Mattze
-
-
AutorBeiträge
- Du musst angemeldet sein, um auf dieses Thema antworten zu können.