Ea se cupleaza direct pe placa mea compatibila Arduino Uno:
Dupa cum se observa, aceasta placa este o clona (reproducere) a placii de retea oficiale Arduino (Arduino Ethernet Shield).
La Arduino pe site se gaseste un articol numit Ethernet library in care se face o prezentare a placii si a comenzilor uzuale, de asemenea, aflam rapid ca pini digitali 4, 10, 11, 12 si 13 sunt folositi pentru comunicatie intre Arduino si placa de retea, respectiv inscriptorul de memorii micro SS:
Am incarcat in Arduino un sketch din exemplele Ethernet numit WebServer, fara a modifica nimic in el (se gaseste prezentare si in articolul http://arduino.cc/en/Tutorial/WebServer):
acesta citeste valorile intrarilor analogice AN0..AN5 si le afiseaza pe o pagina, care adresa 192.168.1.177.
Am conectat cablul de retea la placa mea si imediat s-au aprins o multime de LED-uri:
Intrarile analogice sunt in aer, asa ca rezultatul este:
Avand senzorul DHT11 care indica temperatura si umiditatea (vezi articolul Ministatie meteo cu senzorul DHT11 si.. Arduino), l-am conectat si pe el:
si am modificat sketch-ul din exemplu, punadu-i si partea de senzor DHT11, rezultandu-mi:
/*
Web Server
A simple web server that shows the temperature & humidity from
a DHT11 sensor using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Data from DHT11 is at A2 (analog input 2)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
adapted 24 may 2013
by Nicu FLORICA (niq_ro) - http://www.tehnic.go.ro & http://nicuflorica.blogspot.com
*/
#include <DHT.h>
#define DHTPIN A2 // what pin we're connected the DHT output
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
dht.begin();
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
int h = dht.readHumidity();
int t = dht.readTemperature();
// listen for incoming clients
EthernetClient 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()) {
char c = client.read();
Serial.write(c);
// 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("Connnection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// add a meta refresh tag, so the browser pulls again every 5 seconds:
client.println("<meta http-equiv=\"refresh\" content=\"5\">");
// output the value of temperature and humuidity from DHT
client.print("Senzorul DHT11 al lui Nicu arata:");
client.println("<br />");
client.print("temperatura=");
client.print(t);
client.print("gr.C");
client.println("<br />");
client.print("umiditate=");
client.print(h);
client.print("%");
client.println("<br />");
client.println("</html>");
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(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
Rezultatul este:
/*
Web Server
A simple web server that shows the temperature & humidity from
a DHT11 sensor using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Data from DHT11 is at A2 (analog input 2)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
adapted 24 may 2013
by Nicu FLORICA (niq_ro) - http://www.tehnic.go.ro
niq_ro's version is 1m1
*/
#include <DHT.h>
#define DHTPIN A2 // what pin we're connected the DHT output
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
dht.begin();
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
int h = dht.readHumidity();
int t = dht.readTemperature();
// listen for incoming clients
EthernetClient 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()) {
char c = client.read();
Serial.write(c);
// 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("Connnection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// add a meta refresh tag, so the browser pulls again every 5 seconds:
client.println("<meta http-equiv=\"refresh\" content=\"5\">");
// output the value of temperature and humuidity from DHT
client.print("www.tehnic.go.ro & nicuflorica.blogspot.com");
client.println("<br />");
client.println("<br />");
client.print("Senzorul DHT11 al lui Nicu arata:");
client.println("<br />");
client.print("temperatura=");
client.print(t);
client.print("<sup>0</sup>");
client.print("C");
client.println("<br />");
client.print("umiditate=");
client.print(h);
client.print("%");
client.println("<br />");
client.println("</html>");
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(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
25.mai.2013
Am refacut testele in alta parte, unde este o retea de casa cu un router Edimax, si a trebuit sa schimb adresa paginii, de la 192.168.1.177 la 192.168.2.177, deoarece asa era configurata reteaua:
Modificarile sunt minine in sketch, doar schimband linia
IPAddress ip(192,168,1, 177);
in
IPAddress ip(192,168,2, 177);
Am realizat un mic filmulet cu functionarea, numit DHT11 with Ethernet shield and Arduino (1).
Am modificat sketch-ul, pentru a avea o alta prezentare:
apoi
/*
Web Server
A simple web server that shows the temperature & humidity from
a DHT11 sensor using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Data from DHT11 is at A2 (analog input 2)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
adapted 25 may 2013
by Nicu FLORICA (niq_ro) - http://www.tehnic.go.ro
http://nicuflorica.blogspot.ro
niq_ro's version is 1m2
*/
#include <DHT.h>
#define DHTPIN A2 // what pin we're connected the DHT output
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
dht.begin();
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
int h = dht.readHumidity();
int t = dht.readTemperature();
// listen for incoming clients
EthernetClient 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()) {
char c = client.read();
Serial.write(c);
// 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("Connnection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// add a meta refresh tag, so the browser pulls again every 5 seconds:
client.println("<meta http-equiv=\"refresh\" content=\"5\">");
// output the value of temperature and humidity from DHT
client.println("<h1>");
client.println("<body style=background:#80BFFF>");
client.print("www.tehnic.go.ro & nicuflorica.blogspot.com");
client.println("<br />");
client.println("<br />");
client.print("Senzorul DHT11 al lui Nicu arata:");
client.println("<br />");
client.print("temperatura=");
client.print(t);
client.print("<sup>o</sup>");
client.print("C");
client.println("<br />");
client.print("umiditate=");
client.print(h);
client.print("%");
client.println("<br />");
client.println("</h1>");
client.println("<h4>");
client.print("versiune 1m2");
client.println("</html>");
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(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
Serial.println("======================");
}
}
Filmuletul care prezinta functionare se numeste DHT11 with Ethernet shield and Arduino (2)!!!
28.5.2013
Urmand exemplul din articolul Give Your Arduino Project Its Own Mini-Webserver, With An Ethernet Shield am facut o modificare in skecht, inlocuind linia
EthernetServer server(80);
cu
EthernetServer server(8081);
apoi am incarcat sketch-ul in Arduino si am obtinut informatia la adresa 192.168.2.177:8081:
Am deschis portul 8081 de la router, bifand si optiunea ENABLE PORT FORWARDING (in poza nu e bifat):
Am verificat in router ce IP mi s-a alocat la acea conectare (doarece se schimba la fiecare conectare):
Am folosit si indicatia din articol intrand la http://www.whatismyip.com/:
Am tastat adresa in alt browser (Internet Explorer) comparand-o cu indicatia de pe pagina locala (Google Chrome) - exista diferenta de indicatie datorita faptului ca valorile se schimba la 5 secunde si senzorul DHT11 are doar numere intregi, fara zecimale:
Am solicitat si unor prieteni sa verifica adresa si mi-au spus ca era ok, vazand temperatura si umiditatea.. primind si un "print screen":
.. si la finalul articolului, am pus un filmulet explicativ, care se numeste DHT11 with Ethernet shield and Arduino (3):