AlarmForce-How to it works

Kruk Matias
4 min readFeb 20, 2021

The REST API Approach

General Architecture

Here are the details about the implementation commented on in my previous post. The implementation is based on the Thingspeak REST API.

It’s a prerequisite to check the documentation related to the REST API to understand better how to create the channel and check your APIs keys.

Arduino Code

Though it’s not a post related to Arduino programming (there are very good articles around), I’m going to explain the basic structure of this Arduino development.

The code begins by declaring the functions needed. In this case, WiFi methods and HTTPClient connect to Thingspeak REST API. Take in mind the apiKeyIn is the Thingspeak Write API.

setup block

In the setup part is the idea to

  1. Initialize the ESP32 port 14 to receive the data from the PIR sensor.
  2. Connection to Wifi Network,
  3. Wait to connect.
  4. Display the IP address.
  1. Read PIR Sensor data (Port 14).
  2. Check the Wifi is up and the sensor’s state is 1 (movement detection)
  3. Post the data to Thingspeak API.
  4. Check the HTTP communication with API was successful.
  5. Delay before triggering new iteration in the loop.

Thingspeak monitoring

Thingspeak has some nice dashboards to check online how the data is sent. I’d recommend you to check the different options.

The channel’s view from thingspeak


Kruk Matias