I saw in China's bus system, that there are devices inside the bus which can handle e-payments. The process is something like this:
- Passengers come in the bus.
- Passengers use a QR-code in their smartphone app to wipe on the device's screen (the QR code scanner)
- If passengers charge successfully, they are allowed a seat on the bus. If not, the device sounds some alerts.
I'm trying to implement this system for my project in my university. At first, I used a Raspberry Pi and a QR code scanner module to recognize the QR-code and push the data via Wi-Fi to the API on the remote server. My way of doing is that every time the device receives a QR code, it immediately sends that data to the API. Then the API handles all things and sends a response back to the device.
Everything works well. However, a problem occurs is that it seems taking a lot of time between each sendings and I'm not really handling some unexpected cases such as a lost connection in sending data to API.
For example, when the first passenger comes and put the QR-code of his phone's app on the device but it takes around 4-6 seconds for completing the whole process (included sending the passenger's data to server's API, API handling charging, balance processing, then sending a response back to the device for checking whether that passenger is allowed to come or not). Sometimes, the device loses connection, so the passengers can't use the device.
So, I came up with the idea that:
- I will synchronize the passenger's key data (Id, name, balance) on the database with the device's storage.
- Now, processing payments will be directly implemented on the device. For instance, the device will check the passenger's QR code and then compare with the data in its storage to handle whether that passenger can come in or not.
- After all passengers finished their check-in (it means when the bus moving), the device's storage will again synchronize with the server's database.
I think if the system runs in this way, it will be smooth as all things will be done locally until they synchronize.
So that is the brief summary of my system as well as my idea. However, I'm not in China and my country also has not implemented a similar system so far so I do not have any references sources.
I would very appreciate it if you guys can suggest me some directions or any related references about this new idea.
- Is it possible or not?
- Are there some hidden dangerous logics inside?
- If yes, can you help me with some hints? For example, what is the most suitable time for synchronizing data between server's database and device's database?
- On server side, I use ASP.net to write APIs, and working with passenger data is not hard (find, edit, update) by using the Entity Framework. But how can I do the similar thing in Raspberry Pi for local processing?