- 2019-3-3
- ESP-WROOM-02
- 2 comments
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> #include <BME280_MOD-1022.h> #include <Wire.h> #include "Ambient.h" #define WakeMode RFMode #define WAKE_RF_DEFAULT RF_DEFAULT #define WAKE_RFCAL RF_CAL #define WAKE_NO_RFCAL RF_NO_CAL #define WAKE_RF_DISABLED RF_DISABLED WiFiClient client; Ambient ambient; // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = "fromBlynkApp"; //Blynkで生成されるAuth Token unsigned long lastCheck = 0; double tempMostAccurate, humidityMostAccurate, pressureMostAccurate; char buff[50]; // Arduino needs this to pring pretty numbers void printFormattedFloat(float x, uint8_t precision) { char buffer[10]; dtostrf(x, 7, precision, buffer); Serial.print(buffer); } void deepSleep(uint32_t time_us, RFMode mode = RF_DEFAULT); // Ambientのチャネル設定 unsigned int channelId = 1234; //AmbientのチャネルID const char* writeKey = "abcd1234"; //Ambientのライトキー void setup() { Serial.begin(115200); Blynk.begin(auth, "SSID", "password"); //無線ルーターのSSIDとパスワード Wire.begin(); pinMode(12, OUTPUT); // need to read the NVM compensation parameters BME280.readCompensationParams(); BME280.writeStandbyTime(tsb_0p5ms); // tsb = 0.5ms BME280.writeFilterCoefficient(fc_16); // IIR Filter coefficient 16 BME280.writeOversamplingPressure(os16x); // pressure x16 BME280.writeOversamplingTemperature(os2x); // temperature x2 BME280.writeOversamplingHumidity(os1x); // humidity x1 BME280.writeMode(smNormal); } void formattedFloat(float x, uint8_t precision, char *buff) { dtostrf(x, 7, precision, buff); } BLYNK_READ(V0) { tempMostAccurate = BME280.getTemperatureMostAccurate(); Serial.print("Temp "); printFormattedFloat(tempMostAccurate, 2); Serial.println(); formattedFloat(tempMostAccurate, 2, buff); Blynk.virtualWrite(V0, buff); } BLYNK_READ(V1) { humidityMostAccurate = BME280.getHumidityMostAccurate(); Serial.print("humid "); printFormattedFloat(humidityMostAccurate, 2); Serial.println(); formattedFloat(humidityMostAccurate, 2, buff); Blynk.virtualWrite(V1, buff); } BLYNK_READ(V2) { pressureMostAccurate = BME280.getPressureMostAccurate(); Serial.print("pressure "); printFormattedFloat(pressureMostAccurate, 2); Serial.println(); formattedFloat(pressureMostAccurate, 2, buff); Blynk.virtualWrite(V2, buff); ambient.begin(channelId, writeKey, &client); // チャネルIDとライトキーを指定してAmbientの初期化 ESP.deepSleep(300 * 1000 * 1000); } void loop() { Blynk.run(); int diff = millis() - lastCheck; if (diff > 1000) { while (BME280.isMeasuring()) { } // read out the data - must do this before calling the getxxxxx routines BME280.readMeasurements(); lastCheck = millis(); } else if (diff < 0) { lastCheck = 0; } ambient.set(1, tempMostAccurate); ambient.set(2, humidityMostAccurate); ambient.set(3, pressureMostAccurate); ambient.send(); }
コメント
この記事へのトラックバックはありません。
すごいなあ
ありがとうございます!