So it looks like we got our server working with the sensor readings and everything... great! However, there are a few issues with our implementation that we need to handle. Looking at the server code from the previous example, we can note the following points:
- We are repeating a lot of code; not only does this make our code look bad, but it also makes it less malleable. What if we want to change our sensor pin number from 4 to 6? We need to change the code in two places. Even worse, what if we decide to change the sensor or even the way in which we get sensor readings in the future?
- We are making calls to the native library every time someone hits the API. This is fine when we are testing it on our local machine, but what if we had multiple users hitting our API at the same time? It is highly inefficient to make so many calls to the native library, especially...