parent
16cc2bde7c
commit
5592b1b523
|
@ -77,6 +77,7 @@ lib_deps =
|
|||
adafruit/Adafruit BME280 Library@^2.2.2
|
||||
adafruit/Adafruit BMP085 Library@^1.2.1
|
||||
adafruit/Adafruit BMP280 Library@^2.6.3
|
||||
adafruit/Adafruit SHT31 Library@^2.2.0
|
||||
adafruit/Adafruit TSL2561@^1.1.0
|
||||
|
||||
[env:esp32]
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
#ifdef SENSORS
|
||||
#include "SHT30.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "mqtt.h"
|
||||
#include "defaults.h"
|
||||
#include <AsyncWiFiSettings.h>
|
||||
#include "string_utils.h"
|
||||
|
||||
#include <Adafruit_SHT31.h>
|
||||
|
||||
namespace SHT30
|
||||
{
|
||||
Adafruit_SHT31* sht30;
|
||||
long SHT30_status;
|
||||
String SHT30_I2c;
|
||||
int SHT30_I2c_Bus;
|
||||
unsigned long SHT30PreviousMillis = 0;
|
||||
int sensorInterval = 60000;
|
||||
bool initialized = false;
|
||||
|
||||
void Setup()
|
||||
{
|
||||
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||
|
||||
sht30 = new Adafruit_SHT31(SHT30_I2c_Bus == 1 ? &Wire : &Wire1);
|
||||
if (SHT30_I2c == "0x44") {
|
||||
SHT30_status = sht30->begin(0x44);
|
||||
} else if (SHT30_I2c == "0x45") {
|
||||
SHT30_status = sht30->begin(0x45);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SHT30_status) {
|
||||
Serial.println("[SHT30] Couldn't find a sensor, check your wiring and I2C address!");
|
||||
} else {
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectToWifi()
|
||||
{
|
||||
AsyncWiFiSettings.html("h4", "SHT30/31 Temperature and Humidity Sensor");
|
||||
SHT30_I2c_Bus = AsyncWiFiSettings.integer("SHT30_I2c_Bus", 1, 2, DEFAULT_I2C_BUS, "I2C Bus");
|
||||
SHT30_I2c = AsyncWiFiSettings.string("SHT30_I2c", "", "I2C address (0x77)");
|
||||
}
|
||||
|
||||
void SerialReport()
|
||||
{
|
||||
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||
if (SHT30_I2c.isEmpty()) return;
|
||||
Serial.print("SHT30: ");
|
||||
Serial.println(SHT30_I2c + " on bus " + SHT30_I2c_Bus);
|
||||
}
|
||||
|
||||
void Loop()
|
||||
{
|
||||
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||
if (!initialized) return;
|
||||
|
||||
if (SHT30PreviousMillis == 0 || millis() - SHT30PreviousMillis >= sensorInterval) {
|
||||
|
||||
float temperature = sht30->readTemperature();
|
||||
float humidity = sht30->readHumidity();
|
||||
|
||||
mqttClient.publish((roomsTopic + "/sht30_temperature").c_str(), 0, 1, String(temperature).c_str());
|
||||
mqttClient.publish((roomsTopic + "/sht30_humidity").c_str(), 0, 1, String(humidity).c_str());
|
||||
|
||||
SHT30PreviousMillis = millis();
|
||||
}
|
||||
}
|
||||
|
||||
bool SendDiscovery()
|
||||
{
|
||||
if (SHT30_I2c.isEmpty()) return true;
|
||||
|
||||
return sendSensorDiscovery("SHT30 Temperature", EC_NONE, "temperature", "°C")
|
||||
&& sendSensorDiscovery("SHT30 Humidity", EC_NONE, "humidity", "%");
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
#ifdef SENSORS
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
namespace SHT30
|
||||
{
|
||||
void ConnectToWifi();
|
||||
void SerialReport();
|
||||
bool SendDiscovery();
|
||||
void Setup();
|
||||
void Loop();
|
||||
}
|
||||
|
||||
#endif
|
|
@ -56,6 +56,7 @@ bool sendTelemetry(int totalSeen, int totalFpSeen, int totalFpQueried, int total
|
|||
&& BME280::SendDiscovery()
|
||||
&& BMP180::SendDiscovery()
|
||||
&& BMP280::SendDiscovery()
|
||||
&& SHT30::SendDiscovery()
|
||||
&& TSL2561::SendDiscovery()
|
||||
&& HX711::SendDiscovery()
|
||||
&& SensirionSGP30::SendDiscovery()
|
||||
|
@ -228,6 +229,7 @@ void setupNetwork()
|
|||
BME280::ConnectToWifi();
|
||||
BMP180::ConnectToWifi();
|
||||
BMP280::ConnectToWifi();
|
||||
SHT30::ConnectToWifi();
|
||||
TSL2561::ConnectToWifi();
|
||||
HX711::ConnectToWifi();
|
||||
SensirionSGP30::ConnectToWifi();
|
||||
|
@ -267,6 +269,7 @@ void setupNetwork()
|
|||
BME280::SerialReport();
|
||||
BMP180::SerialReport();
|
||||
BMP280::SerialReport();
|
||||
SHT30::SerialReport();
|
||||
TSL2561::SerialReport();
|
||||
HX711::SerialReport();
|
||||
SensirionSGP30::SerialReport();
|
||||
|
@ -587,6 +590,7 @@ void setup()
|
|||
BME280::Setup();
|
||||
BMP180::Setup();
|
||||
BMP280::Setup();
|
||||
SHT30::Setup();
|
||||
TSL2561::Setup();
|
||||
HX711::Setup();
|
||||
SensirionSGP30::Setup();
|
||||
|
@ -611,6 +615,7 @@ void loop()
|
|||
BME280::Loop();
|
||||
BMP180::Loop();
|
||||
BMP280::Loop();
|
||||
SHT30::Loop();
|
||||
TSL2561::Loop();
|
||||
HX711::Loop();
|
||||
SensirionSGP30::Loop();
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "BME280.h"
|
||||
#include "BMP180.h"
|
||||
#include "BMP280.h"
|
||||
#include "SHT30.h"
|
||||
#include "TSL2561.h"
|
||||
#include "HX711.h"
|
||||
#include "DHT.h"
|
||||
|
|
Loading…
Reference in New Issue