Before programming the system I like to create an UML diagram of what I am going to create, for communication purposes and because it provides an overview of what elements I need to consider. Here you see the UML diagram, and below a short explanation of the important aspects. Click to view the whole image.
Below I have written an elaboration on the classes displayed in the UML about their role in the system.
This is the main Arduino file (.ino), here I put all variables the client needed to have accessible for changing, like network settings and the specific pins the readers are connected to.
As the control of the RFID readers was quite complicated, even with the external library MFRC522.h by Miguel Balboa, I decided to write a wrapper so the game functions wouldn’t get cluttered with code specific for the RFID readers.
To keep everything as clean as possible, all functions concerned with MQTT communication and Json parsing were separated to these two files.
I always like to keep my code as clear as possible so reading back is no effort. When I'm working on commission I like to take it one step further, and document the code so the client won't even have to read back what was agreed concerning the use of the product. To show this I decided to share the setup part of the project.
The Arduino framework is very barebones, it lacked some string functions I needed for the parsing of Json messages, which were sent via MQTT to conrol the game. For this I created my own helper functions.