/* WiFi Web Server A simple web server that a repeated counter Change the macro WIFI_AP, WIFI_PASSWORD and WIFI_AUTH accordingly. created 13 July 2010 by dlf (Metodo2 srl) modified 31 May 2012 by Tom Igoe modified 20 Aug 2014 by MediaTek Inc. */ #include #include #include #include #define outPin 5 #define WIFI_AP "your_ap_ssid" #define WIFI_PASSWORD "your_password" #define WIFI_AUTH LWIFI_WEP // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to your WiFi AP configuration LWiFiServer server(80); void setup() { LWiFi.begin(); Serial.begin(115200); // keep retrying until connected to AP Serial.println("Connecting to AP"); while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD))) { delay(1000); pinMode(3, INPUT); pinMode(outPin, OUTPUT); } printWifiStatus(); Serial.println("Start Server"); server.begin(); Serial.println("Server Started"); } void loop() { // put your main code here, to run repeatedly: delay(500); LWiFiClient client = server.available(); if (client) { Serial.println("new client"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { // we basically ignores client request, but wait for HTTP request end int c = client.read(); Serial.print((char)c); if (c == '\n' && currentLineIsBlank) { Serial.println("send response"); // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // the connection will be closed after completion of the response client.println("Refresh: 5"); // refresh the page automatically every 5 sec client.println(); client.println(""); client.println(""); // output the value of each analog input pin client.println("
"); client.println(""); client.println(); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } int light = analogRead(2); int temp = analogRead(3); int moisture = analogRead(4); if(light == 95-105){ client.print("light is: LOW"); client.println("
"); } if(light == 115-125){ client.print("light is: HIGH"); client.println("
"); } if(temp == 150-175){ client.print("temperature is: LOW"); client.println("
"); } if(temp == 200-225){ client.print("temperature is: HIGH"); client.println("
"); } if(moisture == 250-275){ client.print("moisture is: LOW"); client.println("
"); } if(moisture == 300-325){ client.print("moisture is: HIGH"); client.println("
"); } // give the web browser time to receive the data delay(500); // close the connection: Serial.println("close connection"); client.stop(); Serial.println("client disconnected"); } } void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(LWiFi.SSID()); // print your WiFi shield's IP address: IPAddress ip = LWiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); Serial.print("subnet mask: "); Serial.println(LWiFi.subnetMask()); Serial.print("gateway IP: "); Serial.println(LWiFi.gatewayIP()); // print the received signal strength: long rssi = LWiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); }