#include #include #include #include const char ssid[] = " "; const char password[] = " "; String COLOR1 = "red"; String COLOR2 = "blue"; float tpary[100]; float dpa[10]; int kp = 0; int dp; WebServer server(80); IPAddress ipadr; int n = 0; int bp = 0; unsigned char tmp2_adr = 0x48; i2clcd qlcd(0x3E, 3, 0x20); //具体的な処理を行うためのオブジェクトを作る float get_tmp102(unsigned char tmp0_adr) {//温度センサを読み取る関数 Wire.requestFrom(tmp0_adr, 2); while (Wire.available() < 2) { } int tmpin = Wire.read() * 16; tmpin = tmpin + (Wire.read() >> 4); return 0.0625 * tmpin; } void handleRoot() { handleRootmsg(COLOR2, COLOR2); } void handleon() { digitalWrite(5, HIGH); // GET /H turns the LED on handleRootmsg(COLOR1, COLOR1); } void handleoff() { digitalWrite(5, LOW); // GET /L turns the LED off handleRootmsg(COLOR2, COLOR2); } void handleRootmsg( String cr1, String cr2) { String temp = ""; char tempa[600]; int sec = millis() / 1000; int min = sec / 60; int hr = min / 60; float tvalue = get_tmp102(tmp2_adr); dp = kp - 1; for (int i = 0; i <= 9; i++) { if (dp == 0) { dp = 99; } dpa[i] = tpary[dp]; Serial.println(i); Serial.println(dpa[i]); Serial.println(tpary[dp]); } snprintf(tempa, 600, "\ \ \
\ Denshi Club ESP32 test\ \ \

Temperature from ESP32

\

Uptime: %2d:%2d:%2d:

\

Current Temperature: %8.2f

\

Temperature course:

\

(1 -- 5):%6.2f:%6.2f:%6.2f:%6.2f:%6.2f

\

(6 -- 10):%6.2f:%6.2f:%6.2f:%6.2f:%6.2f

\ \
\ ", hr, min % 60, sec % 60, tvalue, dpa[0], dpa[1], dpa[2], dpa[3], dpa[4], dpa[5], dpa[6], dpa[7], dpa[8], dpa[9] ); temp = tempa; temp += "
"; temp += "

Click here to turn "; temp += "the LED on pin 5 on.

"; temp += "

Click here to turn the LED on pin 5 off.

"; temp += "
"; temp += ""; temp += "
"; temp += ""; temp += "", server.send(200, "text/html", temp); } void handleNotFound() { String message = "File Not Found\n\n"; message += "URI: "; message += server.uri(); message += "\nMethod: "; message += (server.method() == HTTP_GET) ? "GET" : "POST"; message += "\nArguments: "; message += server.args(); message += "\n"; for (uint8_t i = 0; i < server.args(); i++) { message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; } server.send(404, "text/HTML", message); } void setup(void) { qlcd.init_lcd(); //LCDモジュールの初期化処理 qlcd.i2cprint("start:"); pinMode(5, OUTPUT); Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.println(""); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); ipadr = WiFi.localIP(); Serial.println(ipadr); qlcd.lcdcu_set(0, 1); qlcd.i2cprint(String(ipadr[0]) + "." + String(ipadr[1]) + "."); qlcd.i2cprint(String(ipadr[2]) + "." + String(ipadr[3])); server.on("/", handleRoot); server.on("/H", handleon); server.on("/L", handleoff); server.onNotFound(handleNotFound); server.begin(); Serial.println("HTTP server started"); } void loop(void) { server.handleClient(); if (0 == (millis() % 2000)) { float gettmpd = get_tmp102(tmp2_adr); ; qlcd.lcdcu_set(0, 0); // LCDモジュールのカーソルを先頭に n = n + 1; tpary[kp] = gettmpd; Serial.println(kp); Serial.println(tpary[kp]); kp = kp + 1; if (kp > 99) { kp = 0; } qlcd.i2cprint(String(n)); // カウンタの値をLCDへ表示 qlcd.i2cprint(":"); qlcd.i2cprint("temp2="); // 見出しをLCDへ表示 qlcd.i2cprint(String(gettmpd)); //測定温度を表示 } }