Skip to content

An ESP32 based logger node to send data to InfluxDB - configurable with a variety of sensors including BME280, BH1750, MHZ19, SCT-001, etc.

License

Notifications You must be signed in to change notification settings

jack828/esp32-logger

Repository files navigation

esp32-logger

ESP32
License: MIT

Features

  • mDNS discovery
  • InfluxDB support
  • Auto WiFi keep-alive task
  • FLASHING LED
  • AsyncElegantOTA updates
  • Sexy & sleek custom dashboard for updating config options + InfluxDB tags

Logging

Logging is the primary function of this project. Use this chunk of silicon to collect data, and send it to a bigger chunk of silicon to process and store the data on bits of magnetic metal. Then, at a later date, use another chunk of silicon to view the data in really pretty graphs.

As this README is likely to fall out of date as to what exactly is being tracked, check out these two files for info:

Libraries

All required libraries for the various minor variations in this project are kept as git submodules within ./libraries.

To initialise these, run git submodule init && git submodule update in the project root.

To update specific libraries to newer versions, run git submodule update --remote libraries/EmonLib.

EmonLib Patches

If you decide against the submodule approach for the libraries, an want to use the IDE provided ones:

To use the EmonLib library with the 12-bit ADC aboard the ESP32, you'll need to patch it.

  • Add the library using the board manager
  • Open the library in the editor of your choice (Neovim) and manually patch it The location can be found depending on your setup using the instructions here
  1. in EmonLib.h Amend the block at lines 36-40.
-#if defined(__arm__)
#define ADC_BITS    12
-#else
-#define ADC_BITS    10
-#endif
  1. in EmonLib.cpp Replace the 3 occurrences of 1024 with ADC_COUNTS in lines 117, 119, 201.
-    offsetV = offsetV + ((sampleV - offsetV) / ADC_COUNTS);
+    offsetV = offsetV + ((sampleV - offsetV) / 1024);

Setup

Fork the repo, clone, initialise submodules, and configure to match your setup.

Please see credentials.h for credential information. Use .tpl as a starting point. Please see definitions.h for all configurables.

Setup or update arduino-cli:

$ curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=~/.local/bin sh

Usage

This project has been designed to use the Arduino CLI by usage of a Makefile.

Please check the file for the appropriate commands - you may need to adjust which port you use.

After the initial flash to the device, you can use the AsyncElegantOTA solution to keep the node firmware updated.

Using an mDNS browser you can discover nodes without having the IP address. They respond on http://esp<node efuse ID>.local/.

Config is available via http://<node-ip>/

OTA updates available via http://<node-ip>/update

CLI based automatic rollout to multiple nodes is possible using a list of nodes in the Makefile. You need to make a note of the numerical chip ID (which is the decimal representation of the hex portion of the mDNS URL), which can then be used in definitions.h to modify compilation behaviour.

Once this is setup you can run make deploy to rollout all nodes or make deploy-node node=123456789 to target a specific node.

TODO

Useful links

ESP_32_OLED_BATT

This is a all-in-one kit from AliExpress.

  • ESP-WROOM-32 Module (Wifi, Bluetooth, two cores)
  • USB to serial bridge with Silicon Labs CP210X Chip
  • Charge Circuit for an 18650 battery (backside of board)
  • OLED display (SSD1306 or compatible) I2C version
  • LED on GPIO16 (was (int8_t) 16 for me with ESP32 Dev Module board)
  • Power switch
  • AMS1117 voltage regulator (has a high quiescent current!)

Monitoring information

Environment

  • Temperature, Pressure, Humidity all done through BME280/BME680
  • IAQ, eC02, bVOCe done via BME680 after calibration burn in period

Energy

Performed via EmonLib and a split-core current transformer. In my case, I used an SCT-013-000, but there are many different varieties out there.

Notably:

  • SCT-013-XXX (split core, 30-150A)
  • KCT38 (split core, 50-600A)
  • BH-066-XXX (solid core, 10-400A)
  • PZCT-02 (split core, 100A)
  • BZCT30AL (solid core, 50/100A)
  • PZEM-004T - comes with different CTs. Measures voltage, frequency, and power factor via MODBUS interface.

When using EmonLib and a current transformer, there is some additional hardware to ensure the ESP32 can measure the current correctly.

First, we need to convert the alternating current into an AC voltage, biased so the 0-3.3v ADC can read it without setting on fire :).

We do this by applying a burden resistor to the CT (if not already installed) and then connecting the signal output to a voltage divider to offset the signal to the ADC range.

Once complete, the signal now read by the ADC has the following performed: For each reading, we can define the number of samples for the library to calculate; the bigger the number of samples, the longer the method will take to calculate the Current. The library uses the root mean square to calculate the current: Supposing N equals the number of samples, and u(n) being the voltage sample that we get from the ADC: (1) PAGE 10 EQUATION 1 This (1) Urms value is then multiplied by the calibration coefficients, based on the value we define at the beginning for each ADC input. Then using urms × calcoeff results in the current value, we call this Irms that will be used to calculate the apparent power by being multiplied with a voltage constant

nice PCB layout https://github.com/bvarner/PZCT-02-BurdenShift

Author

Jack Burgess

License

MIT

About

An ESP32 based logger node to send data to InfluxDB - configurable with a variety of sensors including BME280, BH1750, MHZ19, SCT-001, etc.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published