Getting feedback on our code! Internet of Things printer that reads RFID cards

Sparkers,

Hope you’re all well. I’m building an Internet of Things-connected printer that reads RFID cards. The backend server gets the RFID card’s ID through Spark.publish, finds a user associated with it and then prints out a chit for them based on their preferences.

The Spark Core firmware is a bit hacky – as you can imagine for a first project in C++/Wiring! I’d love for someone more experienced to have a look at it.

The project is here if you’d like to check it out, with the main code file being here:

Thanks!

@henryaj, is everything working? It is difficult to comment on code not knowing this first. Second, I had adapted the Adafruit thermal printer library for another member on this topic which include a link to the code repo:

From what I can see, you grabbed the other libraries from member repos as well so that's good. Commenting on coding style is often quite subjective and if your code works... :smile:

3 Likes

@peekay123, all working pretty well – though we are getting the occasional lockup which we’re unsure of the source of. The code is reasonably simple; it was more a question of seeing if experienced Sparkers (such as yourself!) were able to spot any obvious bugs at first glance.

Hi @henryaj

One thing I noticed is that the entire print part of the code runs in a Spark function. This is OK but will block loop() until it is completed which at 19200 baud could be a little while. During printing, the card reader part of loop() will not be running.

If this is OK for your application, then there is nothing to be done. But if you want more interactivity while printing, you could change the code to store the Spark function string argument in a global and set a flag, and then process it in loop() based on that flag. Depending on how much time it takes to print, you can choose to split up the print string and service the card reader at some reasonable rate at the same time you are printing.

You have a lot of duplicated common code in the sub-functions called by your main print function and for style reasons only, I would be tempted to refactor that a bit.

3 Likes