-
Notifications
You must be signed in to change notification settings - Fork 319
/
_P119_BME680.ino
156 lines (123 loc) · 4.77 KB
/
_P119_BME680.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//#######################################################################################################
//#################### Plugin 119 BME680 I2C Temp/Hum/Barometric/Pressure/Gas Resistence Sensor ########
//#######################################################################################################
/*******************************************************************************
* Copyright 2017
* Written by Rossen Tchobanski ([email protected])
* BSD license, all text above must be included in any redistribution
*
* Release notes:
Adafruit_BME680 Library v1.0.5 required (https://github.com/adafruit/Adafruit_BME680/tree/1.0.5)
/******************************************************************************/
//#ifdef PLUGIN_BUILD_DEV
//#ifdef PLUGIN_BUILD_TESTING
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME680.h>
#define PLUGIN_119
#define PLUGIN_ID_119 119
#define PLUGIN_NAME_119 "Environment - BME680"
#define PLUGIN_VALUENAME1_119 "Temperature"
#define PLUGIN_VALUENAME2_119 "Humidity"
#define PLUGIN_VALUENAME3_119 "Pressure"
#define PLUGIN_VALUENAME4_119 "Gas"
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME680 bme; // I2C
//Adafruit_BME680 bme(BME_CS); // hardware SPI
//Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
boolean Plugin_119_init = false;
boolean Plugin_119(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_119;
Device[deviceCount].Type = DEVICE_TYPE_I2C;
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_QUAD;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 4;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].GlobalSyncOption = true;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_119);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_119));
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_119));
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[2], PSTR(PLUGIN_VALUENAME3_119));
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[3], PSTR(PLUGIN_VALUENAME4_119));
break;
}
case PLUGIN_WEBFORM_LOAD:
{
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
/*
String options[2];
options[0] = F("0x76 - default settings (SDO Low)");
options[1] = F("0x77 - alternate settings (SDO HIGH)");
*/
int optionValues[2] = { 0x77, 0x76 };
addFormSelectorI2C(F("plugin_119_BME680_i2c"), 2, optionValues, choice);
addFormNote(F("SDO Low=0x76, High=0x77"));
addFormNumericBox(F("Altitude"), F("plugin_119_BME680_elev"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
addUnit(F("m"));
success = true;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_119_BME680_i2c"));
Settings.TaskDevicePluginConfig[event->TaskIndex][1] = getFormItemInt(F("plugin_119_BME680_elev"));
success = true;
break;
}
case PLUGIN_READ:
{
if (!Plugin_119_init)
{
addLog(LOG_LEVEL_INFO, F("BME680 : init"));
Plugin_119_init = bme.begin();
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
success = true;
break;
}
if (Plugin_119_init)
{
if (! bme.performReading()) {
addLog(LOG_LEVEL_ERROR, F("BME680 : Failed to perform reading!"));
success = false;
break;
}
UserVar[event->BaseVarIndex + 0] = bme.temperature;
UserVar[event->BaseVarIndex + 1] = bme.humidity;
UserVar[event->BaseVarIndex + 2] = bme.pressure / 100.0;
UserVar[event->BaseVarIndex + 3] = bme.gas_resistance / 1000.0;
}
success = true;
break;
}
}
return success;
}
//#endif