Open sesame!

Once upon a time, in a company far, far away, they build a bike shed. The actual bike shed. Surprisingly without any bike-shedding. But then they were wondering how to give access to all the cyclists to the yard bike shed was build on. It was not a highly secured area, but still, it was behind gates so no stray dogs or stray cars could enter. They already had a remote-controlled gate via special key fob. But those were expensive, required some tracking, it took quite some time to order a new one and in general there was quite some overhead managing them.

The company was an environment-friendly company and there was plenty of cyclists. So they were looking for an alternative to the existing system. And they found one. It was a widely used system – gate being opened when authorized cell phone rings a specific number. Not a bulletproof solution, there are some attacks vectors, but as I said, their yard was no Fort Knox and the system was great from usability point of view – everybody had a cell phone.

They started to search for ready to use solution that they could integrate with their existing gates. They found plenty of solutions, but none of them was out of the box compatible with current gates. They faced a decision – redesign the whole gate, abandon the current system and migrate everybody to a new one or try to create some compatibility layer between the phone system and existing gates.

They decided to go the third way. If there has to be some interface to work with current gates anyway, why not build everything from scratch and save yourself some troubles of figuring out how cell phone management system works? They were not afraid to get their hands a little dirty. How hard can it be? The question intrigued them, so they created a whole system by themselves from scratch in one afternoon.

To create something like that, they needed some CPU to control stuff and decide who is allowed and who is not. Luckily for them, they had a spare Turris MOX, more specifically module A. They didn’t need anything special, so 512M was fine. Then also needed to be able to call the MOX. Module B supports LTE modem and they had an old one lying around for testing. Combining module B with LTE card and module A made the base of their hardware. Last but not least, to interact with the gate, they took one of the existing remote controls apart and modified it slightly to be able to control it via GPIO from MOX. Quite simple modification, the only thing to pay attention to is 1.8V power levels on MOX. And that’s all.

Now for the software part. There are two aspects to the software part. First one is the need to know when someone is calling and figure out who that is. The second part of the problem is to manage a whitelist of phone numbers and make that management easy and user-friendly.

For the first part, simple shell script suffices. To make it work, some AT commands need to be sent to the modem first, especially AT+CLIP=1 to see the number of the person calling. Then all that is left is to wait till modem announces that someone is calling by printing the following sequence:


RING
+CLIP: "+420123456789",145,,,,0

Where +420123456789 is the number calling. If it is a friend, open sesame, if it is a foe, ignore it. Either way, it is a good idea to decline the call after some action is taken by entering ATH0

For the management of the white list, something easy to use and ideally simple to implement was needed. But there is a silver bullet to most of the problems with data management – Nextcloud. The company already had a company Nextcloud instance, so the easiest way to manage whitelist was to create a shared text file with all whitelisted numbers and give write access to appropriate people. MOX needs just read access – Nextcloud has ability to share read-only link – and can download a new version every five minutes and update its internal cache from it. Really easy. And quite user-friendly – writing phone numbers in one long text file.

And that is how this company made sure that their employees can park their bikes in the yard in the new bike shed and they lived happily ever after.

Note: Any resemblance to any existing company is purely accidental, but encouraged :-).

Autor:

Zanechte komentář

Všechny údaje jsou povinné. E-mail nebude zobrazen.