Forum Replies Created
-
AuthorPosts
-
Nikos LygizosParticipant
I need to dig in the logs for finding where the delay occurs. I have found several times both locomotives do not stop at the END of a block sensor until they passed it a few car lengths. I have not observed this issue when I run Rocrail and mosquito from a fast Windows 10 system. The only difference besides hardware and OS is that mosquito on the Pi is version 1.1 and 2.0 on Windows 10 system.
Any thoughts?Nikos LygizosParticipantDo you use any MTC4PU controllers?
Nikos LygizosParticipantI thought of “shrinking” the computer running Rocrail from a laptop/desktop to something the size of Altoids box!
That means, Raspberry Pi! So I got me a RPi 4 with 4GB of memory and 32GB SD (Class 10). I do not use the NOOBS image because it is “bladed” with applications I will not need for running Rocrail on it. Actually, I used the Raspberry Pi OS Lite and installed all necessary packages manually as the “Desktop” and “Recommended” images have a lot of applications, utilities etc.
By the way, the built below is headless (no keyboard, monitor nor mouse required). For the below installation I used a Windows 10 and a Centos VM but can be done with a Mac or just a linux system.
- Download the Raspberry Pi OS Lite image and unzip the image.
- Burn the image on the SD card using Balena Etcher
- On the root directory of the image create a text file “wpa_supplicant.conf” and enter your WiFi information (do not use Note):
$ sudo nano wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US ————- 2 Letter Country WiFi Designation Here
network={
ssid=”Your Wifi SSID 5GHz prefared”
psk=”passphrase”
} - Create an empty file “ssh:
$ sudo touch ssh - Put the CD card in the Raspberry Pi and power-up
- Find the IP address of the Raspberry Pi and ssh (Putty):
ssh xx.xx.xx.xx - Login using “pi” and “raspberry” for password.
- Enter the following commands to update to the latest:
$ sudo su –
# apt update
# apt upgrade
# reboot - Change the pi default password
pi@raspberrypi:~ $ passwd - Install needed packages:
# apt install xserver-xorg
# apt install raspberrypi-ui-mods
# apt install lightdm
# apt install realvnc-vnc-server
# apt install mosquitto
# apt install libwxgtk3*
# reboot - ssh back to the Pi using the new password.
- Enter:
$ sudo raspi-config - Update the following options:
System Options –> Boot/Auto Login –> Desktop
Display Options –> Resolution –> Any but default (monitor limitations)
Interface Options –> VNC
Localisation Options –> Timezone
Performance Options –> GPU Memory -256
Advance Options –> Expand Filesystem - Final reboot:
$ sudo reboot - Install Rocrail:
$ wget https://wiki.rocrail.net/rocrail-snapshot/Rocrail-ARMHF.zip
$ unzip Rocrail-ARMHF.zip -d ~/Rocrail
$ cd Rocrail
$ desktoplink.sh - Using your RealVNC login to the Pi Desktop and start a terminal (ssh) window.
- Enter the following commands to create a Rocrail button:
$ cd Rocrail
$ desktoplink.sh - Click the “Rocrail” button and done!
You will have to re-program all you MattzoControllers with the IP of this Raspberry Pi, unfortunately.
Initially, is working great except some delayed actions. Especially from the MTC4PU “missing” commands, I think.
Enjoy!
Nikos- This reply was modified 3 years, 2 months ago by Nikos Lygizos.
Nikos LygizosParticipantThe test truck with the following MattzoControllers and components is fully operational and can run 2 PU locomotives in fully automatic/random Rocrail mode!
- 4 TrixBrix switches
- 4 TrixBrix servos
- 2 TrixBrix Signals
- 1 MattzoTrainController for Powered Up (MTC4PU)
- 1 MattzoSwitchController
- 1 MattzoSensorController
- 1 MattzoSignalController
- 8 Reed Switch GPS-14A 14mm
- 1 Crocodile Locomotive
- 1 Cargo Locomotive
Enjoy!
Nikos- This reply was modified 3 years, 2 months ago by Nikos Lygizos. Reason: added images
Nikos LygizosParticipantMy limits for one of the switch servos was off and after a few days operating it it stripped the gears. So I “pop” the hood of the servo casing, cut-off the back wall of the servo housing and after cutting the ears of the new servo it fit perfectly and works better than the original.
After trying a few Chinese micro servos I chose this servo because it has metal gears and most dimensions fit the housing. I could not find a replacement servo with the same dimensions of the original.
Lewansoul 9G Servo Micro servo Metal Gear Motor Anti Blocking servo
Nikos LygizosParticipantThank you Paul!
By the way, I got my sensors from Amazon and I did not have any issues with them:
DIYhz Reed Switch GPS-14A 14mm Plastic Anti-Interference Normally Open Magnetic Control Switch 10PCS
- This reply was modified 3 years, 2 months ago by Nikos Lygizos.
Nikos LygizosParticipantNo worries!
Cheers!
NikosNikos LygizosParticipantMattze, I am glad and provide any help for this awesome project. Btw I tried to start a new topic for Sensors but I think it went to the Cosmic Backet!
Cheers!
NikosNikos LygizosParticipantI have not seen any hang-up after re-compiling.
Nikos LygizosParticipantThank you Henk!
I will re-compile with the line commented and get back.Nikos LygizosParticipantHi! With my 2 locomotives with one hub each. After the Bluetooth pairing is completed successfully both hubs should have a steady light. Also, look at the ESP32 serial console. If everything connects then you should have something like “isConnected()=1”:
Hub 0: macAddress=90:84:2b:1b:a8:e9: isConnecting()=0 isConnected()=1 status=1
Hub 1: macAddress=90:84:2b:21:11:c9: isConnecting()=0 isConnected()=1 status=1
Also, I found out that most of the times already paired hub will re-connect to the ESP32 at any time as long as you see the serial console looping:
*** DEBUG-INFO ***
WiFi + MQTT connection Status: 1
Loco 0: Croco-1 (6051). Target speed: 0, current speed: 0, max speed: 0
Loco 1: Cargo-1 (6061). Target speed: 0, current speed: 0, max speed: 0
next hub to initialize (if any): 0
Hub 0: macAddress=90:84:2b:1b:a8:e9: isConnecting()=0 isConnected()=0 status=0
Hub 1: macAddress=90:84:2b:21:11:c9: isConnecting()=0 isConnected()=0 status=0
…….
until it connects.I hope this helps.
Nikos
Nikos LygizosParticipantSuccess!
The problem was the Hub names (hostnames?). I used the Lego Powered-Up (3.6.0) application and renamed the Hubs to “HubCroco1” and “HubCargo1”. Also, I removed all hyphens; I do not know if hyphens are significant or not. Then I used the same hostnames in the MTC4PU_Configuration.h:
…
hubConf[0] = (MattzoPUHubConfiguration) {
.hubName = “HubCroco1”,
.macAddress = “90:84:2b:1b:a8:e9”,
…
hubConf[1] = (MattzoPUHubConfiguration) {
.hubName = “HubCargo1”,
.macAddress = “90:84:2b:21:11:c9”,
and worked!Also, the Loco Hubs need to be paired every-time you Load a new firmware to the ESP32.
Some output from the working ESP32:
MattzoController booting…
Loaded mattzoControllerId from EEPROM: 40330
Connecting as MTC4PU40330 to Wifi xxxxxxxxxxxxxx…
MattzoController setup completed.
Discovering Powered Up Hubs…
Powered Up Hub found. MAC Address: 90:84:2b:21:11:c9
Initializing hub HubCroco1 (90:84:2b:1b:a8:e9)…
Connecting to hub 0…
Connection attempt to hub 0 refused.
Initializing hub HubCroco1 (90:84:2b:1b:a8:e9)…
Wifi connected. My IP address is 192.168.99.197.
(Re)connecting to MQTT 192.168.99.226…
MQTT connected, listening on topic [rocrail/service/command].
sending mqtt: roc2bricks/discovery MTC4PU40330 Powered Up Hub discovered: 90:84:2b:21:11:c9
Connecting to hub 0…
Connected to hub 0.
sending mqtt: roc2bricks/connectionStatus MTC4PU40330 HubCroco1 (90:84:2b:1b:a8:e9) connected
Initializing hub HubCargo1 (90:84:2b:21:11:c9)…
Connecting to hub 1…
Connected to hub 1.
sending mqtt: roc2bricks/connectionStatus MTC4PU40330 HubCargo1 (90:84:2b:21:11:c9) connected
*** DEBUG-INFO ***
WiFi + MQTT connection Status: 1
Loco 0: Croco1 (6051). Target speed: 0, current speed: 0, max speed: 0
Loco 1: Cargo1 (6061). Target speed: 0, current speed: 0, max speed: 0
next hub to initialize (if any): 1
Hub 0: macAddress=90:84:2b:1b:a8:e9: isConnecting()=0 isConnected()=1 status=1
Hub 1: macAddress=90:84:2b:21:11:c9: isConnecting()=0 isConnected()=1 status=1
******************1611427976: New connection from 192.168.99.197:54437 on port 1883.
1611427976: Client MTC4PU40330 already connected, closing old connection.
1611427976: New client connected from 192.168.99.197:54437 as MTC4PU40330 (p2, c1, k10).
1611427976: Will message specified (64 bytes) (r0, q0).
1611427976: rocrail/service/command
1611427976: Sending CONNACK to MTC4PU40330 (0, 0)
1611427976: Received SUBSCRIBE from MTC4PU40330
1611427976: rocrail/service/command (QoS 0)
1611427976: MTC4PU40330 0 rocrail/service/command
1611427976: Sending SUBACK to MTC4PU40330
1611427976: Received PUBLISH from MTC4PU40330 (d0, q0, r0, m0, ‘roc2bricks/discovery’, … (56 bytes))
1611427977: Received PUBLISH from MTC4PU40330 (d0, q0, r0, m0, ‘roc2bricks/connectionStatus’, … (51 bytes))
1611427978: Received PUBLISH from MTC4PU40330 (d0, q0, r0, m0, ‘roc2bricks/connectionStatus’, … (51 bytes))
1611427987: Received PINGREQ from MTC4PU40330
1611427987: Sending PINGRESP to MTC4PU40330
1611427997: Received PINGREQ from MTC4PU40330
1611427997: Sending PINGRESP to MTC4PU40330
1611428003: Received PUBLISH from MTC4PU40330 (d0, q0, r0, m0, ‘roc2bricks/battery’, … (33 bytes))Next, Rocrail and learn more of the Arduino IDE and how to connect and monitor the ESP32 through WiFi.
Cheers!
NikosNikos LygizosParticipantHello,
Today I received the ESP32 and I managed to compile and upload the MTC4PU with the custom Config.h
It seems the MQTT is connecting sometimes but after a ESP32 reset does not again. Also, I believe I have configured the Config.h correctly for 2 Loco with 2 hubs and one motor each. I see the Hub Mac addresses but when I try to connect (Bluetooth) to the Loco never does. I have attached some outputs from the serial console, mosquitto and the config file.MattzoController booting…
Loaded mattzoControllerId from EEPROM: 40330
Connecting as MTC4PU40330 to Wifi xxxxxxxxxxxx…
MattzoController setup completed.
Discovering Powered Up Hubs…
Powered Up Hub found. MAC Address: 90:84:2b:21:11:c9
Initializing hub Hub-Croco-1 (90:84:2b:1b:a8:e9)…
*** DEBUG-INFO ***
WiFi + MQTT connection Status: 0
Loco 0: Croco-1 (6051). Target speed: 0, current speed: 0, max speed: 0
Loco 1: Cargo-1 (6061). Target speed: 0, current speed: 0, max speed: 0
next hub to initialize (if any): 0
Hub 0: macAddress=90:84:2b:1b:a8:e9: isConnecting()=0 isConnected()=0 status=0
Hub 1: macAddress=90:84:2b:21:11:c9: isConnecting()=0 isConnected()=0 status=0
******************
also:
(Re)connecting to MQTT 192.168.99.226…
Failed to connect to mqtt, state=-2
*** DEBUG-INFO ***
WiFi + MQTT connection Status: 0
Loco 0: Croco-1 (6051). Target speed: 0, current speed: 0, max speed: 0
Loco 1: Cargo-1 (6061). Target speed: 0, current speed: 0, max speed: 0
next hub to initialize (if any): 0
Hub 0: macAddress=90:84:2b:1b:a8:e9: isConnecting()=0 isConnected()=0 status=0
Hub 1: macAddress=90:84:2b:21:11:c9: isConnecting()=0 isConnected()=0 status=0
******************
(Re)connecting to MQTT 192.168.99.226…
MQTT connected, listening on topic [rocrail/service/command].
*** DEBUG-INFO ***
WiFi + MQTT connection Status: 1
Loco 0: Croco-1 (6051). Target speed: 0, current speed: 0, max speed: 0
Loco 1: Cargo-1 (6061). Target speed: 0, current speed: 0, max speed: 0
next hub to initialize (if any): 0
Hub 0: macAddress=90:84:2b:1b:a8:e9: isConnecting()=0 isConnected()=0 status=0
Hub 1: macAddress=90:84:2b:21:11:c9: isConnecting()=0 isConnected()=0 status=0
******************
*** DEBUG-INFO ***
WiFi + MQTT connection Status: 1
Loco 0: Croco-1 (6051). Target speed: 0, current speed: 0, max speed: 0
Loco 1: Cargo-1 (6061). Target speed: 0, current speed: 0, max speed: 0
next hub to initialize (if any): 0
Hub 0: macAddress=90:84:2b:1b:a8:e9: isConnecting()=0 isConnected()=0 status=0
Hub 1: macAddress=90:84:2b:21:11:c9: isConnecting()=0 isConnected()=0 status=0
******************C:\Program Files\mosquitto>mosquitto.exe -c mosquitto.conf -v
1611385569: mosquitto version 2.0.5 starting
1611385569: Config loaded from mosquitto.conf.
1611385569: Opening ipv6 listen socket on port 1883.
1611385569: Opening ipv4 listen socket on port 1883.
1611385569: mosquitto version 2.0.5 running
1611385572: New connection from 192.168.99.197:49701 on port 1883.
1611385572: New client connected from 192.168.99.197:49701 as MTC4PU40330 (p2, c1, k10).
1611385572: Will message specified (64 bytes) (r0, q0).
1611385572: rocrail/service/command
1611385572: Sending CONNACK to MTC4PU40330 (0, 0)
1611385572: Received SUBSCRIBE from MTC4PU40330
1611385572: rocrail/service/command (QoS 0)
1611385572: MTC4PU40330 0 rocrail/service/command
1611385572: Sending SUBACK to MTC4PU40330
1611385582: Received PINGREQ from MTC4PU40330
1611385582: Sending PINGRESP to MTC4PU40330
1611385592: Received PINGREQ from MTC4PU40330const int NUM_LOCOS = 2;
MattzoLocoConfiguration* getMattzoLocoConfiguration() {
static MattzoLocoConfiguration locoConf[NUM_LOCOS];locoConf[0] = (MattzoLocoConfiguration) {
.locoName = “Croco-1”,
.locoAddress = 6051,
.accelerationInterval = 100,
.accelerateStep = 2,
.brakeStep = 3
};locoConf[1] = (MattzoLocoConfiguration) {
.locoName = “Cargo-1”,
.locoAddress = 6061,
.accelerationInterval = 100,
.accelerateStep = 2,
.brakeStep = 3
};return locoConf;
}const int NUM_HUBS = 2;
MattzoPUHubConfiguration* getMattzoPUHubConfiguration() {
static MattzoPUHubConfiguration hubConf[NUM_HUBS];hubConf[0] = (MattzoPUHubConfiguration){
.hubName = “Hub-Croco-1”,
.macAddress = “90:84:2b:1b:a8:e9”,
.devicePortA = MattzoPUDevice::PU_MOTOR,
.configMotorA = 1,
.devicePortB = MattzoPUDevice::NONE,
.configMotorB = 0,
.locoAddress = 6051
};hubConf[1] = (MattzoPUHubConfiguration){
.hubName = “Hub-Cargo-1”,
.macAddress = “90:84:2b:21:11:c9”,
.devicePortA = MattzoPUDevice::PU_MOTOR,
.configMotorA = 1,
.devicePortB = MattzoPUDevice::NONE,
.configMotorB = 0,
.locoAddress = 6061
};return hubConf;
}const int NUM_FUNCTIONS = 4;
uint8_t FUNCTION_PIN[NUM_FUNCTIONS] = { PU_LIGHT, 22, 4, 2 };
int FUNCTION_PIN_LOCO_ADDRESS[NUM_FUNCTIONS] = { 6051, 6051, 6051, 6051 };
const bool AUTO_LIGHTS = true;
// Digital output PIN to monitor controller operation (typically a LED)
bool STATUS_LED_PIN_INSTALLED = true; // set to true if LED is installed (if not: false)
uint8_t STATUS_LED_PIN = 0;#define TRIGGER_EBREAK_UPON_DISCONNECT false
const char* SYSLOG_APP_NAME = “MTC4PU”;
By the way during the time I was typing this post suddenly I see:
WiFi + MQTT connection Status: 1
and
1611386618: New connection from 192.168.99.197:62016 on port 1883.
1611386618: New client connected from 192.168.99.197:62016 as MTC4PU40330 (p2, c1, k10).
1611386618: Will message specified (64 bytes) (r0, q0).
1611386618: rocrail/service/command
1611386618: Sending CONNACK to MTC4PU40330 (0, 0)
1611386618: Received SUBSCRIBE from MTC4PU40330
1611386618: rocrail/service/command (QoS 0)
1611386618: MTC4PU40330 0 rocrail/service/command
1611386618: Sending SUBACK to MTC4PU40330
1611386628: Received PINGREQ from MTC4PU40330Any thoughts?
-
AuthorPosts