Hello!
I’m using a Arduino Uno R3 and a Enc28j60 with the EtherCard.h-library from https://github.com/jcw/ethercard.
When I’m trying the example program “webClient” the board gets online and downloads a web page, but when I try to do almost the same (but without going online, just on my LAN) nothing gets to my local web server.
I think the problem lies in that I don’t really know how to use the method ether.browseUrl() when I only got a plain IP-adress instead of a full URL like in the example. I have attached the code that I have come up with that don’t work for me.
This is want I think is wrong: ether.browseUrl(PSTR("/index.php"), "", NULL, my_result_cb);
Does anyone here have an idea of what I should do to get this working?
#include <EtherCard.h>
static byte mymac[] = { 0x54, 0xD9, 0xFE, 0xDD, 0xFF, 0xE0 };
static byte myip[] = { 192, 168, 0, 91 };
static byte hisip[] = { 192, 168, 0, 16 };
static byte mymask[] = { 255, 255, 255, 0 };
byte Ethernet::buffer[700];
unsigned long previousMillis = 0;
void setup() {
Serial.begin(9600);
ether.begin(sizeof Ethernet::buffer, mymac);
ether.staticSetup(myip);
ether.copyIp(ether.mymask, mymask);
ether.copyIp(ether.hisip, hisip); // Selects the IP 192.168.0.16 to be used with the .browseUrl-method.
// Prints out the current IP-settings
ether.printIp("My IP: ", ether.myip);
ether.printIp("Netmask: ", ether.mymask);
ether.printIp("Server: ", ether.hisip);
}
void loop() {
unsigned long currentMillis = millis();
// Needed for response to ICMP-pings
ether.packetLoop(ether.packetReceive());
// Every 5th second it makes a HTTP-request to index.php on server 192.168.0.16
if(currentMillis - previousMillis > 5000) {
ether.browseUrl(PSTR("/index.php"), "", NULL, my_result_cb);
Serial.println("Sending a request...");
previousMillis = currentMillis;
}
}
// Function to output the response from the web server
static void my_result_cb (byte status, word off, word len) {
Serial.print("<<< reply ");
Serial.println((const char*) Ethernet::buffer + off);
}