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 OLED_OUTPUT
|
||||
//#define BATTERY_USE
|
||||
//#define BME2_USE
|
||||
#define BME2_USE
|
||||
//#define BME6_USE
|
||||
//#define BH_USE
|
||||
#define SHT_USE
|
||||
#define BH_USE
|
||||
//#define SHT_USE
|
||||
//#define VEML_USE
|
||||
//#define CCS_USE
|
||||
#define SGP30_USE
|
||||
const bool metric = true;
|
||||
/************************* generic libs *********************************/
|
||||
#include <ESP8266WiFi.h>
|
||||
@ -79,13 +80,12 @@ const bool metric = true;
|
||||
|
||||
/************************* WiFi Client *********************************/
|
||||
|
||||
#define WLAN_SSID "IoT"
|
||||
#define WLAN_PASS "TF0xJJHtMz5kJUdh3dqf"
|
||||
//see secrets.h
|
||||
const int WIFI_CONNECT_TIMEOUT = 10; // seconds - max time for wifi connect to router, if exceeded go to sleep
|
||||
|
||||
|
||||
//ToDo Legacy IPv4
|
||||
IPAddress ip(10, 0, 4, 7);
|
||||
IPAddress ip(10, 0, 4, 14);
|
||||
IPAddress gateway(10, 0, 4, 1);
|
||||
IPAddress subnet(255, 255, 255, 240);
|
||||
IPAddress dns(10, 0, 4, 1);
|
||||
@ -94,45 +94,42 @@ IPAddress mqttBroker(10, 0, 4, 1); //failsafe
|
||||
const int FW_VERSION = 10;
|
||||
const char* fwUrlBase = "http://10.0.4.2/fota/";
|
||||
/************************* MQTT Broker Setup *********************************/
|
||||
#define name "bathroom"
|
||||
const int MQTT_PORT = 1883;
|
||||
const char MQTT_SERVER[] = "mqtt.koelner.dynvpn.de";
|
||||
#define name "test"
|
||||
//see secrets.h
|
||||
char MQTT_CLIENTID[10];
|
||||
const char MQTT_USERNAME[] = "input";
|
||||
const char MQTT_PASSWORD[] = "tFnlKJu9";
|
||||
const char MQTT_WILL_TOPIC[] = "bathroom/sys/will";
|
||||
const char MQTT_WILL_TOPIC[] = "test/sys/will";
|
||||
const int MQTT_WILL_QOS = 0;
|
||||
const int MQTT_WILL_RETAIN = 0;
|
||||
const char MQTT_WILL_MESSAGE[] = "Finally died...";
|
||||
/****************************** Feeds ***************************************/
|
||||
//ToDo: generate feed from CLIENTID and determine the ClientID from the ChipID
|
||||
#if defined(BME2_USE) || defined(BME6_USE)
|
||||
const char TEMPERATURE_FEED[] = "bathroom/sensors/temperature";
|
||||
const char PRESSURE_FEED[] = "bathroom/sensors/pressure";
|
||||
const char HUMIDITY_FEED[] = "bathroom/sensors/humidity";
|
||||
const char ABSHUMIDITY_FEED[] = "bathroom/sensors/abshumidity";
|
||||
const char TEMPERATURE_FEED[] = "test/sensors/temperature";
|
||||
const char PRESSURE_FEED[] = "test/sensors/pressure";
|
||||
const char HUMIDITY_FEED[] = "test/sensors/humidity";
|
||||
const char ABSHUMIDITY_FEED[] = "test/sensors/abshumidity";
|
||||
#endif
|
||||
#if defined(SHT_USE)
|
||||
const char TEMPERATURE_FEED[] = "bathroom/sensors/temperature";
|
||||
const char HUMIDITY_FEED[] = "bathroom/sensors/humidity";
|
||||
const char ABSHUMIDITY_FEED[] = "bathroom/sensors/abshumidity";
|
||||
const char TEMPERATURE_FEED[] = "test/sensors/temperature";
|
||||
const char HUMIDITY_FEED[] = "test/sensors/humidity";
|
||||
const char ABSHUMIDITY_FEED[] = "test/sensors/abshumidity";
|
||||
#endif
|
||||
#ifdef BME6_USE
|
||||
const char IAQ_FEED[] = "bathroom/sensors/iaq";
|
||||
const char IAQPREC_FEED[] = "bathroom/sensors/iaqprec";
|
||||
const char IAQ_FEED[] = "test/sensors/iaq";
|
||||
const char IAQPREC_FEED[] = "test/sensors/iaqprec";
|
||||
#endif
|
||||
#ifdef VEML_USE
|
||||
const char UVA_FEED[] = "bathroom/sensors/uva";
|
||||
const char UVB_FEED[] = "bathroom/sensors/uvb";
|
||||
const char UVINDEX_FEED[] = "bathroom/sensors/uvindex";
|
||||
const char UVA_FEED[] = "test/sensors/uva";
|
||||
const char UVB_FEED[] = "test/sensors/uvb";
|
||||
const char UVINDEX_FEED[] = "test/sensors/uvindex";
|
||||
#endif
|
||||
#ifdef BH_USE
|
||||
const char LIGHT_FEED[] = "bathroom/sensors/light";
|
||||
const char LIGHT_FEED[] = "test/sensors/light";
|
||||
#endif
|
||||
#ifdef CCS_USE
|
||||
const char ECO2_FEED[] = "bathroom/sensors/eco2";
|
||||
const char TVOC_FEED[] = "bathroom/sensors/tvoc";
|
||||
#if defined (CCS_USE) || defined(SGP30_USE)
|
||||
const char ECO2_FEED[] = "test/sensors/eco2";
|
||||
const char TVOC_FEED[] = "test/sensors/tvoc";
|
||||
#endif
|
||||
#ifdef BATTERY_USE
|
||||
const char BATTERY_FEED[] = "bathroom/sys/battery";
|
||||
const char BATTERY_FEED[] = "test/sys/battery";
|
||||
#endif
|
||||
|
103
main.ino
103
main.ino
@ -6,10 +6,13 @@ struct {
|
||||
uint8_t channel; // 1 byte, 5 in total
|
||||
uint8_t bssid[6]; // 6 bytes, 11 in total
|
||||
uint8_t txPow = 0; // 1 byte, 12 in total
|
||||
IPAddress mqttServer=mqttBroker; //save the dns lookup
|
||||
IPAddress mqttServer = mqttBroker; //save the dns lookup
|
||||
#ifdef CCS_USE
|
||||
bool ccsInit = false;
|
||||
#endif
|
||||
#ifdef SGP30_USE
|
||||
bool sgpInit = false;
|
||||
#endif
|
||||
} rtcData;
|
||||
/************************* RTC Mem *********************************/
|
||||
#define WiFi_RTC 0
|
||||
@ -102,6 +105,10 @@ CCS811 ccs;
|
||||
#define CCSRESET D6 //GPIO12
|
||||
#endif
|
||||
|
||||
#ifdef SGP30_USE
|
||||
#include "SparkFun_SGP30_Arduino_Library.h"
|
||||
SGP30 sgp;
|
||||
#endif
|
||||
|
||||
void messageReceived(String &topic, String &payload) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
@ -217,7 +224,7 @@ char uva[8];
|
||||
char uvb[8];
|
||||
char uvindex[5];
|
||||
#endif
|
||||
#ifdef CCS_USE
|
||||
#if defined(CCS_USE) || defined(SGP30_USE)
|
||||
float eco2(NAN);
|
||||
String eco2_str;
|
||||
char eco2C[8];
|
||||
@ -239,6 +246,7 @@ bool veml6075Check = false;
|
||||
bool bh1750Check = false;
|
||||
bool ccs811Check = false;
|
||||
bool sht30Check = false;
|
||||
bool sgp30Check = false;
|
||||
|
||||
WiFiClient mqttSocket;
|
||||
MQTTClient mqttClient;
|
||||
@ -378,10 +386,10 @@ void initSensors() {
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************BME280 I2C init **************************************/
|
||||
/*********************BME280 I2C init **************************************/
|
||||
#ifdef BME2_USE
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print(F("\tBME280 init...\t"));
|
||||
Serial.print(F("\tBME280 init...\t"));
|
||||
#endif
|
||||
|
||||
#ifdef OLED_OUTPUT
|
||||
@ -417,10 +425,10 @@ Serial.print(F("\tBME280 init...\t"));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*********************SHT3X I2C init **************************************/
|
||||
/*********************SHT3X I2C init **************************************/
|
||||
#ifdef SHT_USE
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print(F("\tSHT30 init...\t"));
|
||||
Serial.print(F("\tSHT30 init...\t"));
|
||||
#endif
|
||||
|
||||
#ifdef OLED_OUTPUT
|
||||
@ -545,6 +553,87 @@ Serial.print(F("\tSHT30 init...\t"));
|
||||
#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 ****************/
|
||||
}
|
||||
@ -556,7 +645,7 @@ void setup() {
|
||||
// if serial is not initialized all following calls to serial end dead.
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.flush();
|
||||
Serial.begin(115200);
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
delay(1);
|
||||
} // Wait
|
||||
|
1436
measurement.ino
1436
measurement.ino
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user