Replace custom python connector with ncat (#42)

* Replace custom made daemon with nmap-ncat

* Use stderr to log ncat output

* Refresh the branch
This commit is contained in:
2025-01-15 18:30:36 +01:00
committed by GitHub
parent 1e7f72e9ec
commit 90211562f9
15 changed files with 84 additions and 197 deletions

View File

@@ -23,7 +23,8 @@ security assesment, pentest, ISO certification, etc.
This project probably doesn't match your needs nor expectations. Be aware.
Your model train may also catch fire while using this software.
> [!CAUTION]
> Your model train may catch fire while using this software.
Check out [my own instance](https://daniele.mynarrowgauge.org).
@@ -49,7 +50,7 @@ It has been developed with:
## Requirements
- Python 3.10+
- Python 3.11+
- A USB port when running Arduino hardware (and adaptors if you have a Mac)
## Web portal installation
@@ -99,43 +100,52 @@ connected via serial port, to the network, allowing commands to be sent via a
TCP socket. A response generated by the DCC++ EX board is sent to all connected clients,
providing synchronization between multiple clients (eg. multiple JMRI instances).
Its use is not needed when running DCC++ EX from a [WiFi](https://dcc-ex.com/get-started/wifi-setup.html) capable board (like when
using an ESP8266 module or a [Mega+WiFi board](https://dcc-ex.com/advanced-setup/supported-microcontrollers/wifi-mega.html)).
Its use is not needed when running DCC++ EX from a [WiFi](https://dcc-ex.com/get-started/wifi-setup.html) capable board, like when
using an ESP8266 module, a [Mega+WiFi board](https://dcc-ex.com/reference/hardware/microcontrollers/wifi-mega.html), or an
[ESP32](https://dcc-ex.com/reference/hardware/microcontrollers/esp32.html) (recommended).
### Customize the settings
### Manual setup
The daemon comes with default settings in `config.ini`.
Settings may need to be customized based on your setup.
You'll need [namp-ncat](https://nmap.org/ncat/) , and `stty` to setup the serial port.
> [!IMPORTANT]
> Other variants of `nc` or `ncat` may not work as expected.
Then you can run the following commands:
```bash
$ stty -F /dev/ttyACM0 -echo 115200
$ ncat -n -k -l 2560 </dev/ttyACM0 >/dev/ttyACM0
```
> [!IMPORTANT]
> You'll might need to change the serial port (`/dev/ttyACM0`) to match your board.
> [!NOTE]
> Your user will also need access to the device file, so you might need to add it to the `dialout` group.
### Using containers
```bash
$ cd daemons
$ podman build -t dcc/net-to-serial .
$ podman run --group-add keep-groups --device /dev/ttyACM0 -p 2560:2560 dcc/net-to-serial
```
### Manual setup
```bash
$ cd daemons
$ pip install -r requirements.txt
$ python ./net-to-serial.py
$ cd connector
$ podman build -t dcc/connector .
$ podman run -d --group-add keep-groups --device /dev/ttyACM0:/dev/arduino -p 2560:2560 dcc/connector
```
### Test with a simulator
A [QEMU AVR based simulator](daemons/simulator/README.md) running DCC++ EX is bundled togheter with the `net-to-serial.py`
daemon into a container. To run it:
A [QEMU AVR based simulator](daemons/simulator/README.md) running DCC++ EX is bundled togheter with the connector
into a container. To run it:
```bash
$ cd daemons/simulator
$ podman build -t dcc/net-to-serial:sim .
$ podman run --init --cpus 0.1 -d -p 2560:2560 dcc/net-to-serial:sim
$ cd connector/simulator
$ podman build -t dcc/connector:sim .
$ podman run --init --cpus 0.1 -d -p 2560:2560 dcc/connector:sim
```
To be continued ...
> [!WARNING]
> The simulator is intended for light development and testing purposes only and far from being a complete replacement for a real hardware.
## Screenshots
@@ -146,15 +156,12 @@ To be continued ...
![Screenshot 2023-09-18 at 21-59-30 RGS 1930s short train - Railroad Assets Manager](https://github.com/daniviga/django-ram/assets/1818657/77f9b7c9-27b3-4a65-bad0-26e9cf77e623)
#### Dark mode
![Screenshot 2023-09-18 at 21-58-22 Company RGS - Railroad Assets Manager](https://github.com/daniviga/django-ram/assets/1818657/c95697c9-0897-46f4-941c-6092271e4743)
---
### Backoffice
![image](https://user-images.githubusercontent.com/1818657/175789937-3e4970a2-b37d-44c3-8605-62dabe209c65.png)
@@ -166,8 +173,3 @@ To be continued ...
### Rest API
![image](https://user-images.githubusercontent.com/1818657/180622471-ade06c84-c73b-41d5-a2a7-02a95b2ffc02.png)