Skip to content

Commit 10ff540

Browse files
committed
added example for BME280 on an ESP8266
1 parent ae07e9a commit 10ff540

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* MonSens BME280 sensor on a ESP8266 MCU example sketchbook
3+
*
4+
* This sketchbook shows you how to use the BME280 sensor on a ESP8266 and
5+
* expose it via TCP port 30303 to read the sensor data.
6+
*/
7+
8+
// the following constants need to be changed according to your WiFi settings
9+
const char* ssid = "your WiFi's SSID";
10+
const char* password = "your own super secret WiFi password";
11+
12+
// this is the port that your monitoring system may read the sensors at
13+
const int port = 30303;
14+
15+
// (optional) conserve memory by reducing the reserved space for the following
16+
// variables
17+
// maximum sensors supported, defaults to 10 (this example only uses 2)
18+
#define MONSENS_MAX_SENSORS 10
19+
// maximum length of measurement strings, defaults to 9 (5 digits, 1 decimal
20+
// point, 2 digits after the point and 1 string termination character)
21+
#define MONSENS_MAX_MEASUREMENT_WIDTH 9
22+
23+
#include <MonSens_ESP8266.h>
24+
25+
#include <MonSens_BME280.h>
26+
27+
// hardware SPI pins on NodeMCU v1, v2 & v3
28+
#define BME_SCK 14
29+
#define BME_MISO 12
30+
#define BME_MOSI 13
31+
#define BME_CS 15
32+
33+
#define SEALEVELPRESSURE_HPA (1013.25)
34+
35+
Adafruit_BME280 bme(BME_CS); // comment when not using hardware SPI
36+
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // uncomment when using software SPI
37+
//Adafruit_BME280 bme; // uncomment when using I2C
38+
MonSens_BME280 bme280;
39+
40+
MonSens_ESP8266 mcu;
41+
42+
/**
43+
* initialize ESP8266 and sensors
44+
*/
45+
void setup() {
46+
Serial.begin(115200);
47+
delay(10);
48+
49+
mcu.setSsid(ssid);
50+
mcu.setPassword(password);
51+
mcu.setPort(port);
52+
mcu.init();
53+
54+
bme280.setBme(bme);
55+
mcu.addSensor(bme280);
56+
}
57+
58+
/**
59+
* main loop
60+
*
61+
* read string sent to server, then evaluate it and print an according result
62+
*/
63+
void loop() {
64+
mcu.communicate();
65+
}
66+

0 commit comments

Comments
 (0)