Scan2Cursor — Using My Phone as a Barcode Scanner for My Computer
Visit github.com
Your phone is the barcode scanner 📱How it started
This project started as a small side project. I wanted to use my phone as a barcode scanner. I scan a barcode with the phone, and it should fill a textbox on the computer, or wherever the cursor is, just like a normal USB scanner would. At first I only wanted an alternative to a barcode scanner device, but later I realized that it can be used in a billing app, a spreadsheet or any web form.
I did not want to install any app or pay a subscription for one of the existing SaaS tools, so I built a simple relay.
Scanning from a different network
One of the best things I have done in this project is making it accessible over a different Wi-Fi or mobile data. In a warehouse, for example, the staff counting stock use handheld devices to scan, and they can't always rely on the warehouse Wi-Fi because it might be weak in some parts. There may already be strong network coverage, but this project covers that (just in case). A handheld scanner surely beats a mobile scanner. A phone has to depend on its camera to scan, it is not ergonomic, and there is the battery as well. Still, this has been a fun project to do.
Despite the limitations of a mobile phone, it is good to have an alternative. When the computer and the phone are on the same Wi-Fi, the phone can just use the IP address of the computer to relay the barcode data. But for a different Wi-Fi or an external network, there has to be something in between to relay the information. This is called tunneling. It is the same concept as a VPN, where we get connected to a network through a different path. I use a Cloudflare tunnel to connect the phone from an external network. So basically there are two QR codes to pair a phone: one for the same Wi-Fi and one for an external network.
The Cloudflare tunnel works nicely, but when it restarts it gets a new address, so there is a new QR code to pair the phone (for the external network).
Not losing scans
I also identified a problem with the connection dropping during scanning, which can slow down the work. So there is an internal queue on the mobile page, which also solves the issue of going offline while scanning. The scanned barcodes are pushed into the queue, and when the network is stable they are sent to the computer.
Why Rust ???
Using Rust for this project was a deliberate choice because of its small memory footprint and binary size. It is just a relay app, so it does not have to be big and bulky. At first I tried Node.js, but it was roughly 50 MB in size, so I moved to Rust to save storage and memory.