/* Display.ino 2013 Copyright (c) Seeed Technology Inc. All right reserved. Author:Loovee 2013-9-18 Grove - Serial LCD RGB Backlight demo. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include "rgb_lcd.h" #include #define LedTempMais 3 #define LedTempMenos 2 #define LedWifiConec 4 char ssid[] = "IoTRoadshow"; // the name of your network int status = WL_IDLE_STATUS; // the Wifi radio's status WiFiServer server(8088); int tempIn; float temperature; int B=3975; //B value of the thermistor float resistance; rgb_lcd lcd; int sensorPin = 0; // select the input pin for the potentiometer int sensorValue = 0; // variable to store the value coming from the sensor int outValue; const int MAX_PAGENAME_LEN = 128; // max characters in page name char buffer[MAX_PAGENAME_LEN+1]; // additional character for terminating null void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("Edison Temp Cont"); //Initialize serial and wait for port to open: Serial.begin(9600); while (!Serial); // wait for serial port to connect. Needed for Leonardo only // initialize digital pin 2 as an output. pinMode(LedTempMenos, OUTPUT); pinMode(LedTempMais, OUTPUT); pinMode(LedWifiConec, OUTPUT); // WiFi ------------------------ // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { lcd.print("WiFi shield not present"); //Serial.println("WiFi shield not present"); // don't continue: while(true); } String fv = WiFi.firmwareVersion(); if( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); // attempt to connect to Wifi network - open SSID: while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to open SSID: "); Serial.println(ssid); status = WiFi.begin(ssid); // wait 10 seconds for connection: delay(10000); } server.begin(); digitalWrite ( LedWifiConec, HIGH ); // ----------------------------- } void loop() { while(1) { int tempPost; // read the value from the sensor: sensorValue = analogRead(sensorPin); outValue = map(sensorValue, 0, 1023, 0, 70); lcd.setCursor(0,2); lcd.print ("Prg "); lcd.print (outValue); lcd.print (" "); // ---------- Temperatura tempIn = analogRead(1); resistance=(float)(1023-tempIn)*10000/tempIn; //get the resistance of the sensor; temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet ; lcd.setCursor(8,2); lcd.print ("Sen "); lcd.print ((int)temperature); lcd.print (" "); // Serial.print("Current temperature is "); // Serial.println(temperature); if ((int)temperature > outValue) { digitalWrite(LedTempMais, HIGH); digitalWrite(LedTempMenos, LOW); } else { digitalWrite(LedTempMais, LOW); digitalWrite(LedTempMenos, HIGH); } // cor backlight do LCD if ( (int)temperature > outValue + 1 ) lcd.setRGB(255, 0, 0); else if ( (int)temperature < outValue - 1 ) lcd.setRGB(0, 0, 255); else lcd.setRGB(0, 255, 0); //----------------------- WiFiClient client = server.available(); if(client) { Serial.println("new client"); lcd.setCursor(15,2); lcd.print ("c"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); // -------- Processa Post /* memset(buffer,0, sizeof(buffer)); // clear the buffer if(client.readBytesUntil('/', buffer,sizeof(buffer))) { if(strcmp(buffer,"POST ") == 0) { client.find("\n\r"); // skip to the body // find string starting with "pin", stop on first blank line // the POST parameters expected in the form pinDx=Y // where x is the pin number and Y is 0 for LOW and 1 for HIGH while(client.findUntil("tempPost", "\n\r")) { tempPost = client.parseInt(); // 0 or 1 Serial.println(tempPost); // processar temp Aqui } } } */ // ----------- Fim processa Post // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { // 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: 6"); // refresh the page automatically every 5 sec client.println(); client.println(""); client.println(""); client.println("INTEL Edison - Controle de Temperatura Ambiente"); client.println("
"); client.println("INTEL IoT Road Show 2015"); client.println("
"); client.println(" "); client.println("
"); client.println(" "); client.println("
"); client.println(""); client.println("Intel IoT "); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.print(""); client.println(""); client.println(""); client.println(""); client.print(""); client.println(""); client.println("
Temperatura Ambiente "); client.print((int)temperature); client.println("
Temperatura Programada"); client.print(outValue); client.println("
"); // client.print((int)temperature); client.println("
"); client.println("Valores Atualizados a cada 6 segundos"); /* client.println("

"); client.println(""); client.println("
"); client.println(""); client.println("

"); */ client.print("

"); // debug rx post client.print( tempPost ); 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; } } } // give the web browser time to receive the data delay(50); // close the connection: client.stop(); Serial.println("client disonnected"); lcd.setCursor(15,2); lcd.print ("_"); } // if client else { } // else if client delay (250); } } void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print your WiFi shield's IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); // print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); } void printCurrentNet() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print the MAC address of the router you're attached to: byte bssid[6]; WiFi.BSSID(bssid); Serial.print("BSSID: "); Serial.print(bssid[5],HEX); Serial.print(":"); Serial.print(bssid[4],HEX); Serial.print(":"); Serial.print(bssid[3],HEX); Serial.print(":"); Serial.print(bssid[2],HEX); Serial.print(":"); Serial.print(bssid[1],HEX); Serial.print(":"); Serial.println(bssid[0],HEX); // print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.println(rssi); // print the encryption type: byte encryption = WiFi.encryptionType(); Serial.print("Encryption Type:"); Serial.println(encryption,HEX); } void printWifiData() { // print your WiFi shield's IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); // LCD: // lcd.setCursor(0,2); // lcd.print ("IP"); // lcd.print(ip); // print your MAC address: byte mac[6]; WiFi.macAddress(mac); Serial.print("MAC address: "); Serial.print(mac[5],HEX); Serial.print(":"); Serial.print(mac[4],HEX); Serial.print(":"); Serial.print(mac[3],HEX); Serial.print(":"); Serial.print(mac[2],HEX); Serial.print(":"); Serial.print(mac[1],HEX); Serial.print(":"); Serial.println(mac[0],HEX); // print your subnet mask: IPAddress subnet = WiFi.subnetMask(); Serial.print("NetMask: "); Serial.println(subnet); // print your gateway address: IPAddress gateway = WiFi.gatewayIP(); Serial.print("Gateway: "); Serial.println(gateway); } /* memset(buffer,0, sizeof(buffer)); // clear the buffer if(client.readBytesUntil('/', buffer,sizeof(buffer))) { if(strcmp(buffer,"POST ") == 0) { client.find("\n\r"); // skip to the body // find string starting with "pin", stop on first blank line // the POST parameters expected in the form pinDx=Y // where x is the pin number and Y is 0 for LOW and 1 for HIGH while(client.findUntil("tempPost", "\n\r")) { int pin = client.parseInt(); // the pin number int tempPost = client.parseInt(); // 0 or 1 pinMode(pin, OUTPUT); Serial.println(tempPost); // processar temp Aqui } } } */