Once we have completed constructing the Rat-Bait-Station, the next step is to upload the Arduino sketch to the ESP8266. Before we proceed, let’s understand what the role of the Rat-Bait-Station as an IoT device does. Sensors are built into the station to detect a rat entering it. Each station is part of the mesh network, which is the Meshquitto Network (refer to IoT Network – the Mesh Network).
Hence, every Rat-Bait-Station is a Meshquitto Node in the Meshquitto Network. The Arduino Sketch programs the station to send data, using the MQTT protocol to the Meshquitto Gateway as a MQTT Client – publisher, to the MQTT broker whenever the touch sensor is triggered by a rat entry to the station.

Before we can upload the Arduino sketch, we need to modify the code. Refer to IoT Data – using MySQL for programming the sensors.
Note: The meshquittoNode.ino file was downloaded from:
https://github.com/sglvladi/meshquitto
Step 1
Open the meshquittoNode.ino file from the meshquittoNode folder:

That will launch the Arduino IDE:

Step 2
We need to change the DIST_TOPIC to the StationNo we assign to each Meshquitto node. For example, we shall upload our first Rat-Bait-Station with the StationNo: RatBS001, and the next station with the StationNo: RatBS002 and so on. Each Rat-Bait-Station (Meshquitto node) is identified by the MQTT topic subscribed to.
Step 3
Next, we need to change the mesh network details. Every Meshquitto node is connected to the mesh network using the SSID: “RatBaitMesh01” and the password: “PoisonRat”. With this, no other outside nodes will be able to join the mesh network. The mesh network communication is also encrypted using AES.
Step 4
Finally, every Meshquitto node must point to the Meshquitto gateway ID (because the Meshquitto network is not IP networking which does not create a TCP/IP network of nodes). Hence, the Meshquitto nodes do not use an IP address, instead the chip ID is used. (Refer to Understanding the painlessMesh Setup.) By running the Mesh Gateway, we can identify the Mesh Gateway’s ID, which is 2486699076.
Watch the video below on uploading the meshquittoNode.ino file to the ESP8266 which is the Rat-Bait-Station. After uploading the source code, the Rat-Bait-Station becomes a full fledged Meshquitto Node.
Step 5
Watch the video:
Step 6
Launch the Serial Monitor after uploading the Arduino sketch.

Watch the video: