Recentemente comprei um módulo enc28j60 para fazer a conexão entre meu arduino e um servidor local rodando laravel, pesquisei sobre como fazer post em um servidor web e consegui designar um ip por meio do DHCP, o módulo está funcionando corretamente, porém não consigo fazer o post no servidor. Segue o código:
#include <EtherCard.h>
#define ROUTE "post"
byte Ethernet::buffer[700];
Stash stash;
byte mymac[] = { 0x74,0x69,0x69,0x2D,0x42,0x42 };
const char server[] PROGMEM = "192.168.1.103:8000";
static void Post () {
Serial.println("Iniciando Post");
Serial.println(F("Enviando informações do post..."));
byte sd = stash.create();
stash.print("mensagem=Mensagem enviada por arduino");
stash.save();
Stash::prepare(PSTR("POST /$F HTTP/1.1" "\r\n"
"Host: $F" "\r\n"
"Content-Length: $D" "\r\n"
"Content-Type: application/x-www-form-urlencoded" "\r\n"
"\r\n"
"$H"),
PSTR(ROUTE), server, stash.size(), sd);
ether.tcpSend();
Serial.println("Post realizado");
}
void setup() {
Serial.begin(9600);
Serial.println("Iniciando");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) {
Serial.println(F("Erro no módulo"));
}
else{
Serial.println(F("Módulo funcionando"));
}
if (!ether.dhcpSetup()){
Serial.println(F("DHCP falhou"));
}
else{
Serial.println(F("DHCP funcionou"));
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
if (!ether.dnsLookup(server)){
Serial.println(F("DNS falhou"));
}
else{
Serial.println(F("DNS funcionou"));
ether.printIp("SRV: ", ether.hisip);
Post();
}
}
void loop() {
}
Quando ele faz a pesquisa do dns no dnsLookup, eu recebo a mensagem dizendo que falhou, porém, quando troco o servidor da pesquisa por google.com, funciona normalmente. O estranho é que se eu troco o google.com pelo ip do website do google, eu volto a receber a mensagem de falha.
Caso eu execute minha função Post() sem realizar o dnsLookup, o post não é realizado da mesma forma, eu me pergunto se talvez o código da função esteja errado, afinal eu não consegui fazer nenhuma requisição post no meu servidor até agora.
O meu plano é em junto do módulo de ethernet, utilizar um sensor de digital para poder armazenar as imagens das digitais e fazer comparações.
Agradeço a ajuda!