sgp30 running but maybe not functional, usage of secrets.h file
This commit is contained in:
parent
1796882154
commit
52472843f4
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#hide credentials from git
|
||||||
|
secrets.h
|
||||||
|
|
@ -2,12 +2,13 @@
|
|||||||
#define SERIAL_DEBUG
|
#define SERIAL_DEBUG
|
||||||
//#define OLED_OUTPUT
|
//#define OLED_OUTPUT
|
||||||
//#define BATTERY_USE
|
//#define BATTERY_USE
|
||||||
//#define BME2_USE
|
#define BME2_USE
|
||||||
//#define BME6_USE
|
//#define BME6_USE
|
||||||
//#define BH_USE
|
#define BH_USE
|
||||||
#define SHT_USE
|
//#define SHT_USE
|
||||||
//#define VEML_USE
|
//#define VEML_USE
|
||||||
//#define CCS_USE
|
//#define CCS_USE
|
||||||
|
#define SGP30_USE
|
||||||
const bool metric = true;
|
const bool metric = true;
|
||||||
/************************* generic libs *********************************/
|
/************************* generic libs *********************************/
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
@ -79,13 +80,12 @@ const bool metric = true;
|
|||||||
|
|
||||||
/************************* WiFi Client *********************************/
|
/************************* WiFi Client *********************************/
|
||||||
|
|
||||||
#define WLAN_SSID "IoT"
|
//see secrets.h
|
||||||
#define WLAN_PASS "TF0xJJHtMz5kJUdh3dqf"
|
|
||||||
const int WIFI_CONNECT_TIMEOUT = 10; // seconds - max time for wifi connect to router, if exceeded go to sleep
|
const int WIFI_CONNECT_TIMEOUT = 10; // seconds - max time for wifi connect to router, if exceeded go to sleep
|
||||||
|
|
||||||
|
|
||||||
//ToDo Legacy IPv4
|
//ToDo Legacy IPv4
|
||||||
IPAddress ip(10, 0, 4, 7);
|
IPAddress ip(10, 0, 4, 14);
|
||||||
IPAddress gateway(10, 0, 4, 1);
|
IPAddress gateway(10, 0, 4, 1);
|
||||||
IPAddress subnet(255, 255, 255, 240);
|
IPAddress subnet(255, 255, 255, 240);
|
||||||
IPAddress dns(10, 0, 4, 1);
|
IPAddress dns(10, 0, 4, 1);
|
||||||
@ -94,45 +94,42 @@ IPAddress mqttBroker(10, 0, 4, 1); //failsafe
|
|||||||
const int FW_VERSION = 10;
|
const int FW_VERSION = 10;
|
||||||
const char* fwUrlBase = "http://10.0.4.2/fota/";
|
const char* fwUrlBase = "http://10.0.4.2/fota/";
|
||||||
/************************* MQTT Broker Setup *********************************/
|
/************************* MQTT Broker Setup *********************************/
|
||||||
#define name "bathroom"
|
#define name "test"
|
||||||
const int MQTT_PORT = 1883;
|
//see secrets.h
|
||||||
const char MQTT_SERVER[] = "mqtt.koelner.dynvpn.de";
|
|
||||||
char MQTT_CLIENTID[10];
|
char MQTT_CLIENTID[10];
|
||||||
const char MQTT_USERNAME[] = "input";
|
const char MQTT_WILL_TOPIC[] = "test/sys/will";
|
||||||
const char MQTT_PASSWORD[] = "tFnlKJu9";
|
|
||||||
const char MQTT_WILL_TOPIC[] = "bathroom/sys/will";
|
|
||||||
const int MQTT_WILL_QOS = 0;
|
const int MQTT_WILL_QOS = 0;
|
||||||
const int MQTT_WILL_RETAIN = 0;
|
const int MQTT_WILL_RETAIN = 0;
|
||||||
const char MQTT_WILL_MESSAGE[] = "Finally died...";
|
const char MQTT_WILL_MESSAGE[] = "Finally died...";
|
||||||
/****************************** Feeds ***************************************/
|
/****************************** Feeds ***************************************/
|
||||||
//ToDo: generate feed from CLIENTID and determine the ClientID from the ChipID
|
//ToDo: generate feed from CLIENTID and determine the ClientID from the ChipID
|
||||||
#if defined(BME2_USE) || defined(BME6_USE)
|
#if defined(BME2_USE) || defined(BME6_USE)
|
||||||
const char TEMPERATURE_FEED[] = "bathroom/sensors/temperature";
|
const char TEMPERATURE_FEED[] = "test/sensors/temperature";
|
||||||
const char PRESSURE_FEED[] = "bathroom/sensors/pressure";
|
const char PRESSURE_FEED[] = "test/sensors/pressure";
|
||||||
const char HUMIDITY_FEED[] = "bathroom/sensors/humidity";
|
const char HUMIDITY_FEED[] = "test/sensors/humidity";
|
||||||
const char ABSHUMIDITY_FEED[] = "bathroom/sensors/abshumidity";
|
const char ABSHUMIDITY_FEED[] = "test/sensors/abshumidity";
|
||||||
#endif
|
#endif
|
||||||
#if defined(SHT_USE)
|
#if defined(SHT_USE)
|
||||||
const char TEMPERATURE_FEED[] = "bathroom/sensors/temperature";
|
const char TEMPERATURE_FEED[] = "test/sensors/temperature";
|
||||||
const char HUMIDITY_FEED[] = "bathroom/sensors/humidity";
|
const char HUMIDITY_FEED[] = "test/sensors/humidity";
|
||||||
const char ABSHUMIDITY_FEED[] = "bathroom/sensors/abshumidity";
|
const char ABSHUMIDITY_FEED[] = "test/sensors/abshumidity";
|
||||||
#endif
|
#endif
|
||||||
#ifdef BME6_USE
|
#ifdef BME6_USE
|
||||||
const char IAQ_FEED[] = "bathroom/sensors/iaq";
|
const char IAQ_FEED[] = "test/sensors/iaq";
|
||||||
const char IAQPREC_FEED[] = "bathroom/sensors/iaqprec";
|
const char IAQPREC_FEED[] = "test/sensors/iaqprec";
|
||||||
#endif
|
#endif
|
||||||
#ifdef VEML_USE
|
#ifdef VEML_USE
|
||||||
const char UVA_FEED[] = "bathroom/sensors/uva";
|
const char UVA_FEED[] = "test/sensors/uva";
|
||||||
const char UVB_FEED[] = "bathroom/sensors/uvb";
|
const char UVB_FEED[] = "test/sensors/uvb";
|
||||||
const char UVINDEX_FEED[] = "bathroom/sensors/uvindex";
|
const char UVINDEX_FEED[] = "test/sensors/uvindex";
|
||||||
#endif
|
#endif
|
||||||
#ifdef BH_USE
|
#ifdef BH_USE
|
||||||
const char LIGHT_FEED[] = "bathroom/sensors/light";
|
const char LIGHT_FEED[] = "test/sensors/light";
|
||||||
#endif
|
#endif
|
||||||
#ifdef CCS_USE
|
#if defined (CCS_USE) || defined(SGP30_USE)
|
||||||
const char ECO2_FEED[] = "bathroom/sensors/eco2";
|
const char ECO2_FEED[] = "test/sensors/eco2";
|
||||||
const char TVOC_FEED[] = "bathroom/sensors/tvoc";
|
const char TVOC_FEED[] = "test/sensors/tvoc";
|
||||||
#endif
|
#endif
|
||||||
#ifdef BATTERY_USE
|
#ifdef BATTERY_USE
|
||||||
const char BATTERY_FEED[] = "bathroom/sys/battery";
|
const char BATTERY_FEED[] = "test/sys/battery";
|
||||||
#endif
|
#endif
|
||||||
|
93
main.ino
93
main.ino
@ -10,6 +10,9 @@ struct {
|
|||||||
#ifdef CCS_USE
|
#ifdef CCS_USE
|
||||||
bool ccsInit = false;
|
bool ccsInit = false;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SGP30_USE
|
||||||
|
bool sgpInit = false;
|
||||||
|
#endif
|
||||||
} rtcData;
|
} rtcData;
|
||||||
/************************* RTC Mem *********************************/
|
/************************* RTC Mem *********************************/
|
||||||
#define WiFi_RTC 0
|
#define WiFi_RTC 0
|
||||||
@ -102,6 +105,10 @@ CCS811 ccs;
|
|||||||
#define CCSRESET D6 //GPIO12
|
#define CCSRESET D6 //GPIO12
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SGP30_USE
|
||||||
|
#include "SparkFun_SGP30_Arduino_Library.h"
|
||||||
|
SGP30 sgp;
|
||||||
|
#endif
|
||||||
|
|
||||||
void messageReceived(String &topic, String &payload) {
|
void messageReceived(String &topic, String &payload) {
|
||||||
#ifdef SERIAL_DEBUG
|
#ifdef SERIAL_DEBUG
|
||||||
@ -217,7 +224,7 @@ char uva[8];
|
|||||||
char uvb[8];
|
char uvb[8];
|
||||||
char uvindex[5];
|
char uvindex[5];
|
||||||
#endif
|
#endif
|
||||||
#ifdef CCS_USE
|
#if defined(CCS_USE) || defined(SGP30_USE)
|
||||||
float eco2(NAN);
|
float eco2(NAN);
|
||||||
String eco2_str;
|
String eco2_str;
|
||||||
char eco2C[8];
|
char eco2C[8];
|
||||||
@ -239,6 +246,7 @@ bool veml6075Check = false;
|
|||||||
bool bh1750Check = false;
|
bool bh1750Check = false;
|
||||||
bool ccs811Check = false;
|
bool ccs811Check = false;
|
||||||
bool sht30Check = false;
|
bool sht30Check = false;
|
||||||
|
bool sgp30Check = false;
|
||||||
|
|
||||||
WiFiClient mqttSocket;
|
WiFiClient mqttSocket;
|
||||||
MQTTClient mqttClient;
|
MQTTClient mqttClient;
|
||||||
@ -545,6 +553,87 @@ Serial.print(F("\tSHT30 init...\t"));
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
/*********************SGP30 I2C init **************************************/
|
||||||
|
#ifdef SGP30_USE
|
||||||
|
// Extend I2C clock stretch timeout (See Notes)
|
||||||
|
//Wire.setClockStretchLimit(500);
|
||||||
|
Wire.setClockStretchLimit(400000);
|
||||||
|
#ifdef SERIAL_DEBUG
|
||||||
|
Serial.print(F("\tSGP30 init...\t"));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef OLED_OUTPUT
|
||||||
|
// clear the display
|
||||||
|
display.clear();
|
||||||
|
display.drawStringMaxWidth(0, 0, 128, "SGP30 init" );
|
||||||
|
// write the buffer to the display
|
||||||
|
display.display();
|
||||||
|
#endif
|
||||||
|
if (!sgp.begin())
|
||||||
|
{
|
||||||
|
delay(10);
|
||||||
|
#ifdef SERIAL_DEBUG
|
||||||
|
Serial.println(F("no SGP30 detected!"));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef OLED_OUTPUT
|
||||||
|
display.drawStringMaxWidth(0, 16, 128, "SGP30 FAILED" );
|
||||||
|
// write the buffer to the display
|
||||||
|
display.display();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sgp30Check = true;
|
||||||
|
delay(100);
|
||||||
|
/*
|
||||||
|
//Get SGP30's ID
|
||||||
|
sgp.getSerialID();
|
||||||
|
//Get version number
|
||||||
|
sgp.getFeatureSetVersion();
|
||||||
|
Serial.print("SerialID: 0x");
|
||||||
|
Serial.print((unsigned long)sgp.serialID, HEX);
|
||||||
|
Serial.print("\tFeature Set Version: 0x");
|
||||||
|
Serial.println(sgp.featureSetVersion, HEX);*/
|
||||||
|
SGP30ERR error;
|
||||||
|
//measureTest() should not be called after a call to initAirQuality()
|
||||||
|
error = sgp.measureTest();
|
||||||
|
if (error == SUCCESS) {
|
||||||
|
Serial.println("Success!");
|
||||||
|
}
|
||||||
|
else if (error == ERR_BAD_CRC) {
|
||||||
|
Serial.println("CRC Failed");
|
||||||
|
}
|
||||||
|
else if (error == ERR_I2C_TIMEOUT) {
|
||||||
|
Serial.println("I2C Timed out");
|
||||||
|
}
|
||||||
|
else if (error == SELF_TEST_FAIL) {
|
||||||
|
Serial.println("Self Test Failed");
|
||||||
|
}
|
||||||
|
//if (!rtcData.sgpInit) {
|
||||||
|
if (error == SELF_TEST_FAIL)
|
||||||
|
{
|
||||||
|
Serial.println(F("SGP30 not initialised"));
|
||||||
|
sgp.initAirQuality();
|
||||||
|
Serial.println(F("SGP30 warm up "));
|
||||||
|
|
||||||
|
error = sgp.measureTest();
|
||||||
|
if (error == SUCCESS) {
|
||||||
|
rtcData.sgpInit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef SERIAL_DEBUG
|
||||||
|
Serial.println(F("SGP30 ready."));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef OLED_OUTPUT
|
||||||
|
display.drawStringMaxWidth(0, 16, 128, "SGP30 ready" );
|
||||||
|
// write the buffer to the display
|
||||||
|
display.display();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/******************** i2c init END ****************/
|
/******************** i2c init END ****************/
|
||||||
}
|
}
|
||||||
@ -556,7 +645,7 @@ void setup() {
|
|||||||
// if serial is not initialized all following calls to serial end dead.
|
// if serial is not initialized all following calls to serial end dead.
|
||||||
#ifdef SERIAL_DEBUG
|
#ifdef SERIAL_DEBUG
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
Serial.begin(115200);
|
Serial.begin(9600);
|
||||||
while (!Serial) {
|
while (!Serial) {
|
||||||
delay(1);
|
delay(1);
|
||||||
} // Wait
|
} // Wait
|
||||||
|
104
measurement.ino
104
measurement.ino
@ -94,6 +94,7 @@ void measurement() {
|
|||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CCS_USE
|
#ifdef CCS_USE
|
||||||
if (ccs811Check) {
|
if (ccs811Check) {
|
||||||
yield();
|
yield();
|
||||||
@ -128,6 +129,24 @@ void measurement() {
|
|||||||
//Serial.println(F("ERROR: CCS811 Data Not Ready"));
|
//Serial.println(F("ERROR: CCS811 Data Not Ready"));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
/******************** SGP30 ********************/
|
||||||
|
#ifdef SGP30_USE
|
||||||
|
if (sgp30Check) {
|
||||||
|
yield();
|
||||||
|
uint8_t sgp_error = 0;
|
||||||
|
// set environmental data
|
||||||
|
//sgp.setHumidity(humidity);
|
||||||
|
sgp.measureAirQuality();
|
||||||
|
|
||||||
|
// Data is ready
|
||||||
|
eco2 = float(sgp.CO2);
|
||||||
|
tvoc = float(sgp.TVOC);
|
||||||
|
}
|
||||||
|
#ifdef SERIAL_DEBUG
|
||||||
|
//Serial.println(F("ERROR: SGP30 Data Not Ready"));
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/************************** ADC Measurement *********************************/
|
/************************** ADC Measurement *********************************/
|
||||||
#ifdef BATTERY_USE
|
#ifdef BATTERY_USE
|
||||||
@ -799,6 +818,91 @@ void measurement() {
|
|||||||
Serial.println("OK");
|
Serial.println("OK");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef OLED_OUTPUT
|
||||||
|
display.drawStringMaxWidth(110, 0, 128, "o");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
mqttClient.loop();
|
||||||
|
yield();
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/********************* SGP30 eCO2 **************************************/
|
||||||
|
#ifdef SGP30_USE
|
||||||
|
//fix sensors internal wait delay
|
||||||
|
if (sgp30Check) {
|
||||||
|
#ifdef SERIAL_DEBUG
|
||||||
|
Serial.print("eCO2:\t\t");
|
||||||
|
Serial.print(eco2);
|
||||||
|
Serial.print(" ppm");
|
||||||
|
Serial.print("\t\t");
|
||||||
|
#endif
|
||||||
|
eco2_str = String(eco2);
|
||||||
|
eco2_str.toCharArray(eco2C, eco2_str.length() + 1);
|
||||||
|
#ifdef OLED_OUTPUT
|
||||||
|
display.drawStringMaxWidth(0, 0, 128, " " + eco2_str + "ppm" );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SERIAL_DEBUG
|
||||||
|
Serial.print("Publish eCO2: \t\t");
|
||||||
|
#endif
|
||||||
|
if (! mqttClient.publish(ECO2_FEED, eco2C, true, 1) || !mqttClient.loop()) {
|
||||||
|
#ifdef SERIAL_DEBUG
|
||||||
|
Serial.println("Failed!");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef OLED_OUTPUT
|
||||||
|
display.drawStringMaxWidth(110, 0, 128, "x");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} else {
|
||||||
|
#ifdef SERIAL_DEBUG
|
||||||
|
Serial.println("OK");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef OLED_OUTPUT
|
||||||
|
display.drawStringMaxWidth(110, 0, 128, "o");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
mqttClient.loop();
|
||||||
|
yield();
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/********************* TVOC **************************************/
|
||||||
|
#ifdef SGP30_USE
|
||||||
|
//fix sensors internal wait delay
|
||||||
|
if (sgp30Check) {
|
||||||
|
#ifdef SERIAL_DEBUG
|
||||||
|
Serial.print("TVOC:\t\t");
|
||||||
|
Serial.print(tvoc);
|
||||||
|
Serial.print(" ppb");
|
||||||
|
Serial.print("\t\t");
|
||||||
|
#endif
|
||||||
|
tvoc_str = String(tvoc);
|
||||||
|
tvoc_str.toCharArray(tvocC, tvoc_str.length() + 1);
|
||||||
|
#ifdef OLED_OUTPUT
|
||||||
|
display.drawStringMaxWidth(0, 0, 128, " " + tvoc_str + "ppb" );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SERIAL_DEBUG
|
||||||
|
Serial.print("Publish TVOC: \t\t");
|
||||||
|
#endif
|
||||||
|
if (! mqttClient.publish(TVOC_FEED, tvocC, true, 1) || !mqttClient.loop()) {
|
||||||
|
#ifdef SERIAL_DEBUG
|
||||||
|
Serial.println("Failed!");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef OLED_OUTPUT
|
||||||
|
display.drawStringMaxWidth(110, 0, 128, "x");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} else {
|
||||||
|
#ifdef SERIAL_DEBUG
|
||||||
|
Serial.println("OK");
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef OLED_OUTPUT
|
#ifdef OLED_OUTPUT
|
||||||
display.drawStringMaxWidth(110, 0, 128, "o");
|
display.drawStringMaxWidth(110, 0, 128, "o");
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user