Skip to content

lafftale1999/esp32-aws-iot-core

Repository files navigation

Pre-requisites

To run this firmware you need the following set up in the project folder:

credentials folder

For the project to compile without errors you need to provide exactly this folder structure with and naming on certificates and keys.

├───main
    ├───credentials
    │   ├───certs
    │   │   ├───AmazonRootCA1.pem
    │   │   ├───private.pem.key
    │   │   ├───public.pem.crt    
    │   └───credentials.h    
    ├───include
    └───src

credentials.h

You need to update the following defines in credentials.h

#ifndef MQTT_CREDENTIALS_H_
#define MQTT_CREDENTIALS_H_

#define WIFI_SSID "wifi" // need to update
#define WIFI_PASS "pass" // need to update

#define MQTT_SERVER_ADDRESS     "endpoint" // found in AWS
#define MQTT_MTLS_PORT          8883

#endif

Note: credentials.h need to be created as shown in credentials folder!

mqtt_implementation.c

This file is already present here! Here you can update the settings for you MQTT connection.

#define MQTT_STANDARD_QOS       1

#define MQTT_PAYLOAD_MAX_LEN    256
#define MQTT_PARSED_MAX_LEN     256
#define MQTT_TOPIC_MAX_LEN      64
#define MQTT_WAIT_FOR_MUTEX_MS  50
#define MQTT_MAX_TRIES_SAVE     3

#define MQTT_RECONNECT_TRIES    5
#define MQTT_RECONNECT_REST_MS  1000

Note: I have chosen to keep the keep-alive as default (120 seconds), and have therefore not implemented a way to change this for now.

AWS IoT Core Shadow

Device Shadow

The current device shadow used in AWS IoT Core for this . By changing temperature, humidity and/or pressure to 0 - it will stop sending these values.

{
  "state": {
    "desired": {
      "interval_s": 20,
      "measurement_map": {
        "temperature": 1,
        "humidity": 1,
        "pressure": 1
      },
      "topic": "/measurements"
    }
  }
}

device_settings.h

The device will work without getting any updates from AWS device_shadow, these are the initial settings:

#define DEVICE_INITIAL_INTERVAL_MS      10000
#define DEVICE_INITIAL_TEMP_SETTING     1         /**1 = take temp          | 0 = do not take temp */
#define DEVICE_INITIAL_HUM_SETTING      1         /**1 = take humidity      | 0 = do not take humidity */
#define DEVICE_INITIAL_PRESS_SETTING    1         /**1 = take air pressure  | 0 = do not take air pressure */

#define DEVICE_INITIAL_PUBLISH_TOPIC    "/measurements"

If you for some reason want to change the keys they exist in the same file:

#define DEVICE_SHADOW_INTERVAL_KEY  "interval_s"
#define DEVICE_SHADOW_TOPIC_KEY     "topic"
#define DEVICE_SHADOW_MEAS_MAP_KEY  "measurement_map"
#define DEVICE_SHADOW_TEMP_KEY      "temperature"
#define DEVICE_SHADOW_HUM_KEY       "humidity"
#define DEVICE_SHADOW_PRESS_KEY     "pressure"

BME280 Sensor Reader

BME280 Sensor Reader connected as following:

Circuit schematic to show how the solution is connected

It is possible to change the pins inside components/bme280/internal/bme280_i2c.h

#define I2C_SDA_PIN                 GPIO_NUM_1      /**< SDA pin */
#define I2C_SCL_PIN                 GPIO_NUM_0      /**< SCL pin */
#define I2C_PORT                    I2C_NUM_0       /**< Which internal i2c module is used */
#define I2C_FREQUENCY               100000          /**< Frequency for communication */
#define I2C_MASTER_TIMEOUT_MS       1000

About

Testing AWS IoT Core using ESP32 and MQTT over mTLS.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published