-
@ Arjen
2025-01-27 03:22:10
At Nostriga in the middle of last year I got introduced to TollGate, a project to resell internet access, I was fascinated and hyped for this to become a thing. Later during SEC-03 I got involved in the development of TollGate and helped work out the idea utilizing Nostr to make the experience of using a TollGate super smooth. That's where the idea started to make a cross-platform app that would autoconnect and start streaming sats to TollGates for internet access.
I'd been working on it here and there and this week I feel like I got in to the developer high (i'm sure some of you know what that feels like) and I just wanted to see the android app work! So as the week moved along I just kept being drawn in. And progress there was! The vision we had during SEC is coming to be a reality very fast.
**TL;DR** There's a demo video at the bottom.
## Quick CI/CD update
I've been talking to DanConwayDev to work together on getting the UI for the pipelines into GitWorkshop, which would be the perfect place for it. He's in the middle of a rewrite, so when that is progressing a bit more we'll cooperate on making this part of it, stay tuned!
## Whoami
I started by creating a service that would run on every TollGate router that a client can use to fetch their own MAC address that's later included in the payment. The MAC address is the anchor for the router to allow/disallow access. The problem we have on Android is that the operating system restricts access to this information. But since we control the router, we can work around it by creating a predictable endpoint that gives us back this answer.
## Beacon frames
Routers use something called Beacon Frames, which are sent out regularly and it is the thing your phone looks at when scanning for wifi networks. It contains the name of the network (SSID) and a whole bunch of other stuff you don't usually see.
We're utilising these beacon frames to add some information specific to tollgates. There is a field in these beacon frames called 'vendor elements'. Which is originally only intended for use by manufacturers of routers. But ofcourse we can utilize them too. Which is exactly what we do.
I eperimented with these beacon frames to see how many of them we can broadcast. It turns out that we're limited to only one of them, but the good news is we can fit up to 249 characters (256 - a few reserved ones) in there.
This is amazing because it will fit everything we need in there.
We put in:
- Nostr npub
- TollGate version
- Gateway IP (required to get around OS limitations)
- allocationType (KiB/Minutes)
- price per 1024 units (eg: 104900 sats per 1024 KiB)
- price units (sat)
So now any tollgate can broadcast this info, which is used by clients to decide wether or not they should connect. And if they do, where the payment should go.
## Suggestions, Suggestions, Suggestions
Unfortunately, Android in the past few years has locked down the wifi api's and we can no longer fully autoconnect to networks. Instead we have to use the 'wifi suggestions' API. As the name implies, it will only suggest a nework to a user using a silent notification that they have to press to actually connect. But alas, we'll work with that and if it's the only user-action required, that's still quite okay.
It took me quite a while to figure out the way the OS handles these suggestions, but eventually I got it to work and was able to get the flow to work!
## Adding the payment
Ok this part doesn't include an actual payment yet, but all the components are in place now for a (semi-)automatic tollgate connection, which is EPIC!
In this version i still manually tap 'connect', but this can and will be automatic soon.
So the steps are as follows (this happens in a few seconds):
- 📲 TollGate App scans for networks and filters for TollGates
- 👤 User taps Connect [to be automated]
- 📲 TollGate App suggests network
- 👤 User taps suggestion notification to connect
- 🤖 Android connects to network
- 📲 TollGate App fetches it's own MAC address (whoami service on router)
- 📲 TollGate App Connects to Nostr relay (running on the router)
- 📲 TollGate App Sends payment
- 🛜 Router receives payment (merchant module)
- 🛜 Router creates session (merchant module)
- 🛜 Router opens the gate for user (valve module)
- 🛜 Router closes the gate for user, when purchase runs out (valve module)
I made this recording, it has a small caveat that at the end the page loaded because I was on 5g, the OS still thought the wifi network had a captive portal open. But there's an API to mark it as dismissed, which we can easily implement. So that's an issue we can overcome!
## Demo video
https://cdn.satellite.earth/ede26976043a0b8edf278ea51aa0c00e721d2134c4e456928192090ea660bda0.mp4