#include <Wire.h>
#include <AHT10.h>
#include <ESP8266WebServer.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
AHT10Class AHT10;
ESP8266WebServer server(80);
float temperature, humidity, pressure, altitude;
/* Введите SSID и пароль от вашей сети */
const char* ssid = "HUAWEI-3F84"; // SSID
const char* password = "01942527"; // пароль
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Wire.begin();
if(AHT10.begin(eAHT10Address_Low))
Serial.println("Init AHT10 Sucess.");
else
Serial.println("Init AHT10 Failure.");
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("//Thinary Eletronic AHT10 Module//");
Serial.println(String("")+"Humidity(%RH):\t\t"+AHT10.GetHumidity()+"%");
Serial.println(String("")+"Temperature(℃):\t"+AHT10.GetTemperature()+"℃");
Serial.println(String("")+"Dewpoint(℃):\t\t"+AHT10.GetDewPoint()+"℃");
delay(500);
}
void setup()
{
Serial.begin(9400);
delay(100);
ath.begin(0x77);
bme.begin(0x76);
if(AHT10.begin(eAHT10Address_Low))
Serial.println("Connecting to ");
Serial.println(ssid);
// подключиться к вашей локальной wi-fi сети
WiFi.begin(ssid, password);
// проверить, выполнено ли подключение wi-fi сети
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.print(".");
}
Serial.println("...");
Serial.println("WiFi connected...!");
Serial.print("Got IP: "); Serial.println(WiFi.localIP());
server.on("/", handle_OnConnect);
server.onNotFound(handle_NotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop()
{
server.handleClient();
}
void handle_OnConnect()
{
temperature = bme.readTemperature();
pressure = bme.readPressure() / 100.0F;
altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
humidity = ath.readHumidity() / 100.0
server.send(200, "text/html", SendHTML(temperature,humidity,pressure,altitude));
}
void handle_NotFound()
{
server.send(404, "text/plain", "Not found");
}
String SendHTML(float temperature,float humidity,float pressure,float altitude)
{
String ptr = "<!DOCTYPE html> <html>\n";
ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
ptr +="<title>ESP8266 Weather Station</title>\n";
ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;}\n";
ptr +="p {font-size: 24px;color: #444444;margin-bottom: 10px;}\n";
ptr +="</style>\n";
ptr +="</head>\n";
ptr +="<body>\n";
ptr +="<div id=\"webpage\">\n";
ptr +="<h1>ESP8266 Weather Station</h1>\n";
ptr +=temperature;
ptr +="<p>Temperature: ";
ptr +="°C</p>";
ptr +="<p>Pressure: ";
ptr +=pressure;
ptr +="hPa</p>";
ptr +="</div>\n";
ptr +="</body>\n";
ptr +="</html>\n";
ptr +="<p>:humidity";
ptr +=humidity;
return ptr;
}
">