Skip to content

Commit

Permalink
Merge pull request #16 from IPlayZed/ADC
Browse files Browse the repository at this point in the history
PR for uploading to uni.
  • Loading branch information
IPlayZed authored May 13, 2023
2 parents c4c6bcc + 80f9512 commit 3c7fa9d
Show file tree
Hide file tree
Showing 33 changed files with 622 additions and 287 deletions.
4 changes: 2 additions & 2 deletions .vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"configuration": "PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,LoopCore=1,EventsCore=1,DebugLevel=none",
"board": "esp32:esp32:esp32",
"sketch": "project/src/Main/Main.ino",
"sketch": "project/Main/Main.ino",
"output": "build",
"port": "/dev/ttyUSB0"
"port": "COM3"
}
46 changes: 26 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
# Thesis on Precision Air Quality Measurements Over Network via the MQTT Protocol using ESP32 MCUs

## Main milestones and their subgoals

- [x] SDK
- [x] WiFi connection
- [x] Peripheral communication
- [x] Communication with a cloud storage provider
- [x] Investigate possible cloud providers.
- Possible providers are: [ESP-IDF supported Cloud Frameworks](https://docs.espressif.com/projects/esp-idf/en/v4.4/esp32/libraries-and-frameworks/cloud-frameworks.html).
- The choice fell on [Azure IoT](https://azure.microsoft.com/en-us/overview/iot/).
- TBA
- TBA
- [ ] PCB implementation
- [ ] Collect data and export it
- [ ] Printable formal thesis
- [ ] *(Optional)* Create a frontend for interactive data representation

## These links are useful resources I have used, grouped by topics:
This project aims to create an expandable smart net of air quality sensors. I wish to provide firmware, a backend solution for data processing, communication and a hardware prototype.

### Containerization
In theory almost all the hardware, software and infrastructure can be swapped out if one complies with the interfaces described in the project, but due to the nature and complexity of the system, some might not integrate as well.

## Development tools used

- [Docker Compose Syntax: Volume or Bind Mount?](https://maximorlov.com/docker-compose-syntax-volume-or-bind-mount/)
- [Visual Studio Code](https://code.visualstudio.com/)
- [Arduino Expansion Pack](https://marketplace.visualstudio.com/items?itemName=mpty.pack-arduino)
- [C/C++ Extension Pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack)
- [IoT Telemetry Simulator](https://github.com/azure-samples/iot-telemetry-simulator/tree/master/)
- [VSCode Remote Development Docoumentation](https://code.visualstudio.com/api/advanced-topics/remote-extensions#architecture-and-extension-types)

## Libraries used in firmware

The following libraries and board definition(s) should be installed via the Arduino framework.

The versions referenced here are guaranteed to compile and function as expected, but you can try upgrading them if you want to, however it is possible that between versions there might be incompatibility. It is also possible that if you wish to build and flash firmware which communicates with a cloud platform with Azure, you might have to update the cloud configuration if not using the Azure templates in this repository. Always consult the documentation properly.

- [esp32 by Espressif Systems](https://github.com/espressif/arduino-esp32) (version 2.0.7) (Board definition for Arduino)
- [DHT sensor library by Adafruit](https://github.com/adafruit/DHT-sensor-library) (version 1.4.4)
- [ArduinoJSON](https://github.com/bblanchon/ArduinoJson) (version 6.21.0)
- [Adafruit MCP3008 by Adafruit](https://github.com/adafruit/Adafruit_MCP3008) (version 1.3.1)
- [Azure SDK for C by Microsoft Corporation](https://github.com/Azure/azure-sdk-for-c) (version 1.1.3)

## Useful links

### Containerization

- [Docker Compose Syntax: Volume or Bind Mount?](https://maximorlov.com/docker-compose-syntax-volume-or-bind-mount/): For configuring the telemetry simulator.
- [VSCode Remote Development Docoumentation](https://code.visualstudio.com/api/advanced-topics/remote-extensions#architecture-and-extension-types): For developing remotely or on immutable systems.
16 changes: 16 additions & 0 deletions project/Main/Main.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed under: GNU GENERAL PUBLIC LICENSE Version 2

#include "src/tasks/Tasks.hpp"

void setup()
{
Tasks::configureLocalPeripherials();
Tasks::initializeConnection();
}

void loop()
{
Tasks::doMeasurements();
Tasks::sendTelemetry();
Tasks::Helpers::startSleep();
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Licensed under: GNU GENERAL PUBLIC LICENSE Version 2

#include <time.h>
#include "Common.h"
#include "Common.hpp"

uint32_t getSecsSinceEpoch()
{
return (uint32_t)time(NULL);
}
}
36 changes: 19 additions & 17 deletions project/src/Main/Common.h → project/Main/src/common/Common.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Licensed under: GNU GENERAL PUBLIC LICENSE Version 2

#ifndef COMMON_H
#define COMMON_H
#ifndef COMMON_HPP
#define COMMON_HPP

#include "SerialLogger.h"
#include "serial-logger/SerialLogger.hpp"

#define DEBUG_MODE

Expand All @@ -22,25 +22,27 @@
#define NULL_TERMINATOR '\0'

// WARNING: Only use this macro if the argument is an actual 1-dimensional C-like array.
// Passing normal pointers will cause "sizeof(arg)" to return the system pointer width, resulting in a silent bug.
// Passing normal pointers will cause "sizeof(arg)" to return the system pointer width, resulting in a silent bug.
#define sizeofarray(arg) (sizeof(arg) / sizeof(arg[0]))

uint32_t getSecsSinceEpoch();

#ifdef DEBUG_MODE
#define LogInfo(text) Logger.Info(text)
#define LogError(text) Logger.Error(text)
#define SerialPrint(text) Serial.print(text)
#define SerialPrintln() Serial.println()
#define SerialPrintlnTimeinfo(timeinfo, formattedText) Serial.println(timeinfo, formattedText)
#define DelayForSerialConnection(time) delay(time);
#define LogInfo(text) Logger.Info(text)
#define LogWarning(text) Logger.Warning(text)
#define LogError(text) Logger.Error(text)
#define SerialPrint(text) Serial.print(text)
#define SerialNewLine() Serial.println()
#define SerialTimeinfo(timeinfo, formattedText) Serial.println(timeinfo, formattedText)
#define DelayForSerialConnection(time) delay(time);
#else
#define LogInfo(text)
#define LogError(text)
#define SerialPrint(text)
#define SerialPrintln()
#define SerialPrintlnTimeinfo(timeinfo, formattedText)
#define DelayForSerialConnection(time)
#define LogInfo(text)
#define LogWarning(text)
#define LogError(text)
#define SerialPrint(text)
#define SerialNewLine()
#define SerialTimeinfo(timeinfo, formattedText)
#define DelayForSerialConnection(time)
#endif

#endif
#endif // COMMON_HPP
34 changes: 34 additions & 0 deletions project/Main/src/common/CommonConfig.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef COMMON_CONFIG_HPP
#define COMMON_CONFIG_HPP

#include "../network/Network.hpp"

#define DEFAULT_INBOUND_DATA_SIZE_BYTES 128
#define DEFAULT_SERIAL_BAUD_RATE 9600
#define DEFAULT_TIME_TO_SLEEP_IN_S 30
#define DEFAULT_DELAY_FOR_SERIAL_CONNECTION 5000

#define CONFIG_SERIAL_BAUD_RATE DEFAULT_SERIAL_BAUD_RATE
#define CONFIG_TIME_TO_SLEEP_IN_S DEFAULT_TIME_TO_SLEEP_IN_S
#define CONFIG_DELAY_FOR_SERIAL_CONNECTION DEFAULT_DELAY_FOR_SERIAL_CONNECTION

namespace Configurations
{
namespace Common
{
namespace Defaults
{
constexpr uint8_t INBOUND_DATA_SIZE_BYTES = 128;
constexpr uint16_t SERIAL_BAUD_RATE = 9600;
constexpr uint16_t TIME_TO_SLEEP_SEC = 30;
constexpr uint16_t DELAY_FOR_SERIAL_MILISEC = 5000;
}

const uint8_t INBOUND_DATA_SIZE_BYTES = Defaults::INBOUND_DATA_SIZE_BYTES;
const uint16_t SERIAL_BAUD_RATE = Defaults::SERIAL_BAUD_RATE;
const uint16_t TIME_TO_SLEEP_SEC = Defaults::TIME_TO_SLEEP_SEC;
const uint16_t DELAY_FOR_SERIAL_MILISEC = Defaults::DELAY_FOR_SERIAL_MILISEC;
}
}

#endif // COMMON_CONFIG_HPP
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
// Modified by project author.

#include "SerialLogger.h"
#include <time.h>

#include "SerialLogger.hpp"

#define UNIX_EPOCH_START_YEAR 1900

static void writeTime()
{
struct tm* ptm;
struct tm *ptm;
time_t now = time(NULL);

ptm = gmtime(&now);
Expand Down Expand Up @@ -44,10 +46,10 @@ static void writeTime()
Serial.print(ptm->tm_sec);
}

SerialLogger::SerialLogger() { Serial.begin(SERIAL_LOGGER_BAUD_RATE); }

// TODO: Use conditional compilation here instead of wrapping this into one.
// TODO: Wrap these into one function call rather.
SerialLogger::SerialLogger()
{
Serial.begin(SERIAL_LOGGER_BAUD_RATE);
}

void SerialLogger::Info(String message)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
// Modified by project author.

#ifndef SERIALLOGGER_H
#define SERIALLOGGER_H
#ifndef SERIALLOGGER_HPP
#define SERIALLOGGER_HPP

#include <Arduino.h>
#include "CommonConfig.h"
#include "../CommonConfig.hpp"

#ifndef SERIAL_LOGGER_BAUD_RATE
#define SERIAL_LOGGER_BAUD_RATE CONFIG_SERIAL_BAUD_RATE
Expand All @@ -22,4 +23,4 @@ class SerialLogger

extern SerialLogger Logger;

#endif // SERIALLOGGER_H
#endif // SERIALLOGGER_HPP
Loading

0 comments on commit 3c7fa9d

Please sign in to comment.