The problem is quite simple really. I'm trying to create a site, where the user can add a physical device to a database. Every device has its own unique id, which is stored in the database.
However, I want to make sure, that whoever types in the device id actually has access to the device, so that someone can't just type in a bunch of numbers and maybe get lucky.

To do this there is a button on the device, which makes a call to the webserver (HTTP).
I thought doing it like this:

  1. The user types in a device id
  2. The user gets redirected to a "waiting" site, which checks the database every x seconds for new entries, and checks if they're a match to the device id.
  3. When the button is pressed on the device, an entry gets made in the database which allows the user to continue from the "waiting" site.

The problem is, I don't know how to make the waiting site. As I see it, the way I have described step 2 above will create a lot of unnecessary calls to the database, so I was wondering how to do this effeciently?

Thanks in advance

  • 3
    You don't have to check the database every x seconds. Just put a submit button on the waiting page and ask the user to click it after they've pressed the button on the device. – Robert Harvey Aug 16 '16 at 14:42
  • This is a good way to solve the database problem, but I feel it adds unnecessary UX components. I want the user to be able to navigate the system with ease which is why I would like this mundane task to be solved by the software - if it's possible of course. – user2563949 Aug 16 '16 at 14:52
  • Does the device have any sort of screen? – Karl Bielefeldt Aug 16 '16 at 16:42
  • @KarlBielefeldt Unfortunately no. There's only a button, accelerometer and wifi. – user2563949 Aug 16 '16 at 16:48
  • Well, your question says that they have to push the button on their device before they can continue. I just assume that "continue" means that they eventually click a submit button somewhere. – Robert Harvey Aug 16 '16 at 19:50

Depending on how real-time adding a device should be, consider making the two processes disconnected. Pushing the button logs the id along with a timestamp. Registering an ID on the website logs the id along with another timestamp. Have a process check the pending registrations from the site against the pending devices and when they match, allow the user access by marking the device in the database as belonging to the user. This can easily be done with a job that runs at a given interval.

Alternatively, if this has to be semi-real time you can simply ask the user to first press the button on the device and check the registration once when the ID is entered on the website. If that fails, simply ask them to either wait and try again or push the button on the device again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.