Skip to content

Cartos - the application for reading NTAG and MIFARE cards with added features for following usage.

License

Notifications You must be signed in to change notification settings

petrzakopal/cartos

Repository files navigation

Cartos - NFC Card Reader project

currently in development

documentation will be added later

Also, the code is not finished at all. Currently rewriting the one file code from my secret Gist.

Build

Backend

Tip

Easiest way to build the backend app for the ARM64 is to run make build-arm in the project root.

Frontend

Tip

Easiest way to build the frontend app for the is to run bun run build in the project root.

Installation

Backend

Tip

It is very appropriate to copy the build app from backend/target/aarch64-unknown-linux-gnu/release/app to /cartos/backend directory of the system together with migrations and service folder. Then when running the service for the first time, install requirements using install_requirements.sh and the service using install.sh. The logs can be displayed using logs.sh

Note

This process will be probably automated in the future.

After copying the app and migrations (and cartos.db) to the target using for example scp -r app orangepi@<ip-address>:/cartos/backend, where when app is already present it is suitable to copy the app as app_new and then on the server manually rename app_new to app and restart the service using sudo systemctl restart cartos-backend.service or using frontend feature HW System Restart.

Frontend

The frontend uses bun as a runtime and build tool.

To build the frontend simply run bun run build at the frontend folder. The build artefacts can be found in build directory.

Then transfer the files of server.js and build directory to the /cartos/frontend path in the ARM64. Please note that the client side environmental varibales in Vite are embedded to the application at the runtime. So when using only client side part of the app, it is not needed to copy the .env file to the ARM64.

The service running the application can be installed using the same install.sh script as the backend. It is not needed to reload the service when new files are loaded to the target.

Run websocket testing utility on Linux

websocat

Using following command.

websocat "ws://0.0.0.0:4000/ws"

When websocat is not installed or not in path download the prebuilt binaries and run with the same argument.

./websocat.x86_64-unknown-linux-musl "ws://0.0.0.0:4000/ws"

API Requests for Bruno

For testing the api the Bruno open source tool for testing the endpoints was used. The files of bruno requests can be found in the folder bruno_api_test.

Cross compilation of the Rust application in Docker

Either create directory and file in the project root ./cargo/Config.toml and insert following values.

[build]
target = "aarch64-unknown-linux-gnu"

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

Or it can be defined in-line using following RUST_FLAGS.

RUSTFLAGS="-C linker=aarch64-linux-gnu-gcc" cargo build --release --target aarch64-unknown-linux-gnu

Also for the build the Dockerfile can be used.

The container can be build using following command.

docker build -f Dockerfile.rust.build.arm64 -t cartos-backend ./backend

Manually in bash

One approach is to log in to the bash in the docker container and perform the build process manually.

Note

This approach is not suitable for CI/CD or any automated approach.

And the image then can be run manually in the project root using docker run --rm -it -v $(pwd):/project rust-cross-aarch64 bash.

Then the build process for the ARM64 architecture can easily run using Makefile when following is specified.

arm64:
	RUSTFLAGS="-C linker=aarch64-linux-gnu-gcc" cargo build --release --target aarch64-unknown-linux-gnu

Then run the build using make arm64.

The project is build to the target/<architecture>/ directory.

Automatically

Note

This approach is suitable for CI/CD or any automated approach.

After building the docker container, just run docker run --rm -it -v $(pwd):/project rust-cross-aarch64 and the project is automatically build to the target/<architecture>/ directory.

When using docker

Caution

Buildrun does not work when cross-compiling. Could not figure how to make it work.

The file Dockerfile.rust.buildrun.arm64 can be used to build and then run the application.

To be able to use HW devices such as GPIO or NFC reader, the devices must be passed to the docker build command.

sudo docker run --device=/dev/gpiochip0 <image-name>

To be able to use GPIO and NFC using pcsd use probably the following command.

sudo docker run --device=/dev/gpiochip0 -v /var/run/pcscd/pcscd.comm:/var/run/pcscd/pcscd.comm gpio-rust-test

Run the backend as a service in Linux

sudo vi /etc/systemd/system/cartos-backend.service
sudo systemctl daemon-reload
sudo systemctl enable cartos-backend.service
sudo systemctl start cartos-backend.service
sudo systemctl status cartos-backend.service

When running on the Orange Pi 3 W

Warning

The USB ACS Reader must be reconnected after the system reboots and the service/app running cartos must be also restarted.

After the board reboots, there is a need to unplug and plug the USB of the NFC reader, then run

sudo systemctl restart cartos-backend

so the USB reader can be read by the backend application.

Note

This approach is not suitable but could not find how to make it automatically.

Services

The service for backend can be installed with the usage of files in service.

install_requirements.sh

Installs the requirements for the pcsc and other required configs.

install.sh

Installs the service to the daemon.

logs.sh

Opens logs of the cartos-backend.service.

Wifi problem

When connected to the university wifi, there is a problem with wifi, which keeps disconnecting and the drivers must be loaded to reset the connection.

sudo rmmod sprdwl_ng && sudo modprobe sprdwl_ng

Tried to change the power saving mode using following commands.

sudo vim /etc/NetworkManager/conf.d/wifi-powersave.conf

Added following configuration.

[connection]
wifi.powersave = 2

And restarted NetworkManager

sudo systemctl restart NetworkManager

When trying to delete column from the database table

Need to create a new table, copy data over to the new table and delete the old table and then rename the new table.

Also when using triggers on the table, they must be also created as new triggers on the newly renamed table.

About

Cartos - the application for reading NTAG and MIFARE cards with added features for following usage.

Resources

License

Stars

Watchers

Forks