EtherCard
EtherCard copied to clipboard
Local IP - Bypass DNS
Hey,
I am trying to make a Post request within my local environment. When I use the IP it never goes further then DNS Lookup. I have found some related problem in this issues box but not a working example so far.
This is what I have.
#include <EtherCard.h>
#define TOKEN "picobello"
byte Ethernet::buffer[700];
Stash stash;
char website[] = "192.168.150.146";
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static uint32_t timer;
static byte session;
// called when the client request is complete
static void my_callback (byte status, word off, word len) {
Serial.println(">>>");
Ethernet::buffer[off+300] = 0;
Serial.print((const char*) Ethernet::buffer + off);
Serial.println("...");
}
void setup () {
Serial.begin(9600);
Serial.println(F("\n[webClient]"));
/*
// Change 'SS' to your Slave Select pin, if you arn't using the default pin
if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
Serial.println(F("Failed to access Ethernet controller"));
if (!ether.dhcpSetup())
Serial.println(F("DHCP failed"));
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
*/
const static uint8_t ip[] = {192,168,150,123};
const static uint8_t gw[] = {192,168,150,1};
const static uint8_t dns[] = {192,168,150,52};
if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
Serial.println(F("Failed to access Ethernet controller"));
if(!ether.staticSetup(ip, gw, dns))
{
// handle failure to configure static IP address (current implementation always returns true!)
Serial.println("Connection failed");
}
//ether.dnsLookup(website);
ether.parseIp(ether.hisip, website);
ether.printIp("SRV: ", ether.hisip);
Serial.println("Sending...");
byte sd = stash.create();
const char tweet[] = "This works!";
stash.print("token=");
stash.print(TOKEN);
stash.print("&status=");
stash.println(tweet);
stash.save();
int stash_size = stash.size();
// Compose the http POST request, taking the headers below and appending
// previously created stash in the sd holder.
Stash::prepare(PSTR("POST http://$F/update HTTP/1.0" "\r\n"
"Host: $F" "\r\n"
"Content-Length: $D" "\r\n"
"\r\n"
"$H"),
website, website, stash_size, sd);
// send the packet - this also releases all stash buffers once done
// Save the session ID so we can watch for it in the main loop.
session = ether.tcpSend();
}
void loop () {
ether.packetLoop(ether.packetReceive());
const char* reply = ether.tcpReply(session);
if (reply != 0) {
Serial.println("Got a response!");
Serial.println(reply);
}
if (millis() > timer) {
timer = millis() + 11000;
Serial.println(reply);
// Serial.print("<<< REQ ");
// ether.browseUrl(PSTR("/foo/"), "bar", website, my_callback);
}
}
This is the log: 22:15:05.222 -> [webClient] 22:15:05.222 -> SRV: 192.168.150.146 22:15:05.256 -> Sending... 22:15:05.256 ->
When I use a hostname + Lookup everything works fine, but local doesnt work unfortunately. How can I bypass the DNS Lookup?
Thank you in advance.