//Test4-WiFiServer_DHT11 #include "WiFiS3.h" #include #define DHTPIN 11 // Define the pin used to connect the sensor #define DHTTYPE DHT11 // Define the sensor type DHT dht(DHTPIN, DHTTYPE); // Create a DHT object char ssid[] = "106F3FD9B204"; char pass[] = "sxg9vv3dxawf8"; WiFiServer server(23); void setup() { // put your setup code here, to run once: pinMode( 2, INPUT ); pinMode( 3, OUTPUT ); Serial.begin(9600); delay(1000); Serial.println("Test4-WiFiServer_DHT"); dht.begin(); // Initialize the DHT sensor if(WiFi.status() == WL_NO_MODULE){ Serial.println("WiFi 接続先がありません"); while(1); } Serial.print("接続中..."); while(1){ if(WiFi.begin(ssid, pass) == WL_CONNECTED){ Serial.println("接続完了"); break; } Serial.print("."); delay(1000); } Serial.print("IP アドレス;"); Serial.println( WiFi.localIP().toString()); while( digitalRead( 2)==0 ) server.begin(); } void loop() { // put your main code here, to run repeatedly: WiFiClient client = server.available(); if(client){ Serial.println("new client"); client.println("new client"); while (client.connected()) { // loop while the client's connected if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // read a byte, then Serial.write(c); // print it out to the serial monitor if ( c=='1') { digitalWrite( 3, HIGH ); Serial.println("LED_ON"); client.println("LED_ON"); // Reading temperature or humidity takes about 250 milliseconds! float h = dht.readHumidity();//湿度を読み取る // Read temperature as Celsius (the default) float t = dht.readTemperature();//温度を摂氏で読み取る // Read temperature as Fahrenheit (isFahrenheit = true) float f = dht.readTemperature(true);//温度を華氏で読み取る // Compute heat index in Fahrenheit (the default) float hif = dht.computeHeatIndex(f, h);//体感温度を摂氏で読み取る // Compute heat index in Celsius (isFahreheit = false) float hic = dht.computeHeatIndex(t, h, false);//体感温度を華氏で読み取る // Print the humidity, temperature, and heat index values to the serial monitor Serial.print(F("Humidity: ")); Serial.print(h); Serial.print(F("% Temperature: ")); Serial.print(t); Serial.print(F("°C ")); Serial.print(f); Serial.print(F("°F Heat index: ")); Serial.print(hic); Serial.print(F("°C ")); Serial.print(hif); Serial.println(F("°F")); //client.print(F("Humidity: ")); client.print(F("湿度: ")); client.print(h); //client.print(F("% Temperature: ")); client.print(F("% 温度: ")); client.print(t); client.print(F("°C ")); client.print(f); //client.print(F("°F Heat index: ")); client.print(F("°F 体感温度: ")); client.print(hic); client.print(F("°C ")); client.print(hif); client.println(F("°F")); }else if ( c=='0') { digitalWrite( 3, LOW ); Serial.println("LED_OFF"); client.println("LED_OFF"); } } } // close the connection: client.stop(); Serial.println("client disconnected"); } }