You are on page 1of 4

// EtherShield webserver // Reads the 4 analogue inputs and prints them up to the webpage #include "EtherShield.h" #include <stdlib.

h> #include <string.h> #include <LiquidCrystal.h> LiquidCrystal lcd(14, 15, 16, 18,19, 20, 21); // please modify the following two lines. mac and ip have to be unique // in your local area network. You can not have the same numbers in // two devices: static uint8_t mymac[6] = { 0x54,0x55,0x58,0x10,0x00,0x23}; static uint8_t myip[4] = { 192,168,1,6}; #define MYWWWPORT 80 #define BUFFER_SIZE 550 static uint8_t buf[BUFFER_SIZE+1]; char numstr[6]; // The ethernet shield EtherShield es=EtherShield(); uint16_t http200ok(void) { return(es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"))); } // prepare the webpage by writing the data to the tcp send buffer uint16_t print_webpage(uint8_t *buf) { uint16_t plen; plen=http200ok(); plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<html><head><title>Dmandas ENC28J60 Ethernet Shield V1.0</title></head><body>")); // plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<center><h1>Welcome to Dmandas ENC28J60 Ethernet Shield V1.0</h1>")); plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<hr><br><h2><font color=\"green\">-- Welcome Dorel Mandas -- ")); plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<hr><br><h2><font color=\"black\">-- Monitoring Web server -- ")); // plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<br> Control digital outputs"));

plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<br> Read analog inputs here : ")); // Read the 6 analogue inputs in turn, convert the ADC result to ASCII and put into numstr // Then copy from RAM, the numstr and put into the tcp send buffer to send to the web page plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<br> Tensiune = ")); itoa(analogRead(4),numstr,10); // convert integer to string plen=es.ES_fill_tcp_data(buf,plen,numstr); plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<br> Temperatura = ")); itoa(analogRead(7),numstr,20); // convert integer to string plen=es.ES_fill_tcp_data(buf,plen,numstr); plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<br> Frecventa = ")); itoa(analogRead(5),numstr,10); // convert integer to string plen=es.ES_fill_tcp_data(buf,plen,numstr); plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<br> Curent = ")); itoa(analogRead(6),numstr,10); // convert integer to string plen=es.ES_fill_tcp_data(buf,plen,numstr);

plen=es.ES_fill_tcp_data_p(buf,plen,PSTR(" <br> <a href=.>[refresh]</a> ")); // add a Refresh button // plen=es.ES_fill_tcp_data(buf,plen,PSTR("<br> Read digital analog inputs here ")); plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<br></font></h2>") ); plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</center><hr>")); plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("V1.0 <a href=\"http://www.Dmandas.ro </a>")); plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</body></html>")); return(plen); } void setup(){ Serial.begin(9600); lcd.begin(16, 2); lcd.clear(); // Initialise SPI interface es.ES_enc28j60SpiInit(); // initialize enc28j60 es.ES_enc28j60Init(mymac); // init the ethernet/ip layer: es.ES_init_ip_arp_udp_tcp(mymac,myip, MYWWWPORT); }

void loop(){ uint16_t plen, dat_p; while(1) { // read packet, handle ping and wait for a tcp packet: dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf)); /* dat_p will be unequal to zero if there is a valid * http get */ if(dat_p==0){ // no http request continue; } // tcp port 80 begin if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){ // head, post and other methods: dat_p=http200ok(); dat_p=es.ES_fill_tcp_data_p(buf,dat_p,PSTR("<h1>200 OK</h1>")); goto SENDTCP; } // just one web page in the "root directory" of the web server if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0){ dat_p=print_webpage(buf); goto SENDTCP; } else{ dat_p=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>")); goto SENDTCP; } SENDTCP: es.ES_www_server_reply(buf,dat_p); // send web page data // tcp port 80 end lcd.setCursor(0, 1); float temp; int tempPin = 7; temp = analogRead(tempPin); temp = (temp * 0.48828125)+ 3.4; lcd.print("T="); lcd.print(temp); delay(500); Serial.print(temp), Serial.println(" C"); float val; int valPin = 4; val = analogRead(valPin); val =( val * 0.48828125)*5 +10 ; val=val+20; lcd.print(" "); lcd.print("U="); lcd.print(val); delay(500);

Serial.print(val),Serial.println(" V"); lcd.setCursor(0, 0); valPin = 6; val = analogRead(valPin); val = val * 0.4/10; delay(500); lcd.print("I="); lcd.print(val); Serial.print(val),Serial.println(" A"); valPin = 5; val =analogRead(valPin); val =( val * 0.48828125) ; val = val+6 ; lcd.print(" "); lcd.print("F="); lcd.print(val); delay(500); Serial.print(val),Serial.println(" Hz"); } }

You might also like