masz cały kod:
Kod: Zaznacz cały
#include <SPI.h>
#include <SuplaDevice.h>
#include <supla/sensor/BME280.h>
#define sensor_address 0x76 // Adafruit devices use 0x77 all others use 0x76
Adafruit_BME280 bme;
#include <supla/network/esp_wifi.h>
Supla::ESPWifi wifi("XXF", "XX");
void setup() {
Serial.begin(115200);
if (!bme.begin(sensor_address)) Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
Serial.println("-- Default Test --");
Serial.println("Temperature = " + String(bme.readTemperature()) + "'C");
Serial.println(" Pressure = " + String((bme.readPressure() / 100.0F) + 3.8) + " hPa"); // +4.3 Adjustment for current altitude, each device is different
Serial.println(" Humidity = " + String(bme.readHumidity()) + " %");
// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] = {0x90, 0x7B, 0xD8, 0x9B, 0x7F, 0x9A, 0x71, 0x2E, 0xF5, 0x95, 0x36, 0xC6, 0xAE, 0x4D, 0x1A, 0x8D};
// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {0xF0, 0xB5, 0xBC, 0xC7, 0x96, 0xA4, 0x00, 0x14, 0x93, 0x5E, 0xDD, 0x53, 0x08, 0x4A, 0xF6, 0x03};
// new Supla::Sensor::BME280(0x76, 100);
auto bt = new Supla::Sensor::BME280(0x76, 100);
bt->getChannel()->setValidityTimeSec(5*60);
bt->getSecondaryChannel()->setValidityTimeSec(5*60);
/*
SuplaDevice Initialization.
*/
SuplaDevice.setName("Test R@F");
SuplaDevice.begin(GUID, // Global Unique Identifier
"svrX.supla.org", // SUPLA server address
"XX@gmail.com", // Email address used to login to Supla Cloud
AUTHKEY); // Authorization key
delay(30000);
}
void loop() {
SuplaDevice.iterate();
BME280_Sleep(sensor_address); // Now place BME280 into sleep mode
Serial.println(" ESP8266 to Sleep mode..."); // Say going to sleep
ESP.deepSleep(300e6); // 20e6 is 20 microseconds
}
void BME280_Sleep(int device_address) {
// BME280 Register 0xF4 (control measurement register) sets the device mode, specifically bits 1,0
// The bit positions are called 'mode[1:0]'. See datasheet Table 25 and Paragraph 3.3 for more detail.
// Mode[1:0] Mode
// 00 'Sleep' mode
// 01 / 10 'Forced' mode, use either '01' or '10'
// 11 'Normal' mode
Serial.println("BME280 to Sleep mode...");
Wire.beginTransmission(device_address);
Wire.write((uint8_t)0xF4); // Select Control Measurement Register
Wire.write((uint8_t)0b00000000); // Send '00' for Sleep mode
Wire.endTransmission();
}