Creating an interface for the smart plug
Commercial smart plugs usually come with a nice interface, which you can use from your phone or computer to control the plug via Wi-Fi. In this section, we are going to do exactly the same: build a simple interface that we will use to control the device connected to the smart plug, and also visualize the current and power consumption of the device.
As the code for this part is quite similar to the code of the previous section, I will only highlight the differences here.
Inside the Node.js JavaScript file, we declare the public
folder in which we will store the interface:
app.use(express.static('public'));
Then, we need to declare to which pin we connected the output of the smart plug:
var outputPin = 18;
Using Express
, we can now define some routes. We define the main route of the application to redirect to the interface
file:
app.get('/', function (req, res) { res.sendfile(__dirname + '/public/interface.html'); });
Then, as we saw in the previous chapter...