Giter Site home page Giter Site logo

sambenko / esp32s3-no-std-async-tls-mqtt Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 158 KB

Sending MQTT messages containing sensor data from BME680 to any MQTT broker that requires MQTT over TLS (AWS IoT Core) in no_std Rust! ๐Ÿฆ€

License: Apache License 2.0

Rust 99.13% Shell 0.87%

esp32s3-no-std-async-tls-mqtt's Introduction

๐Ÿ“ก esp32s3 no_std Async TLS MQTT

Sending MQTT messages containing sensor data from BME680 to any MQTT broker that requires MQTT over TLS (AWS IoT Core) in no_std Rust! ๐Ÿฆ€

๐Ÿ“š Based on: esp32c3-no-std-async-mqtt-demo


๐Ÿ“‹ Table of Contents


๐ŸŽฏ About The Project

This program allows the user to get measured data from a BME680 sensor ๐ŸŒก and send them in MQTT messages ๐Ÿ“ฌ via a TLS session to an MQTT Broker (in this case AWS IoT Core). All of this is done in Rust ๐Ÿฆ€ without the use of the standard library. The program uses the ESP32S3-BOX Devkit.

๐Ÿ” back to top


๐Ÿ“ฆ Built With Crates

๐Ÿ” back to top


๐Ÿ”ง Prerequisites

Software Requirements

To run this project, you'll need to install the following:

  • Rust ๐Ÿฆ€
  • Install espup tool and follow the instructions there ๐Ÿ› 

Hardware Requirements

๐Ÿ” back to top


๐Ÿš€ Getting Started

1. ๐Ÿ”Œ Hardware Setup

Before running the program, make sure your hardware is properly set up.

  • Connect the BME680 Sensor to ESP32S3-BOX device:

    • SDA to G41 on the device
    • SCL to G40 on the device
    • 2-5V to 3v3 on the device
    • GND to GND on the device

    All 4 wires should be next to each other in the end.

  • Connect the ESP32S3-BOX to your computer:

    • Use a USB-C cable to establish the connection.


2. ๐Ÿ›ก๏ธ Setting up MQTT Configuration and Certificates

2.1 MQTT Endpoint and Client ID

  • Endpoint Address: Write your MQTT broker's endpoint address into endpoint.txt in the secrets/ folder.
  • Client ID: If you are using a private broker like AWS MQTT, a client ID is also required. Paste the client ID into client_id.txt in the secrets/ folder.

2.2 MQTT over TLS

If your MQTT broker requires secure connections, you'll need to provide the necessary TLS X.509 certificates:

  • Trusted Root Certificate: This is generally needed to verify the broker's identity. Paste the content of your root certificate into a file named rootCA.pem in the secrets/ folder.
  • Client Certificate: This is your device's certificate, which is presented to the broker during the handshake. Save it as client_cert.pem.crt in the secrets/ folder.
  • Private Key: This key matches the client certificate and must be kept private. Save it as client_private.pem.key in the secrets/ folder.

The certificate and key files are read in the code snippet below after crate imports in src/main.rs:

const CERT: &'static str = concat!(include_str!("../secrets/rootCA.pem"), "\0");
const CLIENT_CERT: &'static str = concat!(include_str!("../secrets/client_cert.pem.crt"), "\0");
const PRIVATE_KEY: &'static str = concat!(include_str!("../secrets/client_private.pem.key"), "\0");

You can rename the files however you like, but you need to change the paths in consts accordingly.

๐Ÿšจ Warning: Never commit your secrets and certificates to GitHub or any other public repository. The .gitignore file is set up to ignore these files, but you must also ensure not to manually include them in commits.


After setting up these files, you should have 2 tracked changes only, in client_id.txt and endpoint.txt. Don't commit these!



3. ๐Ÿ“ถ WiFi Setup and Program Execution

To set up your WiFi credentials and execute the program, you have two options:

Option 1: Use the Script ๐Ÿ“œ

  1. Edit the Script: Open run_with_wifi_credentials.sh and enter your WiFi SSID and PASSWORD.
  2. Run the Script: Execute the script to set the environment variables and run the program.
    ./run_with_wifi_credentials.sh

    ๐Ÿšจ 3rd tracked change should appear in VSCode Source Control tab. Again, don't commit any of the 3 changes!

Option 2: Manual Setup ๐Ÿค–

  1. Export Environment Variables: Manually set the environment variables for your WiFi credentials.
    export SSID=your_wifi_ssid
    export PASSWORD=your_wifi_password
  2. Run the Program: Use the following command to run the program.
    cargo run --release

Choose one of these options to set up your WiFi and execute the program.

๐Ÿ” back to top

esp32s3-no-std-async-tls-mqtt's People

Contributors

sambenko avatar

Stargazers

Ole Kristian avatar Casi McDaniels avatar Juan Villa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.