web server load-drive and reading sensors based on LPC1768

Dependencies:   DHT22 EthernetNetIf HTTPServer mbed

Files at this revision

API Documentation at this revision

Comitter:
douglasofranco
Date:
Mon Dec 07 14:06:24 2015 +0000
Commit message:
Web server load-drive and reading sensors based on LPC1768

Changed in this revision

Atuadores/Atuadores.cpp Show annotated file Show diff for this revision Revisions of this file
Atuadores/Atuadores.h Show annotated file Show diff for this revision Revisions of this file
DHT22.lib Show annotated file Show diff for this revision Revisions of this file
EthernetNetIf.lib Show annotated file Show diff for this revision Revisions of this file
HTTPServer.lib Show annotated file Show diff for this revision Revisions of this file
LCDPrint/Print.cpp Show annotated file Show diff for this revision Revisions of this file
LCDPrint/Print.h Show annotated file Show diff for this revision Revisions of this file
Leituras/Leitura.cpp Show annotated file Show diff for this revision Revisions of this file
Leituras/Leitura.h Show annotated file Show diff for this revision Revisions of this file
SensorHandler.cpp Show annotated file Show diff for this revision Revisions of this file
SensorHandler.h Show annotated file Show diff for this revision Revisions of this file
Temporizadores/Temporizadores.cpp Show annotated file Show diff for this revision Revisions of this file
Temporizadores/Temporizadores.h Show annotated file Show diff for this revision Revisions of this file
TextLCD.cpp Show annotated file Show diff for this revision Revisions of this file
TextLCD.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Atuadores/Atuadores.cpp	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,113 @@
+#include "Atuadores.h"
+#include "Leitura.h"
+#include "mbed.h"
+
+DigitalOut Carregador(p28);
+DigitalOut ArCond(p29);
+
+float saidaCarr;
+float saidaAr;
+
+int CarregadorB;
+int ArCondB;
+int EstadoCarr;
+int EstadoAr;
+int Trava2 = 0;
+int Trava3 = 0;  
+int TravaAuto1 = 0;
+int TravaAuto2 = 0;
+bool complemento = false;
+int x9 = 0;
+int x92 = 0;
+
+void Atuadores::AtuadorCarr()
+ {
+     saidaCarr = atof(TensCC);
+    if ((saidaCarr <=12.2) && (TravaAuto1 == 0)){
+         Carregador = 1;
+         TravaAuto1 = 1;
+                 
+     }
+    if (CarregadorB == 1 && Trava2 == 0){
+         if (Carregador == 0){ Carregador = 1; x9 = 1;}
+         else{ Carregador = 0; x9 = 2;}
+         Trava2 = 1;
+      
+         }
+   else if (CarregadorB == 0 && Trava2 == 1){
+         if (Carregador == 0){ Carregador = 1; x9 = 1;}
+         else { Carregador = 0; x9 = 2;}
+       //  if (saidaCarr >= 12.8){ complemento = true;}
+         Trava2 = 0;
+         }
+  EstadoCarr = Carregador;
+//  if (complemento == true){x9 = 0;}
+ }  
+ 
+void Atuadores::AtuadorAr()
+ {
+    saidaAr = szTemp;
+     if ((saidaAr >= 22) && (TravaAuto2 == 0)){
+    ArCond = 1;
+    TravaAuto2 = 1;
+       }
+   else if(ArCondB == 1 && Trava3 == 0){
+        if( ArCond == 0){ArCond = 1; x92 = 1;}
+        else { ArCond = 0; x92 = 2; }
+        Trava3 = 1;
+        TravaAuto2 = 1;
+        }
+   else if (ArCondB == 0 && Trava3 == 1 ){
+        if( ArCond == 0){ArCond = 1; x92 = 1;}
+        else {ArCond = 0; x92 = 2;}
+        Trava3 = 0;
+         TravaAuto2 = 1;
+        }
+    EstadoAr = ArCond;
+   // if((saidaAr >= 22) && (x92 == 1)) {x92 = 0;}
+ }       
+ 
+ 
+void Atuadores::Desliga() 
+{
+    if (Carregador == 1)
+    {
+        Carregador = 0;
+        CarregadorB = 0;
+        TravaAuto1 = 0;
+        Trava2 = 0;
+        x9 = 0;
+
+    }
+     if (ArCond == 1)
+     {
+         ArCond = 0;
+         ArCondB = 0;
+         TravaAuto2 = 0;
+         Trava3 = 0;
+         x92 = 0;
+     }
+}            
+                 
+void Atuadores::Religa() 
+{
+    if (Carregador == 0)
+    {
+        Carregador = 1;
+        CarregadorB = 0;
+        TravaAuto1 = 1;
+        Trava2 = 0;
+     // x9 = 0;
+
+    }
+     if (ArCond == 0)
+     {
+         ArCond = 1;
+         ArCondB = 0;
+         TravaAuto2 = 1;
+         Trava3 = 0;
+    //   x92 = 0;
+     }
+}            
+
+                
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Atuadores/Atuadores.h	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,26 @@
+#ifndef ATUADORES_H_
+#define ATUADORES_H_
+#include "mbed.h"
+#include "Leitura.h"
+
+using namespace std;
+
+extern    float saidaCarr;
+extern    float saidaAr;
+extern    int   EstadoAr;
+extern    int   EstadoCarr;
+extern    int x9;
+extern    int x92; 
+extern    int TravaAuto2;
+
+class Atuadores 
+{
+public:
+    void AtuadorCarr();
+    void AtuadorAr();
+    void Desliga();
+    void Religa();
+};
+
+    #endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DHT22.lib	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Julepalme/code/DHT22/#7fd3ff04ae95
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPServer.lib	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPServer/#d753966e4d97
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCDPrint/Print.cpp	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,95 @@
+#include "Print.h"
+#include "Leitura.h"
+#include "TextLCD.h"
+#include "Atuadores.h"
+//#include "ACS712.h"
+
+TextLCD lcd(p10, p9, p8, p7, p6, p5);
+
+void Print::imprimezero()
+{
+  lcd.cls();
+}
+
+
+void Print::imprimeTexto()
+{
+  lcd.locate(0,0);
+  lcd.printf ("SIST. MONITORAMENTO");
+  lcd.locate(0,1);
+  lcd.printf ("                    ");
+  lcd.locate(0,2);
+  lcd.printf ("                    ");
+  lcd.locate(0,3);
+  lcd.printf ("                    ");
+  }
+void Print::imprimeTemp()
+{
+        if (err == 0) {
+        lcd.locate(0,1);
+        lcd.printf ("                    ");
+        lcd.locate(0,2);
+        lcd.printf("Temperatura:"); 
+        lcd.printf("%d",szTemp);        
+        lcd.printf("\nHumidade:");  
+        lcd.locate(12,3);           
+        lcd.printf("%d",szUmid);
+        } else
+            lcd.printf("\nErr %i \n",err);
+        }      
+   // }
+void Print::imprimeCurr()
+{
+   //  lcd.cls();
+    lcd.locate(0,1);
+    lcd.printf("Corrente1: %s",Corrente);
+    lcd.printf(" A");
+    lcd.locate(0,2);
+    lcd.printf("Corrente2: %s",Corrente2);
+    lcd.printf(" A");
+    lcd.locate(0,3);
+    lcd.printf("Corrente3: %s",Corrente3);
+    lcd.printf(" A");
+  //  lcd.locate(0,1);
+  //  lcd.printf("Tensao:",Tensao);
+}
+
+void Print::imprimeCC()
+  {
+    lcd.locate(0,1);
+    lcd.printf("Baterias: %.2f",Tcc);
+    lcd.printf(" V");
+    lcd.locate(0,2);
+    if (AC == 1) {
+    lcd.printf("Rede Eletrica : ON"); }
+        else if (AC == 0){
+            lcd.printf("Rede Eletrica : OFF"); }
+    lcd.locate(0,3);
+    lcd.printf ("                    ");
+   }
+   
+void Print::imprimeAviso()
+{
+ // lcd.locate(0,0);
+ // lcd.printf ("SIST. MONITORAMENTO ");
+  lcd.locate(0,1);
+  lcd.printf ("Atuador ativado de  ");
+  lcd.locate(0,2);
+  lcd.printf ("forma manual e sera ");
+  lcd.locate(0,3);
+  lcd.printf ("desativado em 8:00h ");
+  lcd.locate(0,0);
+  }
+  
+  void Print::imprimeAviso2()
+{
+  //lcd.locate(0,0);
+  //lcd.printf ("SIST. MONITORAMENTO ");
+  lcd.locate(0,1);
+  lcd.printf ("Atuador desastivado ");
+  lcd.locate(0,2);
+  lcd.printf ("manualmente e sera  ");
+  lcd.locate(0,3);
+  lcd.printf ("reativado em 0:30h  ");
+  lcd.locate(0,0);
+  }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCDPrint/Print.h	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,24 @@
+#ifndef PRINT_H_
+#define PRINT_H_
+#include "mbed.h"
+#include "TextLCD.h"
+#include "Leitura.h"
+
+
+
+using namespace std;
+
+
+class Print
+{
+public:
+void imprimezero();
+void imprimeTexto();
+void imprimeTemp();
+void imprimeCurr();
+void imprimeCC();
+void imprimeAviso();
+void imprimeAviso2();
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Leituras/Leitura.cpp	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,164 @@
+#include "Leitura.h"
+#include "mbed.h"
+#include "DHT22.h"
+#include "TextLCD.h"
+#include "SensorHandler.h"
+
+AnalogIn   sensCur(p15);
+AnalogIn   sensCur2(p16);
+AnalogIn   sensCur3(p17);
+AnalogIn   sensCC (p18);
+DigitalIn   sensAC (p27);
+DHT22 sensor(p11);
+
+DigitalOut dout(LED1);
+DigitalOut myled(LED4);
+
+int AC;
+int err;
+int szTemp;
+int szUmid;
+char szTemp2[10];   //utilizado no sensorhandler
+char szUmid2[10];   //utilizado no sensorhandler
+char Corrente[50];
+char Corrente2[50];
+char Corrente3[50];
+//char Tensao[10];
+char TensCC[10];
+unsigned char k = 0;
+unsigned char h = 0;
+
+float sensorValue;
+float sensorValue_aux;
+float sensorValue2;
+float sensorValue_aux2;
+float sensorValue3;
+float sensorValue_aux3;
+float getValor;
+float Tcc;
+float TensAC;
+float media = 0;                                //para media movel 
+float filtro[10];                               //para media movel
+float media2 = 0;                                //para media movel 
+float filtro2[10];                               //para media movel
+
+float       voltsporUnidade = 0.0008056640625;  //  3.3/4096
+float       Vref = 3.3;
+float       Vref2 = 3.11;
+float       Offset = 2.3;                       //6.7;  //Tensão CC
+float       salto = 0.01559;                    //0.01563;
+float       DHT = 62;                           //Taxa de amostragem DHT
+int         chute=0;
+
+
+void Leituras::clima()
+{
+
+
+    sensor.sample() ;
+
+    szTemp = (sensor.getTemperature()/10.0);
+    szUmid = (sensor.getHumidity()/10.0);
+
+}
+void Leituras::corrente()
+{
+    sensorValue_aux = 0;
+    for (int a=0; a<10; a++) {
+        sensorValue_aux += sensCur.read();
+    }
+    sensorValue_aux = sensorValue_aux / 10;
+    sensorValue = ((((sensorValue_aux * Vref2) / voltsporUnidade)-1650)/DHT) - 12.56;
+    sprintf( Corrente, "%0.2f", sensorValue);
+}
+
+void Leituras::corrente2()
+{
+    sensorValue_aux2 = 0;
+
+    for (int b=0; b<10; b++) {
+        sensorValue_aux2 += sensCur2.read();
+    }
+    sensorValue_aux2 = (sensorValue_aux2 / 10);
+    sensorValue2 = ((((sensorValue_aux2 * Vref2) / voltsporUnidade)-1650)/DHT) - 12.36;
+    sprintf( Corrente2, "%0.2f", sensorValue2);
+
+}
+
+void Leituras::corrente3()
+{
+    sensorValue_aux3 = 0;
+
+    for (int c=0; c<10; c++) {
+        sensorValue_aux3 += sensCur3.read();
+    }
+    sensorValue_aux3 = sensorValue_aux3 / 10;
+    sensorValue3 = ((((sensorValue_aux3 * Vref2) / voltsporUnidade)-1650)/DHT) - 12.10;
+    sprintf( Corrente3, "%0.2f", sensorValue3);
+}
+
+void Leituras::TensaoCC()
+{   
+    Tcc = 0;
+    if (chute ==0){
+        Tcc= sensCC.read();
+        Tcc = ((Tcc * salto) + Offset);
+        chute =1;
+        }
+    
+//media movel
+   
+    unsigned char j;
+    filtro[k] = sensCC.read();
+    k++;
+    if(k==10) {
+        k=0;
+    }
+
+    for(j=0; j<10; j++) {
+        getValor += filtro[j];
+    }
+    getValor = getValor/10;
+    Tcc = ((getValor * 4094) - 2048);
+    Tcc = ((Tcc * salto) + Offset);
+    if (Tcc < 12.1) {
+        Tcc = Tcc + 0.18;
+    }
+    if (Tcc>= 13) {
+        Tcc = Tcc - 0.06;
+    }
+    if (Tcc < 11.7) {
+        Tcc = Tcc + 0.09;
+    }
+    sprintf(TensCC, "%2.2f", Tcc);
+
+
+}
+
+void Leituras::TensaoAC()
+{
+    float TAC = 0.0;
+    TensAC = 0;
+    unsigned char l;
+    
+    for (int w=0; w<30; w++) {
+        TAC += sensAC.read();
+    }
+        TAC = (TAC / 30);
+   
+    filtro2[h] = TAC;
+    h++;
+    if(h==10) {
+        h=0;
+    }
+
+    for(l=0; l<=10; l++) {
+        TensAC += filtro2[l];
+    }
+    
+  TensAC = TensAC * Vref;  
+ //   TensAC = (TAC / 100) * Vref;
+    if (TensAC != 33.0) {
+        AC = 1;
+    } else AC = 0 ;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Leituras/Leitura.h	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,40 @@
+#ifndef LEITURA_H_
+#define LEITURA_H_
+#include "mbed.h"
+#include "DHT22.h"
+
+using namespace std;
+extern    int AC;
+extern    int err;
+extern    int  szTemp;
+extern    int  szUmid;
+extern    char szTemp2[10];
+extern    char szUmid2[10];
+extern    char Corrente[50];
+extern    char Corrente2[50];
+extern    char Corrente3[50];
+extern    char Tensao[10];
+extern    char TensCC[10];
+extern    float sensorValue;
+extern    float sensorValue_aux;
+extern    float sensorValue2;
+extern    float sensorValue_aux2;
+extern    float sensorValue3;
+extern    float sensorValue_aux3;
+extern    float getValor;
+extern    float Tcc;
+extern    float TensAC;
+
+class Leituras
+{ 
+public:
+    void clima();
+    void corrente();
+    void corrente2();
+    void corrente3();
+    void TensaoCC();
+    void TensaoAC();
+  
+ };
+ 
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SensorHandler.cpp	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,165 @@
+#include "mbed.h"
+#include "SensorHandler.h"
+#include <dbg.h>
+#include "DHT22.h"
+#include "Leitura.h"
+#include "Atuadores.h"
+#define DELIMITER   ("&")
+
+extern bool g_bLed1;
+int estado;
+extern int EstadoCarr;
+extern int EstadoAr;
+
+
+SensorHandler::SensorHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket) : HTTPRequestHandler(rootPath, path, pTCPSocket)
+
+{
+    DBG("SensorHandler()\r\n");
+}
+
+SensorHandler::~SensorHandler()
+{
+    DBG("~SensorHandler()\r\n");
+}
+void SensorHandler::printString( const char* pszString )
+{
+    writeData( pszString, strlen(pszString) );
+}
+
+void SensorHandler::printHtml()
+{
+    respHeaders()["Connection"] = "close";
+
+    printString( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n" );
+    printString( "<html lang=\"ja\">\n" );
+    printString( "<head>\n" );
+    printString( "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" );
+    printString( "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\">\n" );
+    printString( "<title>Sistema de Monitoramento</title><br />\n" );
+    printString( "</head>\n" );
+    printString( "<body>\n" );
+    //printString("<img src=logo.png alt=Logo style=position:absolute;top:50px;right:10px; />");
+    printString("<center><img src=\"http://www.cbm.sc.gov.br/templates/kodadesign/images/topo_site_88anos.jpg\"></ center>");
+    printString( "<p style=font-size:40px;font-family:courier><b> Sistema de Monitoramento de Estaçãoes Repetidoras<b></p>");
+    
+    printString("<table width=\"100%\">");
+    printString("<tr>");
+    printString( "<td>Temperatura: " );
+    sprintf( szTemp2, "%4.1d", szTemp);
+    printString(szTemp2);
+    printString("°C");
+    printString("</td>");
+    printString("<td>Corrente ACS01:");
+    printString(Corrente);
+    printString("A </td>");
+    printString("<td>Tensão do Banco de Baterias:");
+    printString(TensCC);
+    printString("V</td>");
+    printString("</tr><tr>");
+    printString("<td>Umidade:");
+    sprintf( szUmid2, "%4.1d", szUmid);
+    printString(szUmid2);
+    printString("%</td>");
+    printString("<td>Corrente ACS02:");
+    printString(Corrente2);
+    printString("A</td>");
+    printString("<td>Ar Condicionado:");
+    if (EstadoAr == 1){printString("Ligado");}
+    if (EstadoAr == 0){printString("Desligado");}
+    printString("</td><tr>");
+    if (AC == 1) {printString("<td><label>Rede Elétrica:"); printString("<FONT COLOR=\" blue\"> Rede Eletrica Ligada</FONT><label></td>");}
+    if (AC == 0) {printString("<td><label>Rede Elétrica:"); printString("<FONT COLOR=\" red\"> Falha na Alimentação</FONT><label></td>");}
+    printString("<td>Corrente ACS03:");
+    printString(Corrente3);
+    printString("A</td>");
+    printString("<td>Carregador:");
+    if (EstadoCarr == 1){printString("Ligado");}
+    if (EstadoCarr == 0){printString("Desligado");}
+    printString("</td></tr>");
+    printString("<br><hr>\n");
+     
+    
+    printString("</table><br><br>");
+    
+    printString("<form method=\"post\" action=\"\">\n");
+    printString("<table width=\"100%\">");
+    printString("<tr>");
+    printString("<td><label><input type=\"radio\" name=\"led1\" value=\"1\""); if(g_bLed1 == false){ printString(" checked"); } printString(">Lampadas Desligadas</label><br></td>\n");
+    printString("<td rowspan=\"3\"><a href=\"http://10.193.240.157/main.cgi?next_file=video2.htm\" target=\"_blank\"><img src=\"http://10.193.240.157/img/video.mjpeg\" width=\"'342' height= '23'\"></a></td>");
+    printString("</tr><tr>");
+    printString("<td><label><input type=\"radio\" name=\"led2\" value=\"1\""); if(g_bLed1 == true){ printString(" checked"); } printString(">Lampadas Ligadas</label><br></td>\n");
+    printString("</tr><tr>");
+    if(g_bLed1 == false){ printString("<td><input type=\"submit\"style=\"font-weight:30px; color: blue\" value=\"Ligar Lampadas\" style=\"width: 200px; height: 80px\"></td>\n");}
+    if(g_bLed1 == true){ printString("<td><input type=\"submit\" style=\"font-weight:30px; color: red\" value=\"Desl. Lampadas\"style=\"width: 200px; height: 80px\"></td>\n");}
+    printString("</tr></table><br><br>");  
+    printString("</form>\n");
+    printString("</body>\n");
+    printString("</html>");
+}
+void SensorHandler::doGet()
+{
+    DBG("doGet()\n");
+    printHtml();
+ }
+// botoes acionadores copia: https://developer.mbed.org/users/star297/code/ESP8266-WEB-Mbed-Controller/file/f7febfa77784/main.cpp
+// https://developer.mbed.org/users/star297/code/ESP8266-WEB-Mbed-Controller/
+static void analyzePostData( char* pszLine, bool& rbLed1)
+{
+    rbLed1 = false;
+     char* pszToken = strtok(pszLine, DELIMITER);
+    while(pszToken)
+    {
+        if( 6 == strlen(pszToken)
+         && 0 == strncmp(pszToken, "led", 3) )
+        {   // led?=1
+            if(      '1' == pszToken[3] ){ rbLed1 = true; }
+            else if( '2' == pszToken[3] ){ rbLed1 = false; }
+             }
+          //   else{ rbLed1 = false;}
+             //else if  (    '1' != pszToken[3] ){ rbLed1 = false; }
+             
+        pszToken = strtok(NULL, DELIMITER);
+    }
+}
+void SensorHandler::doPost()
+{
+    DBG("doPost()\r\n");
+    int iCountData = dataLen(); //add posterior
+    if( 0 == iCountData )
+    { 
+    printHtml();       
+    return; 
+    }
+  char* pszData = (char*) malloc( sizeof(char) * (iCountData + 1) );
+  readData( pszData, iCountData );
+  pszData[iCountData] = '\0';
+    
+    DBG( pszData );
+    
+    bool bLed1;
+    analyzePostData( pszData, bLed1);
+    g_bLed1 = bLed1;
+    printHtml();
+}
+
+void SensorHandler::doHead()
+{
+    DBG("doHead()\r\n");
+}
+
+void SensorHandler::onReadable() //Data has been read
+{
+    DBG("onReadable()\r\n");
+}
+
+void SensorHandler::onWriteable() //Data has been written & buf is free
+{
+    DBG("onWriteable()\r\n");
+    close(); //Data written, we can close the connection
+}
+
+void SensorHandler::onClose() //Connection is closing
+{
+    DBG("onClose()\r\n");
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SensorHandler.h	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,29 @@
+#ifndef SENSOR_HANDLER_H
+#define SENSOR_HANDLER_H
+
+#include <HTTPRequestHandler.h>
+
+
+class SensorHandler : public HTTPRequestHandler
+{
+public:
+  SensorHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket);
+    
+  virtual ~SensorHandler();
+
+  static inline HTTPRequestHandler* inst(const char* rootPath, const char* path, TCPSocket* pTCPSocket) { return new SensorHandler( rootPath, path, pTCPSocket); } //if we ever could do static virtual functions, this would be one
+
+  virtual void doGet();
+  virtual void doPost();
+  virtual void doHead();
+  
+  virtual void onReadable(); //Data has been read
+  virtual void onWriteable(); //Data has been written & buf is free
+  virtual void onClose(); //Connection is closing
+  
+private:
+  void printString( const char* pszString );
+  void printHtml();
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Temporizadores/Temporizadores.cpp	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,11 @@
+#include "Temporizadores.h"
+#include "Leitura.h"
+#include "mbed.h"
+Leituras teste2;
+
+void Estouro::Sensores(void)
+{
+    teste2.clima();
+    
+    }
+    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Temporizadores/Temporizadores.h	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,13 @@
+#ifndef TEMPORIZADORES_H_
+#define TEMPORIZADORES_H_
+#include "mbed.h"
+
+
+class Estouro
+{ 
+public:
+//  void Botoes();
+  void Sensores();
+};
+ 
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.cpp	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,159 @@
+/* mbed TextLCD Library, for a 4-bit LCD based on HD44780
+ * Copyright (c) 2007-2010, sford, http://mbed.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "TextLCD.h"
+#include "mbed.h"
+
+TextLCD::TextLCD(PinName rs, PinName e, PinName d4, PinName d5,
+                 PinName d6, PinName d7, LCDType type) : _rs(rs),
+        _e(e), _d(d4, d5, d6, d7),
+        _type(type) {
+
+    _e  = 1;
+    _rs = 0;            // command mode
+
+    wait(0.015);        // Wait 15ms to ensure powered up
+
+    // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
+    for (int i=0; i<3; i++) {
+        writeByte(0x3);
+        wait(0.00164);  // this command takes 1.64ms, so wait for it
+    }
+    writeByte(0x2);     // 4-bit mode
+    wait(0.000040f);    // most instructions take 40us
+
+    writeCommand(0x28); // Function set 001 BW N F - -
+    writeCommand(0x0C);
+    writeCommand(0x6);  // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
+    cls();
+}
+
+void TextLCD::character(int column, int row, int c) {
+    int a = address(column, row);
+    writeCommand(a);
+    writeData(c);
+}
+
+void TextLCD::cls() {
+    writeCommand(0x01); // cls, and set cursor to 0
+    wait(0.00164f);     // This command takes 1.64 ms
+    locate(0, 0);
+}
+
+void TextLCD::locate(int column, int row) {
+    _column = column;
+    _row = row;
+}
+
+int TextLCD::_putc(int value) {
+    if (value == '\n') {
+        _column = 0;
+        _row++;
+        if (_row >= rows()) {
+            _row = 0;
+        }
+    } else {
+        character(_column, _row, value);
+        _column++;
+        if (_column >= columns()) {
+            _column = 0;
+            _row++;
+            if (_row >= rows()) {
+                _row = 0;
+            }
+        }
+    }
+    return value;
+}
+
+int TextLCD::_getc() {
+    return -1;
+}
+
+void TextLCD::writeByte(int value) {
+    _d = value >> 4;
+    wait(0.000040f); // most instructions take 40us
+    _e = 0;
+    wait(0.000040f);
+    _e = 1;
+    _d = value >> 0;
+    wait(0.000040f);
+    _e = 0;
+    wait(0.000040f);  // most instructions take 40us
+    _e = 1;
+}
+
+void TextLCD::writeCommand(int command) {
+    _rs = 0;
+    writeByte(command);
+}
+
+void TextLCD::writeData(int data) {
+    _rs = 1;
+    writeByte(data);
+}
+
+int TextLCD::address(int column, int row) {
+    switch (_type) {
+        case LCD20x4:
+            switch (row) {
+                case 0:
+                    return 0x80 + column;
+                case 1:
+                    return 0xc0 + column;
+                case 2:
+                    return 0x94 + column;
+                case 3:
+                    return 0xd4 + column;
+            }
+        case LCD16x2B:
+            return 0x80 + (row * 40) + column;
+        case LCD16x2:
+        case LCD20x2:
+        default:
+            return 0x80 + (row * 0x40) + column;
+    }
+}
+
+int TextLCD::columns() {
+    switch (_type) {
+        case LCD20x4:
+        case LCD20x2:
+            return 20;
+        case LCD16x2:
+        case LCD16x2B:
+        default:
+            return 16;
+    }
+}
+
+int TextLCD::rows() {
+    switch (_type) {
+        case LCD20x4:
+            return 4;
+        case LCD16x2:
+        case LCD16x2B:
+        case LCD20x2:
+        default:
+            return 2;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.h	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,111 @@
+/* mbed TextLCD Library, for a 4-bit LCD based on HD44780
+ * Copyright (c) 2007-2010, sford, http://mbed.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MBED_TEXTLCD_H
+#define MBED_TEXTLCD_H
+
+#include "mbed.h"
+
+/**  A TextLCD interface for driving 4-bit HD44780-based LCDs
+ *
+ * Currently supports 16x2, 20x2 and 20x4 panels
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "TextLCD.h"
+ * 
+ * TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d4-d7
+ * 
+ * int main() {
+ *     lcd.printf("Hello World!\n");
+ * }
+ * @endcode
+ */
+class TextLCD : public Stream {
+public:
+
+    /** LCD panel format */
+    enum LCDType {
+        LCD16x2     /**< 16x2 LCD panel (default) */
+        , LCD16x2B  /**< 16x2 LCD panel alternate addressing */
+        , LCD20x2   /**< 20x2 LCD panel */
+        , LCD20x4   /**< 20x4 LCD panel */
+    };
+
+    /** Create a TextLCD interface
+     *
+     * @param rs    Instruction/data control line
+     * @param e     Enable line (clock)
+     * @param d4-d7 Data lines for using as a 4-bit interface
+     * @param type  Sets the panel size/addressing mode (default = LCD16x2)
+     */
+    TextLCD(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD20x4);
+
+#if DOXYGEN_ONLY
+    /** Write a character to the LCD
+     *
+     * @param c The character to write to the display
+     */
+    int putc(int c);
+
+    /** Write a formated string to the LCD
+     *
+     * @param format A printf-style format string, followed by the
+     *               variables to use in formating the string.
+     */
+    int printf(const char* format, ...);
+#endif
+
+    /** Locate to a screen column and row
+     *
+     * @param column  The horizontal position from the left, indexed from 0
+     * @param row     The vertical position from the top, indexed from 0
+     */
+    void locate(int column, int row);
+
+    /** Clear the screen and locate to 0,0 */
+    void cls();
+
+    int rows();
+    int columns();
+
+protected:
+
+    // Stream implementation functions
+    virtual int _putc(int value);
+    virtual int _getc();
+
+    int address(int column, int row);
+    void character(int column, int row, int c);
+    void writeByte(int value);
+    void writeCommand(int command);
+    void writeData(int data);
+
+    DigitalOut _rs, _e;
+    BusOut _d;
+    LCDType _type;
+
+    int _column;
+    int _row;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,315 @@
+/* SISTEMA DE MONITORAMENTO REMOTO para LPC1768.
+ *Este código foi desenvolvido como parte de um projeto de Especialização, e utiliza varias bibliotecas
+ *que estão disponiveis em https://developer.mbed.org/code/.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "mbed.h"
+#include "SensorHandler.h"
+#include "EthernetNetIf.h"
+#include "HTTPServer.h"
+#include "Leitura.h"
+#include "Print.h"
+#include "TextLCD.h"
+#include "Atuadores.h"
+//#include "Temporizadores.h"
+
+Ticker to1;
+Ticker to2;
+Ticker to3;
+Ticker Serie;
+Ticker Curr;
+Timer timer3;
+Timer timer4;
+Timer timer5;
+Timer debounce;
+
+DigitalOut led1(LED3);  // for alive check
+DigitalOut Lampadas(p30);
+
+InterruptIn Ilumin(p21);
+InterruptIn ArC(p22);
+InterruptIn Carreg(p23);
+InterruptIn Menu(p24);
+
+EthernetNetIf ethif( IpAddr(10,193,240,158), // IP
+                     IpAddr(255,255,255,248), // Subnet mask
+                     IpAddr(10,193,240,153), //Gateway
+                     IpAddr(10,193,4,3) ); // DNS
+
+/*
+EthernetNetIf ethif( IpAddr(192,168,0,18), // IP
+                     IpAddr(255,255,255,0), // Subnet mask
+                     IpAddr(192,168,0,1),   // Gateway
+                     IpAddr(192,168,0,1) ); // DNS
+*/
+//EthernetNetIf eth;
+HTTPServer server;
+Leituras sensores;
+Leituras Baterias;
+Leituras EnerEletrica;
+Leituras Correntes1;
+Leituras Correntes2;
+Leituras Correntes3;
+Print imprime;
+Print impri;
+Print Text;
+Print impriCC;
+Print Aviso1;
+Print Aviso2;
+Print clear;
+//Estouro teste;
+Atuadores AR;
+Atuadores CARR;
+Atuadores desligar;
+Atuadores religar;
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+bool g_bLed1    = false;
+bool g_bHighLow = true;
+bool Valor_RetornadoWeb = 0;
+int  Bot_Lampada;
+int  Bot_Menu;
+int Item = 0;
+int TravaAviso = 0;
+int TravaAviso2 = 0;
+int T =0;
+int trava =0;
+extern int CarregadorB;
+extern int ArCondB;
+
+
+void sensordht(void)
+{
+    sensores.clima();
+    if ((TravaAviso == 0) && (TravaAviso2 == 0)) {
+        Text.imprimeTexto();
+        imprime.imprimeTemp();
+    }
+}
+
+void sensorbat(void)
+{
+    Baterias.TensaoCC();
+}
+
+void sensorac(void)
+{
+    EnerEletrica.TensaoAC();
+}
+
+void sensorCorrrente (void)
+{
+    Correntes1.corrente();
+    Correntes2.corrente2();
+    Correntes3.corrente3();
+}
+
+void esperaB (void)
+{
+    wait_ms(200);
+}
+
+void Bmenu (void)
+{
+    if(debounce.read_ms()>300) {    // only allow toggle after 20 ms
+        if (Bot_Menu !=1) {
+            Item = Item + 1;
+            if(Item == 1) {
+                Text.imprimeTexto();
+                imprime.imprimeTemp();
+            } else if(Item == 2) {
+                Text.imprimeTexto();
+                impri.imprimeCurr();
+            } else if(Item == 3) {
+                Text.imprimeTexto();
+                impriCC.imprimeCC();
+                Item = 0;
+            }
+        }
+        debounce.reset();          // restart timer after toggle
+    }
+}
+
+void Blamapada (void)
+{
+    if(debounce.read_ms()>300) {    // only allow toggle after 20 ms
+        if (Lampadas == 0) {
+            Lampadas = 1;
+        } else
+            Lampadas = 0;
+    }
+    debounce.reset();          // restart timer after toggle
+}
+
+void Bar (void)
+{
+    if(debounce.read_ms()>300) {    // only allow toggle after 20 ms
+        if (ArCondB == 0) {
+            ArCondB = 1;
+        } else
+            ArCondB = 0;
+    }
+    debounce.reset();          // restart timer after toggle
+}
+
+void Bcarr (void)
+{
+    if(debounce.read_ms()>300) {    // only allow toggle after 20 ms
+        if (CarregadorB == 0) {
+            CarregadorB = 1;
+        } else
+            CarregadorB = 0;
+    }
+    debounce.reset();          // restart timer after toggle
+}
+void ImpSerial (void)
+{
+    pc.printf("\r valor X9 = %d\n",x9);
+    pc.printf("\r valor X92 = %d\n",x92);
+    pc.printf("\r valor retornado de gb_Led1= %d\n",g_bLed1);
+    pc.printf("\r valor 2 retornado = %d\n",Valor_RetornadoWeb);
+    pc.printf("\r bateria = %f\n",Tcc);
+    pc.printf("\r getValor = %2.5f\n",getValor);
+    pc.printf("\r Bot Carr = %d\n",CarregadorB);
+    pc.printf("\r Bot Ar = %d\n",ArCondB);
+    pc.printf("\r TravaAviso = %d\n",TravaAviso);
+    pc.printf("\r TravaAviso = %d\n",TravaAviso2);
+//    pc.printf("\r T = %d\n",T);
+    pc.printf("\r Timer 3= %f sec\n", timer3.read());
+    pc.printf("\r Timer 4= %f sec\n", timer4.read());
+    pc.printf("\r Timer 5= %f sec\n", timer5.read());
+//    pc.printf("\r corrente 3= %f\n ",sensorValue_aux3);
+//    pc.printf("\r corrente 3= %s\n\n",Corrente3);
+//    pc.printf("\r TEnsao AC= %f\n\n", TensAC);
+ //   pc.printf("\r Estado da Lampada = %d\n\n", Lampadas);
+    pc.printf("\r Estado da trava = %d\n\n", trava);
+  
+  }
+int main()
+{
+    
+    timer3.start();
+    //  timer4.start();
+    Ilumin.mode(PullUp);           //Pull up porta do botão lampada
+    Menu.mode(PullUp);             //Pull up porta do botão menu
+    ArC.mode(PullUp);              //Pull up porta do botão Ar
+    Carreg.mode(PullUp);           //Pull up porta do botão Garreg
+    to1.attach(&sensordht, 19.3);    //Temporizador de leitura do DHT22
+    to2.attach(&sensorbat, 0.7);    //Temporizador de leitura das Baterias
+    to3.attach(&sensorac,  5.9);
+    Curr.attach(&sensorCorrrente, 1.2);
+    Serie.attach(&ImpSerial, 4.0);
+    debounce.start();
+
+    Menu.fall(&Bmenu);              //aguarda a borda de decida para gerar a interrupção do menu
+    Ilumin.fall(&Blamapada);        //aguarda a borda de decida para gerar a interrupção da lamapada
+    ArC.fall(&Bar);                 //aguarda a borda de decida para gerar a interrupção do Ar
+    Carreg.fall(&Bcarr);            //aguarda a borda de decida para gerar a interrupção do Carregador
+
+    Menu.rise(&esperaB);            //aguarda a borda de Subida para gerar a interrupção de espera
+    Ilumin.rise(&esperaB);
+    ArC.rise(&esperaB);
+    Carreg.rise(&esperaB);
+
+    // EthernetNetIf setup
+    if(ethif.setup()) {
+        return 1;
+    }
+    Text.imprimeTexto();
+
+    // Set web root path handler
+    server.addHandler<SensorHandler>("/");
+    // Set http port
+    server.bind(80);
+    Timer tmLed;
+    Timer tm;
+    tmLed.start();
+    tm.start();
+
+    while (1) {
+
+        if ((( x9==1 ) || (x92 == 1)) && (TravaAviso == 0)) {
+            Aviso1.imprimeAviso();
+            TravaAviso = 1;
+            timer4.reset();
+            timer4.start();
+            timer5.reset();
+            timer5.start();
+        }
+
+        if((( x9==2 ) || (x92 == 2)) && (TravaAviso2 == 0)) {
+            Aviso2.imprimeAviso2();
+            TravaAviso2 = 1;
+            timer4.reset();
+            timer4.start();
+            timer5.reset();
+            timer5.start();
+        }
+
+        if ( (timer3.read()) > 1800) {  //tempo em segundos = 30minutos. 1800 *tempo para desligar as cargas
+            T ++;
+            timer3.reset();
+            if(T==16) {
+                desligar.Desliga();
+                TravaAviso=0;
+                TravaAviso2=0;
+                T = 0;
+            }
+        }
+        if ( (timer4.read()) > 30) {  //tempo em segundos = 1minuto. *tempo para apagar aviso
+            TravaAviso2= 0;
+            TravaAviso= 0 ;
+            x9=0;
+            x92=0;
+            timer4.stop();
+        }
+        if ( (timer5.read()) > 1800) {   //tempo em segundos = 30minutos. *tempo para religar as garcas
+            religar.Religa();
+            timer5.stop();
+        }
+
+        AR.AtuadorAr();
+        CARR.AtuadorCarr();
+
+        Net::poll();
+        if( 1.0 < tm.read() ) {
+            led1 = !led1;   // high->low, low->high
+            tm.start();
+        }
+
+        if( 1.0 < tmLed.read() ) {
+            Valor_RetornadoWeb = g_bLed1;
+
+            if(Valor_RetornadoWeb == true && trava == 0) {
+                Lampadas = 1;
+                trava = 1;
+            }
+            if(Valor_RetornadoWeb == false && trava == 1) {
+                Lampadas = 0;
+                trava = 0;
+            }
+            wait_ms(50);
+            tmLed.start();
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Dec 07 14:06:24 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ed12d17f06
\ No newline at end of file