Configuring the ESP8266 board
It's now time to configure the ESP8266 Wi-Fi chip so it can accept commands coming from the cloud. This is something we already saw earlier, but it's always good to remember the basics, as we'll make a more complicated sketch later in this chapter:
We first need to include the required libraries:
#include <ESP8266WiFi.h> #include <PubSubClient.h> #include <aREST.h>
Then, we declare a Wi-Fi client and PubSub (MQTT) client:
WiFiClient espClient; PubSubClient client(espClient);
After that, we create an instance of the
aREST
library:aREST rest = aREST(client);
You also need to enter your Wi-Fi name and password into the sketch:
const char* ssid = "wifi-ssid"; const char* password = "wifi-pass";
You can also give a name to your device:
rest.set_id(device_id); rest.set_name("door_lock");
Finally, in the
loop()
function of the sketch, we handle the connection coming from the cloud:rest.handle(client);
It's now time to configure the board! Simply grab the code...