#include <Wire.h>
#include <AHT10.h> // https://github.com/enjoyneering/AHT10
//https://github.com/enjoyneering/AHTxx

#include <Adafruit_BMP280.h> //CHECK #define BMP280_ADDRESS mine works with (0x76)
// https://github.com/adafruit/Adafruit_BMP280_Library

const char* ssid        = "asd"; //YOUR WIFI SSID
const char* password    = "asd"; //YOUR WIFIPASS
const char* host        = "api.thingspeak.com";
const char* writeAPIKey = "asd"; //YOUR APIKEY

Wire wire(2, 0);

//AHT10
AHT10 myAHT10(AHT10_ADDRESS_0X38);
//BMP280
Adafruit_BMP280 bmp(&wire);

void setup() {
  // put your setup code here, to run once:
  WiFi.persistent(false);  //disable saving wifi config into SDK flash area
  WiFi.forceSleepBegin();  //disable AP & station by calling "WiFi.mode(WIFI_OFF)" & put modem to sleep

  Serial.begin(115200);

  /* AHT10 connection check */
  while (myAHT10.begin(SDA, SCL) != true)
  {
    lcd.print(F("AHT10 Error"));
    Serial.println(F("AHT10 not connected or fail to load calibration coefficient"));
    delay(5000);
  }

  if(AHT10.begin(eAHT10Address_Low)) Serial.println("Init AHT10 Success!");
  else Serial.println("Init AHT10 Failed!");

  //BMP280
  if (!bmp.begin())
  {
  //   Serial.println("No BMP280");
  //   while (1) {}
  }
  //Connect to WiFi network
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
  }
}

void loop() {
  // put your main code here, to run repeatedly:

  valueTH = myAHT10.readTemperature(AHT10_FORCE_READ_DATA); //float in °C
  valueTH = myAHT10.readHumidity(AHT10_USE_READ_DATA);      //float in %

// BMP return float
  bmp.readTemperature(); // float in °C
  bmp.readPressure(); // float in Pa
  bmp.readAltitude(1024); // send sealevelpressure in hPa, return float in m


  delay(1000);
}