#include <DHTesp.h>
#include <U8g2lib.h>
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
const int DHT_PIN = 15;
DHTesp dhtSensor;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");
  u8g2.begin();
  u8g2.setFont(u8g2_font_ncenB08_tr);
  dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
  //表示使用的是DHT22型号的传感器。
}

void loop() {
  // put your main code here, to run repeatedly:
  TempAndHumidity data = dhtSensor.getTempAndHumidity();
  char buffer[20];
  char buffer2[20];
  sprintf(buffer, "Temp:%.2fC", data.temperature);
  sprintf(buffer2, "Humidity:%.2f%", data.humidity);
  u8g2.clearBuffer();
  u8g2.drawStr(0, 20, buffer);
  u8g2.drawStr(0, 30, buffer2);
  u8g2.sendBuffer();
  delay(1000);
}