Ajuda-me no meu projecto
boa tarde pessoal!! 
como eu sou novato nisto, estou precisar de um empurrão para tentar acabar meu projeto que consiste em eu criar um web server que vai apresentar dados de temperatura e humidade, eu estou utilizar os seguintes shield enc28j60"para conectar com net para depois monstra no browser" o sensor dht11" para dar os dados de temperatura e humidade ".
eu já tentei fazer um código mas tá ter um erro nos dados e não estou conseguir corrigir o erro. :~
-------------------------------------------------------------------------------------------------------------------------
#include <dht.h>
#include <ethercard.h>
#define dht_dpin a1
dht dht;
// ethernet interface mac address, must unique on lan
static byte mymac[] = { 0x74,0x69,0x69,0x2d,0x30,0x31 };
static byte myip[] = { 192,168,1,203 };
byte ethernet::buffer[500];
bufferfiller bfill;
float rh, rt;
void setup () {
if (ether.begin(sizeof ethernet::buffer, mymac) == 0)
serial.println( "failed access ethernet controller");
ether.staticsetup(myip);
serial.begin(9600);
dht.begin();
}
static word homepage() {
dht.read11(dht_dpin);
bfill = ether.tcpoffset();
bfill.emit_p(pstr(
"http/1.0 200 ok\r\n"
"content-type: text/html\r\n"
"pragma: no-cache\r\n"
"\r\n"
"<meta http-equiv='refresh' content='1'/>"
"<title>rbbb server</title>"
"<h1>arduino </h1>"
"<br>"
"<h2>humidity: $d</h2>"
"<h2>temperature: $d</h2>"),
rh, rt);
return bfill.position();
}
void loop () {
rh = dht.readhumidity();
rt = dht.readtemperature();
word len = ether.packetreceive();
word pos = ether.packetloop(len);
if (isnan(rt) || isnan(rh)) {
serial.println("failed read dht");
} else {
serial.print("humidity: ");
serial.print(rh);
serial.print(" %\t");
serial.print("temperature: ");
serial.print(rt);
serial.println(" *c");
}
if (pos) // check if valid tcp data received
ether.httpserverreply(homepage()); // send web page data
}
------------------------------------------------------------------------------------------------------------------------
eu espero que me possam dar uma ajuda
meus comprimentos
tiago gomes

como eu sou novato nisto, estou precisar de um empurrão para tentar acabar meu projeto que consiste em eu criar um web server que vai apresentar dados de temperatura e humidade, eu estou utilizar os seguintes shield enc28j60"para conectar com net para depois monstra no browser" o sensor dht11" para dar os dados de temperatura e humidade ".
eu já tentei fazer um código mas tá ter um erro nos dados e não estou conseguir corrigir o erro. :~
-------------------------------------------------------------------------------------------------------------------------
#include <dht.h>
#include <ethercard.h>
#define dht_dpin a1
dht dht;
// ethernet interface mac address, must unique on lan
static byte mymac[] = { 0x74,0x69,0x69,0x2d,0x30,0x31 };
static byte myip[] = { 192,168,1,203 };
byte ethernet::buffer[500];
bufferfiller bfill;
float rh, rt;
void setup () {
if (ether.begin(sizeof ethernet::buffer, mymac) == 0)
serial.println( "failed access ethernet controller");
ether.staticsetup(myip);
serial.begin(9600);
dht.begin();
}
static word homepage() {
dht.read11(dht_dpin);
bfill = ether.tcpoffset();
bfill.emit_p(pstr(
"http/1.0 200 ok\r\n"
"content-type: text/html\r\n"
"pragma: no-cache\r\n"
"\r\n"
"<meta http-equiv='refresh' content='1'/>"
"<title>rbbb server</title>"
"<h1>arduino </h1>"
"<br>"
"<h2>humidity: $d</h2>"
"<h2>temperature: $d</h2>"),
rh, rt);
return bfill.position();
}
void loop () {
rh = dht.readhumidity();
rt = dht.readtemperature();
word len = ether.packetreceive();
word pos = ether.packetloop(len);
if (isnan(rt) || isnan(rh)) {
serial.println("failed read dht");
} else {
serial.print("humidity: ");
serial.print(rh);
serial.print(" %\t");
serial.print("temperature: ");
serial.print(rt);
serial.println(" *c");
}
if (pos) // check if valid tcp data received
ether.httpserverreply(homepage()); // send web page data
}
------------------------------------------------------------------------------------------------------------------------
eu espero que me possam dar uma ajuda

meus comprimentos
tiago gomes
esse funciona, mas é com ds18b20, basta você adaptá-lo.
baseado em http://mk90.blogspot.com.br/2013/05/web.html
baseado em http://mk90.blogspot.com.br/2013/05/web.html
code: [select]
//*********************************************************//
// name: ethercard + ds18b20 ? ????????? //
// author: ilya danilov www.mk90.ru/blog //
// date: 07 may 2013, last update: 18 may 2013 //
// version: 0.0.1 //
// schematic: ???????-??????????? ????? ?? atmega328p + //
// ethercard (ss=d10) + ds18b20 (d9) //
// note: ??? ????????? ????? ??????? ?????????? ????? //
// ???????? ds12b20, ??????????? ? ????????? //
// ??????? ???????? ???????????. ? ???????? //
// ?????????????? ??????? ????????? ????????, //
// ?????? ?????????????? ? ??????. ??. ????? //
// mk90.blogspot.com/ds18b20 //
// based on ethercard project: github.com/jcw/ethercard //
//*********************************************************//
#include <onewire.h>
#include <ethercard.h>
// definição ethernet
#define buf_size 512
byte mac[] = { 0x00, 0x04, 0xa3, 0x21, 0xca, 0x39 }; // mac address
byte fixed = false; // =false: tentando obter um endereço dhcp,
// em caso de falha de usar uma estática;
// =true: usar imediatamente uma estática
uint8_t ip[] = { 10, 16, 131, 23 }; // endereço ip estático
uint8_t subnet[] = { 255, 255, 252, 0 }; // mascara de subrede
uint8_t gateway[] = { 10, 16, 130, 70 }; // gateway
uint8_t dns[] = { 10, 16, 130, 9 }; // endereço servidor dns (opcional)
byte ethernet::buffer[buf_size];
static bufferfiller bfill; // used cursor while filling buffer
// ????????? onewire
#define ds18b20pin 9
onewire ds(ds18b20pin);
// ??????? ds18b20
void setconversiontime(byte conf) {
ds.reset();
ds.skip(); // skip rom
ds.write(0x4e); // write scratchpad
ds.write(0); // th
ds.write(0); // tl
ds.write(conf); // configuration
}
void startconversionall() {
ds.reset();
ds.skip(); // skip rom
ds.write(0x44, 1); // start conversion
delay(10);
}
//#include <avr/pgmspace.h>
prog_char string_0[] progmem = "sensor 0";
prog_char string_1[] progmem = "sensor 1";
prog_char string_2[] progmem = "sensor 2";
progmem const char *locations[] =
{
string_0,
string_1,
string_2
};
void setup(void)
{
serial.begin(57600);
delay(2000);
// verifique se o controlador ethernet está disponível para trabalhar
serial.println("initialising ethernet controller");
if (ether.begin(sizeof ethernet::buffer, mac) == 0) {
serial.println( "ethernet controller not initialised");
while (true);
}
// tentando obter um endereço dinamicamente
serial.println("attempting ip address using dhcp");
if (ether.dhcpsetup()) {
ether.printip("got ip address using dhcp: ", ether.myip);
} else {
// se o dhcp não estiver disponível, use um endereço ip estático
ether.staticsetup(ip, gateway, dns);
ether.printip("dhcp failed, using fixed address: ", ether.myip);
fixed = true;
}
}
char okheader[] progmem =
"http/1.0 200 ok\r\n"
"content-type: text/html; charset=utf-8\r\n"
"pragma: no-cache\r\n"
;
char authorlink[] progmem =
"</pre><hr>temperatura"
;
static void homepage (bufferfiller& buf) {
buf.emit_p(pstr("$f\r\n"
// "<title>arduino web-thermometr</title>"
"<h2>ds18b20 network:</h2>"
"<pre>"), okheader);
byte counter = 0;
byte addr[8];
byte data[12];
setconversiontime(0x7f); // conjunto de resolução de 9 bits
startconversionall(); // iniciar conversão de temperatura
delay(400); // para converter 9 bits requer 93,75 ms
// dispositivo procura e exibir os resultados
ds.reset_search();
delay(250);
while (ds.search(addr)) {
//buf.emit_p(pstr("$d: "),++counter);
buf.emit_p( (char*)pgm_read_word(&(locations[counter++])) );
buf.emit_p(pstr(": "));
if ( onewire::crc8(addr, 7) != addr[7]) {
buf.emit_p(pstr("- address crc not valid!\n"));
continue;
} else if (addr[0] != 0x28) {
buf.emit_p(pstr("- not ds18b20 family device!\n"));
continue;
}
ds.reset();
// ds.select(addr);
// ds.write(0x44, 1); // start conversion, parasite power on @ end
// delay(1000); // maybe 750ms enough, maybe not
// might ds.depower() here, reset take care of it.
ds.reset();
ds.select(addr);
ds.write(0xbe); // leia rascunho
(byte k=0; k<9; k++) { // precisamos de 9 bytes
data[k] = ds.read();
}
if ( onewire::crc8( data, 8) != data[8]) {
buf.emit_p(pstr("- value crc not valid!\n"));
continue;
}
buf.emit_p(pstr("<title>$d.$d °c</title>"), *(int *)data/16, (int) (abs(*(int *)data % 16) * 0.625));
buf.emit_p(pstr(" $d.$d °c\n"), *(int *)data/16, (int) (abs(*(int *)data % 16) * 0.625));
}
buf.emit_p(pstr("\ntotal: $d devices."), counter);
buf.emit_p(authorlink);
}
void loop(void)
{
word len = ether.packetreceive();
word pos = ether.packetloop(len);
if (pos) {
bfill = ether.tcpoffset();
char* data = (char *) ethernet::buffer + pos;
serial.println(data); // imprimir um pedido de depuração
if (strncmp("get / ", data, 6) == 0)
homepage(bfill);
else
bfill.emit_p(pstr(
"http/1.0 401 unauthorized\r\n"
"content-type: text/html\r\n"
"\r\n"
"<h1>401 unauthorized</h1>"));
// enviar uma resposta para o cliente
ether.httpserverreply(bfill.position());
}
}
Arduino Forum > International > Portugues > Ajuda-me no meu projecto
arduino
Comments
Post a Comment