I have a FRDM-K64F board and I am trying to set up the basic network example. What I find is that although the code compiles and runs ok I cannot get no IP address or mac set up. This is the code I have:
- include "mbed.h"
- include "main-hw.h"
- include "EthernetInterface.h"
Network interface
EthernetInterface net;
int main(void)
{
Bring up the ethernet interface
printf("Ethernet socket example\r\n");
int ret;
ret = net.set_network("x.x.x.x","255.255.255.0","x.x.x.x");
char macadd[6];
mbed_mac_address(macadd);
printf("%02x:%02x:%02x:%02x:%02x:%02x \r\n", macadd[0], macadd[1], macadd[2], macadd[3], macadd[4], macadd[5]);
const char *mac = net.get_mac_address();
printf("MAC address is: %s\r\n", mac ? mac : "No MAC");
const char *ip = net.get_ip_address();
printf("IP address is: %s\r\n", ip ? ip : "No IP");
ret = net.connect();
printf("Connect: %d\n",ret);
Show the network address
const char *ip = net.get_ip_address();
printf("IP address is: %s\n", ip ? ip : "No IP");
Open a socket on the network interface, and create a TCP connection to mbed.org
TCPSocket socket;
socket.open(&net);
socket.connect("developer.mbed.org", 80);
Send a simple http request
char sbuffer[] = "GET / HTTP/1.1\r\nHost: developer.mbed.org\r\n\r\n";
int scount = socket.send(sbuffer, sizeof sbuffer);
printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
Recieve a simple http response and print out the response line
char rbuffer[64];
int rcount = socket.recv(rbuffer, sizeof rbuffer);
printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);
Close the socket to return its memory and bring down the network interface
socket.close();
Bring down the ethernet interface
net.disconnect();
printf("Done\n");
return 0;
}
The mbed_mac_address prints the mac address correclty but the net.get_mac_address and net.get_ip_address return null values. The program stops on the net.connect command.
What am I doing wrong?
thanks,
I have a FRDM-K64F board and I am trying to set up the basic network example. What I find is that although the code compiles and runs ok I cannot get no IP address or mac set up. This is the code I have:
Network interface EthernetInterface net;
int main(void) {
Bring up the ethernet interface printf("Ethernet socket example\r\n");
int ret; ret = net.set_network("x.x.x.x","255.255.255.0","x.x.x.x");
char macadd[6]; mbed_mac_address(macadd); printf("%02x:%02x:%02x:%02x:%02x:%02x \r\n", macadd[0], macadd[1], macadd[2], macadd[3], macadd[4], macadd[5]);
const char *mac = net.get_mac_address(); printf("MAC address is: %s\r\n", mac ? mac : "No MAC");
const char *ip = net.get_ip_address(); printf("IP address is: %s\r\n", ip ? ip : "No IP");
ret = net.connect(); printf("Connect: %d\n",ret);
Show the network address const char *ip = net.get_ip_address(); printf("IP address is: %s\n", ip ? ip : "No IP");
Open a socket on the network interface, and create a TCP connection to mbed.org TCPSocket socket; socket.open(&net); socket.connect("developer.mbed.org", 80);
Send a simple http request char sbuffer[] = "GET / HTTP/1.1\r\nHost: developer.mbed.org\r\n\r\n"; int scount = socket.send(sbuffer, sizeof sbuffer); printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
Recieve a simple http response and print out the response line char rbuffer[64]; int rcount = socket.recv(rbuffer, sizeof rbuffer); printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);
Close the socket to return its memory and bring down the network interface socket.close();
Bring down the ethernet interface net.disconnect(); printf("Done\n");
return 0; }
The mbed_mac_address prints the mac address correclty but the net.get_mac_address and net.get_ip_address return null values. The program stops on the net.connect command.
What am I doing wrong?
thanks,