|
这是在之前的示例基础上更近一步,添加历史数据存储:
效果如图:
[mw_shl_code=cpp,true]#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "xxxxxxxxxxxx";
char ssid[] = "xxxxx";
char pswd[] = "xxxxxxxx";
BlinkerNumber TEMP("temp"); // Temperature
BlinkerNumber HUMI("humi"); // Humidity
BlinkerNumber PRES("pres"); // Pressure
BlinkerNumber ALTI("alti"); // Altitude
int tempValue;
int humiValue;
int presValue;
int altiValue;
// Download Adafruit-BMP085-Library library here:
// https://github.com/adafruit/Adafruit_BME280_Library
// https://github.com/adafruit/Adafruit_Sensor
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
void dataRead(const String &data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
void dataStorage()
{
readSensor();
Blinker.dataStorage("temp", tempValue);
Blinker.dataStorage("humi", humiValue);
Blinker.dataStorage("pres", altiValue);
}
void heartbeat()
{
readSensor();
TEMP.print(tempValue);
HUMI.print(humiValue);
PRES.print(presValue);
ALTI.print(altiValue);
}
void readSensor()
{
tempValue = bme.readTemperature();
humiValue = bme.readHumidity();
presValue = bme.readPressure();
altiValue = bme.readAltitude(SEALEVELPRESSURE_HPA);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, ssid, pswd);
if (!bme.begin())
{
BLINKER_LOG("Could not find a valid BME280 sensor, check wiring!");
while (1)
{
delay(100);
}
}
readSensor();
Blinker.attachData(dataRead);
Blinker.attachHeartbeat(heartbeat);
Blinker.attachDataStorage(dataStorage);
}
void loop()
{
Blinker.run();
}[/mw_shl_code]
|
|