The Grove – Touch Sensor is fixed at the entrance of the Rat-Bait-Station. When a rat enters the station, it triggers the capacitive touch sensor.

We shall program the Touch Sensor in the Arduino sketch for the Meshquitto Node. Open the meshquittoNode.ino file (the Meshquitto Node sketch) using the Arduino IDE.
Define the TOUCHPIN for the touch sensor:
// Define GPIO pins
#define TOUCHPIN 16 // Pin for capacitive touch sensor
#define LED_PIN 0 // Pin for the pin for the Onboard red LED
#define LED_TOPIC "LED1"
#define TRIGGER 12 // GPIO pin for HC-SR04 Ultrasonic Sensor's Trig pin
#define ECHO 13 // GPIO pin for HC-SR04 Ultrasonic Sensor's Echo pin
#define DIST_TOPIC "RatBS001"
The touch sensor is activated upon a rat entering the station, which gives the sensorValue equal to 1. I will use the IF statement. When the sensorValue = 1 is TRUE, the ESP8266 onboard red LED will light up. There will be a delay of 3 seconds before the Ultrasonic sensor activates.
When there is no touch sensing received from the capacitive touch sensor, the sensorValue is always equal to 0. Therefore, using the IF statement, when sensorValue = 1 is FALSE (which is the ELSE statement), the ESP8266 onboard red LED will be off and there will be no Ultrasonic sensing activity. Hence, any pests entering the Rat-Bait-Station will not trigger the ultrasonic sensor without able to trigger the touch sensor.
I had integrated the touch sensor code (highlighted in blue) with the Meshquitto Node sketch:
Under the void setup():
The Grove – Touch Sensor's data is the easiest and simplest to handle with. It produces numeric data consisting of only two integers which is 0 and 1. The value 0 indicates the touch sensor is in detection mode. When the touch pad of the touch sensor is touched, it activates the capacitive sensing circuit and gives the value 1 until the touch is lifted off from the touch pad.
The Touch Sensor Data is used on the go. When the data indicates the value 1, a rat is detected entering the Rat-Bait-Station and followed by activating the ultrasonic sensor. Hence, it is not necessary to store the data.