Baixei essa biblioteca e estou usando porque foi a unica que funcionou perfeitamente com o Arduino nano, porém ela não tem exemplo de como usar o DHCP para obter um ip.

Alguém pode me ajudar ?

Exibições: 1662

Responder esta

Respostas a este tópico

Amigão é o seguinte: testei o DHCP com a biblioteca em anexo aqui e funcionou perfeitamente com o Arduino Nano + ENC28j60.

Usei um exemplo que já vem com ela, só alterei alguns detalhes:

#include <EtherShield.h>

static uint8_t mymac[6] = { 0x54,0x55,0x58,0x12,0x34,0x56 };
static uint8_t myip[4] = { 0,0,0,0 };
static uint8_t mynetmask[4] = { 0,0,0,0 };
static uint8_t websrvip[4] = { 0, 0, 0, 0 };
static uint8_t gwip[4] = { 0,0,0,0};
static uint8_t dnsip[4] = { 0,0,0,0 };
static uint8_t dhcpsvrip[4] = { 0,0,0,0 };
#define MYWWWPORT 80

#define BUFFER_SIZE 750
static uint8_t buf[BUFFER_SIZE+1];

EtherShield es=EtherShield();

void setup() {
Serial.begin(9600);
Serial.println("DHCP Client test");

for( int i=0; i<6; i++ ) {
Serial.print( mymac[i], HEX );
Serial.print( i < 5 ? ":" : "" );
}
Serial.println();

es.ES_enc28j60SpiInit();

Serial.println("Init ENC28J60");

es.ES_enc28j60Init(mymac);

Serial.println("Init done");

Serial.print( "ENC28J60 version " );
Serial.println( es.ES_enc28j60Revision(), HEX);
if( es.ES_enc28j60Revision() <= 0 ) {
Serial.println( "Failed to access ENC28J60");

while(1);
}

Serial.println("Requesting IP Addresse");
if( es.allocateIPAddress(buf, BUFFER_SIZE, mymac, 80, myip, mynetmask, gwip, dhcpsvrip, dnsip ) > 0 ) {

Serial.print( "My IP: " );
printIP( myip );
Serial.println();

Serial.print( "Netmask: " );
printIP( mynetmask );
Serial.println();

Serial.print( "DNS IP: " );
printIP( dnsip );
Serial.println();

Serial.print( "GW IP: " );
printIP( gwip );
Serial.println();

} else {
Serial.println("Failed to get IP address");
}

}

void printIP( uint8_t *buf ) {
for( int i = 0; i < 4; i++ ) {
Serial.print( buf[i], DEC );
if( i<3 )
Serial.print( "." );
}
}

void loop(){
}

Olha o print do Serial Monitor:

Qualquer coisa é só falar!

Abraço.

Anexos

Posta o código do seu teste de envio/recebimento pra dar uma olhada.

Qual a maneira que você está enviando os dados para o Arduino?

Abraço.

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço