dB SPL readings differ from external sound level meter?
Your calculations are correct, although you should do some kind of sliding average over a few hundred samples or so. The problem seems to be that the sound level meter employs an A-weighting, while your code does not. If there is low frequency noise in your measurement environment, the readings at "silence" can easily differ by 40-50dB. Try measuring a test tone at 1kHz, results should be closer together. Also, have a look at

https://en.wikipedia.org/wiki/A-weighting

You can see the huge low frequency differences there.