qiweimao / ESP32-Datalogger

The ESP32 Data Logger is a cost efficient data acquisition system that supports vibrating wire sensors and other sensors with RS-485, TTL protocol.
0 stars 0 forks source link
arduino esp32 iot lora

Introduction

The ESP32 Data Logger is a cost efficient data acquisition system that supports vibrating wire sensors and other sensors with RS-485, TTL protocol. To set up the data logger as an end user, you can plug it into your computer, and configure the logger in a website using the browser. For advanced configurations, you can program your own code and flash the logger on PC, using PlatformIO or Arduino IDE.

Development Environment

System Log

Use this guide: https://community.platformio.org/t/redirect-esp32-log-messages-to-sd-card/33734, update esp32-hal-log.h to define TAG

#ifdef USE_ESP_IDF_LOG
#ifndef TAG
#define TAG "myAPP"
#endif

Update platformio.ini to include:

build_flags= -DUSE_ESP_IDF_LOG -DCORE_DEBUG_LEVEL=5

Include the following libraries and definitions:

#include "esp_log.h"
#include "esp32-hal-log.h"

#define LOG_LEVEL ESP_LOG_WARN
#define MY_ESP_LOG_LEVEL ESP_LOG_INFO

ESP-Prog

MAC OS driver issue: https://arduino.stackexchange.com/questions/91111/how-to-install-ftdi-serial-drivers-on-mac

Settings to update in Dependencies

ElegantOTA

Enable async webserver in the

  #define ELEGANTOTA_USE_ASYNC_WEBSERVER 1

FTP Server SD Card Settings

Architecture

Power Supply

For powering the ESP32 development kit via USB, an 18650 battery is utilized. However, for production purposes, a custom PCB will be designed, and the module should be powered via the 3V3 or VIN pin to minimize power loss. To harness solar power, the 18650 Shield is employed, facilitating power supply to the ESP32. This AliExpress link provides details on the shield. The input voltage range is specified as 5V to 8V, although preliminary tests suggest that a 5V solar panel is functional. Further validation will be conducted. SD only seems to work with power from VIN pin with a buck converter in between.

Reference: Intro to LoRaWAN by Andreas Spiess. Aspect ESP-NOW LoRaWAN
Range Short range, local area Long range, wide area
Power Consumption Low power Ultra-low power
Data Rate High data rates, real-time Low data rates, optimized for range
Topology Peer-to-peer (P2P) Star-of-stars
Scalability Small to medium networks Large-scale networks
Regulatory 2.4 GHz ISM band Sub-gigahertz ISM bands
Infrastructure Included in bare ESP32 module Gateway devices required

After conducting research, it appears that implementing LoRaWAN requires Gateway devices. However, opting for ESP-NOW provides an alternative solution and allows for exploration of range extension possibilities. LoRaWAN can be added when budget is available.

If a LoRa gateway is unnecessary, the firmware for all ESP32 devices can remain similar. Only the "gateway device" or main station needs adjustments to handle data communication and data table combination for HTTP requests from remote clients. Substations should still support local WiFi communication and serve webpages for users in areas without cell service.

How do devices interconnect?

The device will be configured via the WiFi manager interface, which is essentially serving a website for users to set modes.

API

An instance of AsyncWebServer is created on port 80. A Callback function is set up to handle incoming HTTP GET requests at the root ("/") by responding with the content of a file stored in the SPIFFS file system. Adjust the filename variable to match the desired file. After configuring the server, it is started with server.begin().

Logger System Control

Logger Configuration

Impletemented using the Preference.h library.

credentials
{
    "WIFI_SSID": "*********",
    "WIFI_PASSWORD": "**********",
    "gmtOffset_sec": "************"
}

ESP-NOW Routing Map

The master logger should have a master list of all substation system information.

[
    {
        "macAddress": "30:83:98:00:52:8C",
        "batteryVoltage": "3.7V"
    },
    {
        "macAddress": "30:83:98:00:52:8C",
        "batteryVoltage": "3.7V"
    },
]

File system TODO

Data Retrieval TODO

Timeseries request

The logger should liten on route /api/readings for timeseries requests. The client can specify the sensorId, start and end, and readingsOptions. A sample request should look like the following:

/api/readings?sensorId=238&start=2024-02-06T13:40:00&end=2024-02-13T13:40:00&readingsOptions=0

License

Created by Qiwei Mao

Useful References

Random Nerd Tutorials: https://randomnerdtutorials.com/projects-esp32/ Dashboard: https://github.com/ayushsharma82/ESP-DASH Github Reference https://github.com/topics/sensors-data-collection