/ESP8266-TempSensor

ESP8266 --> InfluxDB low power temperature sensor

Primary LanguageC++MIT LicenseMIT

ESP8266 Power efficient temperature sensor

Assembled sensor

Sensor design and features

  • Utilizes DHT22 temperature + humidity sensor
    • Changing to a different sensor should only require changes to a few lines of code
  • OTA (Over The Air) firmware updates
    • No need to physically connect to device to flash new firmware
  • Utilizes InfluxDB time series DB for data logging
  • Utilizes the board's deep sleep (low power) mode to minimize power consumption
    • For maximum efficient/lowest power consumption, the board needs to be powered directly and not via the USB connector (which utilizes the on-board voltage regulator)
  • Per device configuration for temperature and humidity adjustments
    • Adjustments can be made globally (it's all code) but for my purposes I used the ESP8266 WiFI adapter MAC address
    • It's reccomended to calibrate (adjust the software offsets) relative to known accurate sensors

BOM (Bill of Materials)

Sensor

  • 1x ESP8266
    • The provided case leverages NodeMCU v3 w/o attached headers
  • 1x 1N5817 Schottky diode
  • 1x 10kΩ resistor

Case

  • 4x M2x4 self tapping screws
  • 2x M2x8 self tapping screws
  • 1x M2 nylon washer (optional)
  • 1x 3-wire Micro JST connector (optional to simplify disassembly/reassembly)

Wiring diagram

Wiring diagram

Sensor OTA (Over The Air) update server

Sensor case

  • stl, step, and f3d models provided
  • Flame retartent filament recommended
    • I personally use eSun ePC (Flame retardant level: UL94:V2) for electronics projects
  • Remember to scale the 3D model to compensate for filament shrinkage
  • This case relies on the ESP8266 NodeMCU v3 dimensions and a headerless (no pre-soldered pin headers) board. While headerless boards are more difficult to find, their use does allow for a much shorter, uniform, and convenient case height
  • Board dimensions vary wildly between ESP8266 version and manufacturer. I highly reccomend comparing the dimensions of your board and screw hole sizes/locations to the 3D model to avoid wasting unnecessary time and filament
  • Assembly
    • Use the 4x M2x4 screws to attach the ESP8266 to the case
    • Use the 2x M2x8 screws to attach the sensor lid to the case
    • If the sensor does not sit flush, use the nylon washer (any thin washer would do but I used a nylon washer as I had one available) to fill the empty space between the sensor and the lid
    • As long as the tolerances of your 3D print are within reason, the sliding lid should attach without force but should also not slide out on its own

Sensor case parts Open sensor case

Getting started

  1. Install the ES8266 boards
  2. Select the ESP8266 board
    • Tools --> Boards --> NodeMCU 1.0 (ESP-12E Module)
  3. Install the Adafruit DHT sensor library
    • Instructions here
    • Don't forget to install both the DHT sensor library and the Adafruit Unified Sensor libraries
  4. Locate the writeNewDeviceSettings function and make updates as necessary

These settings should be common across all your sensors.

  char* otaUrl = "http://otaserverhostname:otaserverport/ota/tempsensor.bin"; //Blank if not using OTA updates
  short dhtPin = 5; //ESP8266 D1
  short dhtPowerPin = 4; //ESP8266 D2 (Not required if you use a power pin directly)
  char* wifiSSID = "yourwifissid";
  char* wifiPwd = "yourwifipwd";
  char* influxDBProtocol = "http";
  char* influxDBHost = "yourinfluxdbhost";
  int influxDBPort = 8086;
  char* influxDBDB = "sensordata";
  char* influxDBMeasurement = "temperature";
  short sendInterval = 60; //seconds

Each sensor must also have an entry to specify the device's ID and temperature/humidity adjustments. To locate each sensor's MAC address, upload the sketch and observe the serial output. WiFi MAC Address: AA:AA:AA:AA:AA:AA

  if (mac_address == "AA:AA:AA:AA:AA:AA") {
    sensorTempAdjustment = 0.0;
    sensorHumdidityAdjustment = 0.0;
    deviceId = "SensorA";
  } else if (mac_address == "BB:BB:BB:BB:BB:BB") {
    sensorTempAdjustment = 0.0;
    sensorHumdidityAdjustment = 0.0;
    deviceId = "SensorB";
  }