# ConsentiumThings Arduino API

## Overview

This code is designed to interface with the **ConsentiumThings Dalton** IoT board, which connects to a Wi-Fi network and transmits sensor data over the internet using a RESTful API. The board reads data from connected sensors and sends it to a designated endpoint at regular intervals.

## Dependencies

The code depends on the following library:

* **ConsentiumThings.h**: This is a library specific to the ConsentiumThings IoT board, enabling functions such as Wi-Fi connectivity, sensor reading, and data transmission via RESTful APIs.

## Components

### 1. **Wi-Fi Configuration**

* `const char *ssid = "YOUR_WIFI_SSID";`: Defines the name of the Wi-Fi network that the IoT board will connect to.
* `const char *pass = "YOUR_WIFI_PASSWORD";`: Defines the password for the specified Wi-Fi network.

### 2. **API Keys**

* `const char *SendApiKey = "YOUR_API_KEY";`: API key used for sending data via the REST API.
* `const char *BoardApiKey = "YOUR_BOARD_API_KEY";`: API key specific to the board for authentication purposes.

### 3. **Data Transmission Interval**

* `constexpr int interval = 7000;`: Sets the delay interval between data transmissions in milliseconds. In this case, the system waits for 7 seconds (7000 ms) between data sends.

### 4. **Board Initialization**

* `ConsentiumThingsDalton board;`: Creates an instance of the **ConsentiumThingsDalton** object, which represents the IoT board.

## Functions

### `void setup()`

* This function is called once when the board is powered on or reset.
* **Wi-Fi Initialization**:
  * `board.initWiFi(ssid, pass);`: Connects the board to the specified Wi-Fi network using the SSID and password provided.
* **Board API Initialization**:
  * `board.beginSend(SendApiKey, BoardApiKey);`: Authenticates the board with the necessary API keys to enable data transmission.

### `void loop()`

* This function runs repeatedly after the setup is complete.
* **Sensor Data Reading**:
  * `double data_0 = board.busRead(0);`: Reads the voltage data from the sensor connected to port 0 of the board.
* **Sensor Data Array**:
  * `double sensorValues[] = {data_0};`: Stores the sensor data (in this case, only one sensor) in an array.
* **Sensor Information Array**:
  * `const char* sensorInfo[] = {"Temperature"};`: Describes the type of data being read from the sensor.
* **Sensor Count**:
  * `int sensorCount = sizeof(sensorValues)/sizeof(sensorValues[0]);`: Calculates the number of sensors connected by determining the size of the sensor data array.
* **Data Transmission**:
  * `board.sendData(sensorValues, sensorInfo, sensorCount, LOW_PRE);`: Sends the sensor data, along with the sensor information, to the server using REST with low precision.
* **Delay**:
  * `delay(interval);`: Waits for 7 seconds before running the loop again, creating a periodic data transmission schedule.

## Customization

### Wi-Fi Configuration

Replace `"YOUR_WIFI_SSID"` and `"YOUR_WIFI_PASSWORD"` with your actual Wi-Fi network credentials:

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

### API Keys

You must replace `"YOUR_API_KEY"` and `"YOUR_BOARD_API_KEY"` with the actual API keys provided by the ConsentiumThings service. These keys authenticate the board and allow it to send data to the designated API endpoint.

### Interval

The data transmission interval is set to 7 seconds by default. You can modify this by changing the value of the `interval` constant.

```cpp
constexpr int interval = 5000; // Waits for 5 seconds between data transmissions
```

### Adding More Sensors

If you have more than one sensor, you can expand the `sensorValues` and `sensorInfo` arrays. For example, to add a second sensor:

```cpp
double data_1 = board.busRead(1); // Read voltage data from sensor on port 1
double sensorValues[] = {data_0, data_1}; // Add both sensor data to array
const char* sensorInfo[] = {"Temperature", "Humidity"}; // Add sensor info for both
```

Then adjust the sensor count:

```cpp
int sensorCount = sizeof(sensorValues)/sizeof(sensorValues[0]); // Update sensor count
```
