ConsentiumThings Arduino Data Receiver API

Overview

This code interfaces with the ConsentiumThings board to receive sensor data from a server via Wi-Fi and print it to the Serial Monitor. It is intended for use with ESP8266, ESP32, and Raspberry Pi Pico W boards and operates by connecting to Wi-Fi and receiving data at regular intervals using the ConsentiumThings REST API.

Dependencies

The code depends on the ConsentiumThings.h library, which provides functions for Wi-Fi connection, data reception, and RESTful API communication with the Consentium IoT platform.

Components

1. Wi-Fi Configuration

  • const char *ssid = "YOUR_WIFI_SSID";: This is the Wi-Fi network SSID to which the IoT board will connect.

  • const char *pass = "YOUR_WIFI_PASSWORD";: The password for the specified Wi-Fi network.

2. API Keys

  • const char *ReceiveApiKey = "YOUR_API_KEY";: API key for receiving data from the server.

  • const char *BoardApiKey = "YOUR_BOARD_API_KEY";: API key specific to the board, used for authentication purposes.

3. Data Reception Interval

  • constexpr int interval = 7000;: Defines the time interval between each data reception in milliseconds. In this case, the system will wait for 7 seconds (7000 ms) between receiving data from the server.

4. Board Initialization

  • ConsentiumThings board;: Creates an instance of the ConsentiumThings object, representing the IoT board that will receive data from the server.

Functions

void setup()

  • This function runs once when the board is powered on or reset.

  • Wi-Fi Initialization:

    • board.initWiFi(ssid, pass);: Connects the board to the Wi-Fi network using the provided SSID and password.

  • Board API Initialization:

    • board.beginReceive(ReceiveApiKey, BoardApiKey);: Authenticates the board and initiates the process to receive data from the server using the ConsentiumThings platform.

void loop()

  • This function runs repeatedly after setup() and handles the continuous reception and printing of sensor data.

  • Data Reception:

    • auto dataPairs = board.receiveData();: Retrieves the sensor data from the server, storing it as key-value pairs, where each pair contains a sensor reading and its corresponding label.

  • Data Printing:

    • A for loop iterates through the received dataPairs to print both the sensor data and its corresponding label (info) to the Serial Monitor.

    • Serial.print("Data: "); and Serial.print("Info: ");: These lines are used to display the data and information for each sensor.

  • Delay:

    • delay(interval);: Pauses execution for 7 seconds before receiving and printing new data again.

Example Output

The code prints the received sensor data in the following format on the Serial Monitor:

Data: 24.5          	Info: Temperature
Data: 55.0          	Info: Humidity

This output shows the sensor values along with the description of what each value represents.

Customization

Wi-Fi Configuration

You must replace "YOUR_WIFI_SSID" and "YOUR_WIFI_PASSWORD" with your actual Wi-Fi network credentials:

const char *ssid = "MyWiFiNetwork";
const char *pass = "MyWiFiPassword";

API Keys

The placeholders "YOUR_API_KEY" and "YOUR_BOARD_API_KEY" should be replaced with the actual API keys provided by the ConsentiumThings service. These keys authenticate the board and allow it to receive data.

Interval

To change the interval between receiving data from the server, adjust the value of the interval constant (in milliseconds):

constexpr int interval = 5000; // Wait for 5 seconds between data receptions

LED Indication (Optional)

You can connect an LED to a specific GPIO pin to visually indicate REST events as mentioned in the comment header. The GPIO pin depends on the board:

  • GPIO 16 for ESP8266

  • GPIO 23 for ESP32

  • GPIO 25 for Raspberry Pi Pico W

Last updated