Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SmartHome
NodeManager_GasSensor
Commits
275a645b
Commit
275a645b
authored
Mar 31, 2017
by
user2684
Browse files
Add support for BME280 temperature/humudity/pressure sensor #21
parent
d2a785b1
Changes
4
Hide whitespace changes
Inline
Side-by-side
NodeManagerTemplate/NodeManager.cpp
View file @
275a645b
...
@@ -888,6 +888,93 @@ void SensorMLX90614::onReceive(const MyMessage & message) {
...
@@ -888,6 +888,93 @@ void SensorMLX90614::onReceive(const MyMessage & message) {
}
}
#endif
#endif
/*
SensorBME280
*/
#if MODULE_BME280 == 1
// contructor
SensorBME280
::
SensorBME280
(
int
child_id
,
Adafruit_BME280
*
bme
,
int
sensor_type
)
:
Sensor
(
child_id
,
A4
)
{
// store the sensor type (0: temperature, 1: humidity, 2: pressure)
_sensor_type
=
sensor_type
;
if
(
_sensor_type
==
0
)
{
// temperature sensor
setPresentation
(
S_TEMP
);
setType
(
V_TEMP
);
setValueType
(
TYPE_FLOAT
);
}
else
if
(
_sensor_type
==
1
)
{
// humidity sensor
setPresentation
(
S_HUM
);
setType
(
V_HUM
);
setValueType
(
TYPE_FLOAT
);
}
else
if
(
_sensor_type
==
2
)
{
// pressure sensor
setPresentation
(
S_BARO
);
setType
(
V_PRESSURE
);
setValueType
(
TYPE_FLOAT
);
}
}
// what do to during setup
void
SensorBME280
::
onBefore
()
{
// initialize the library
}
// what do to during loop
void
SensorBME280
::
onLoop
()
{
// temperature sensor
if
(
_sensor_type
==
0
)
{
// read the temperature
float
temperature
=
_bme
->
readTemperature
();
// convert it
if
(
!
getControllerConfig
().
isMetric
)
temperature
=
temperature
*
1.8
+
32
;
#if DEBUG == 1
Serial
.
print
(
"BME I="
);
Serial
.
print
(
_child_id
);
Serial
.
print
(
" T="
);
Serial
.
println
(
temperature
);
#endif
// store the value
if
(
!
isnan
(
temperature
))
_value_float
=
temperature
;
}
// Humidity Sensor
else
if
(
_sensor_type
==
1
)
{
// read humidity
float
humidity
=
_bme
->
readHumidity
();
if
(
isnan
(
humidity
))
return
;
#if DEBUG == 1
Serial
.
print
(
"BME I="
);
Serial
.
print
(
_child_id
);
Serial
.
print
(
" H="
);
Serial
.
println
(
humidity
);
#endif
// store the value
if
(
!
isnan
(
humidity
))
_value_float
=
humidity
;
}
// Pressure Sensor
else
if
(
_sensor_type
==
2
)
{
// read humidity
float
pressure
=
_bme
->
readPressure
()
/
100.0
F
;
if
(
isnan
(
pressure
))
return
;
#if DEBUG == 1
Serial
.
print
(
"BME I="
);
Serial
.
print
(
_child_id
);
Serial
.
print
(
" P="
);
Serial
.
println
(
pressure
);
#endif
// store the value
if
(
!
isnan
(
pressure
))
_value_float
=
pressure
;
}
}
// what do to as the main task when receiving a message
void
SensorBME280
::
onReceive
(
const
MyMessage
&
message
)
{
onLoop
();
}
#endif
/*******************************************
/*******************************************
NodeManager
NodeManager
*/
*/
...
@@ -1050,15 +1137,28 @@ int NodeManager::registerSensor(int sensor_type, int pin, int child_id) {
...
@@ -1050,15 +1137,28 @@ int NodeManager::registerSensor(int sensor_type, int pin, int child_id) {
#endif
#endif
#if MODULE_MLX90614 == 1
#if MODULE_MLX90614 == 1
else
if
(
sensor_type
==
SENSOR_MLX90614
)
{
else
if
(
sensor_type
==
SENSOR_MLX90614
)
{
Serial
.
println
(
"1"
);
Adafruit_MLX90614
*
mlx
=
new
Adafruit_MLX90614
();
Adafruit_MLX90614
*
mlx
=
new
Adafruit_MLX90614
();
Serial
.
println
(
"2"
);
registerSensor
(
new
SensorMLX90614
(
child_id
,
mlx
,
0
));
registerSensor
(
new
SensorMLX90614
(
child_id
,
mlx
,
0
));
Serial
.
println
(
"3"
);
child_id
=
_getAvailableChildId
();
child_id
=
_getAvailableChildId
();
return
registerSensor
(
new
SensorMLX90614
(
child_id
,
mlx
,
1
));
return
registerSensor
(
new
SensorMLX90614
(
child_id
,
mlx
,
1
));
}
}
#endif
#endif
#if MODULE_BME280 == 1
else
if
(
sensor_type
==
SENSOR_BME280
)
{
Adafruit_BME280
*
bme
=
new
Adafruit_BME280
();
if
(
!
bme
->
begin
())
{
#if DEBUG == 1
Serial
.
println
(
"NO BME"
);
#endif
return
-
1
;
}
registerSensor
(
new
SensorBME280
(
child_id
,
bme
,
0
));
child_id
=
_getAvailableChildId
();
registerSensor
(
new
SensorBME280
(
child_id
,
bme
,
1
));
child_id
=
_getAvailableChildId
();
return
registerSensor
(
new
SensorBME280
(
child_id
,
bme
,
2
));
}
#endif
else
{
else
{
#if DEBUG == 1
#if DEBUG == 1
Serial
.
print
(
"INVALID "
);
Serial
.
print
(
"INVALID "
);
...
...
NodeManagerTemplate/NodeManager.h
View file @
275a645b
...
@@ -133,7 +133,10 @@
...
@@ -133,7 +133,10 @@
#ifndef MODULE_MLX90614
#ifndef MODULE_MLX90614
#define MODULE_MLX90614 0
#define MODULE_MLX90614 0
#endif
#endif
// Enable this module to use one of the following sensors: SENSOR_BME280
#ifndef MODULE_BME280
#define MODULE_BME280 0
#endif
/***********************************
/***********************************
Sensors types
Sensors types
*/
*/
...
@@ -187,8 +190,11 @@
...
@@ -187,8 +190,11 @@
// MLX90614 sensor, contactless temperature sensor
// MLX90614 sensor, contactless temperature sensor
#define SENSOR_MLX90614 17
#define SENSOR_MLX90614 17
#endif
#endif
#if MODULE_BME280 == 1
// last Id: 17
// MLX90614 sensor, contactless temperature sensor
#define SENSOR_BME280 18
#endif
// last Id: 18
/***********************************
/***********************************
Libraries
Libraries
*/
*/
...
@@ -218,6 +224,12 @@
...
@@ -218,6 +224,12 @@
#include
<Wire.h>
#include
<Wire.h>
#include
<Adafruit_MLX90614.h>
#include
<Adafruit_MLX90614.h>
#endif
#endif
#if MODULE_BME280 == 1
#include
<Wire.h>
#include
<SPI.h>
#include
<Adafruit_Sensor.h>
#include
<Adafruit_BME280.h>
#endif
/**************************************
/**************************************
Classes
Classes
...
@@ -578,6 +590,23 @@ class SensorMLX90614: public Sensor {
...
@@ -578,6 +590,23 @@ class SensorMLX90614: public Sensor {
};
};
#endif
#endif
/*
SensorBME280
*/
#if MODULE_BME280 == 1
class
SensorBME280
:
public
Sensor
{
public:
SensorBME280
(
int
child_id
,
Adafruit_BME280
*
bme
,
int
sensor_type
);
// define what to do at each stage of the sketch
void
onBefore
();
void
onLoop
();
void
onReceive
(
const
MyMessage
&
message
);
protected:
Adafruit_BME280
*
_bme
;
int
_sensor_type
;
};
#endif
/***************************************
/***************************************
NodeManager: manages all the aspects of the node
NodeManager: manages all the aspects of the node
*/
*/
...
...
NodeManagerTemplate/NodeManagerTemplate.ino
View file @
275a645b
...
@@ -29,7 +29,7 @@ void before() {
...
@@ -29,7 +29,7 @@ void before() {
/*
/*
* Register below your sensors
* Register below your sensors
*/
*/
/*
/*
* Register above your sensors
* Register above your sensors
...
...
NodeManagerTemplate/config.h
View file @
275a645b
...
@@ -66,5 +66,7 @@
...
@@ -66,5 +66,7 @@
#define MODULE_BH1750 0
#define MODULE_BH1750 0
// Enable this module to use one of the following sensors: SENSOR_MLX90614
// Enable this module to use one of the following sensors: SENSOR_MLX90614
#define MODULE_MLX90614 0
#define MODULE_MLX90614 0
// Enable this module to use one of the following sensors: SENSOR_BME280
#define MODULE_BME280 0
#endif
#endif
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment