In this section, we are going to build a smart socket. The setup is going to be quite similar to what we had in Chapter 4, Smart Agriculture. Create a new folder named chapter5 and copy the contents of the chapter4 folder into it. The chapter4 folder has the code for the smart weather station, and now, we are going to add the required code for smart socket.
The smart socket is a simple electrical socket that can be controlled over the internet. That is, turn on the socket and turn off the socket. We are going to use a mechanical relay to achieve this.
We are going to start off by setting up the relay with the other sensors on the Raspberry Pi. I am going to use one Raspberry Pi to demonstrate the smart weather station as well as the smart socket. You can use two Raspberry Pis as well for this.
We are going to add the appropriate MQTT client code to the...