Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 2 months ago.
EthernetInterface MBED-OS 5.3 static IP
It appears there is still no way to set a static IP in the Ethernet Interface. My application must be able to set a static IP, is there anyway to fix this? I just updated to the very latest MBED-OS 5.3 and would hate to go back to MBED 2 to regain this feature. I am using the FRDM-k64 board.
2 Answers
9 years, 2 months ago.
Static IP addresses were re-included around mbed-os-5.2 with the set_network function that Dan is correctly using.
Unfortunately, when IPv6 support was added to the EthernetInterface, a bug was introduced that prevented the network from working with static IPv4 addresses. This left the API in the worst state: disfunctional and misleading.
Sorry about the trouble this caused, the issue is being tracked with a fix up on the mbed-os repo:
https://github.com/ARMmbed/mbed-os/pull/3526
This static IPv4 addresses should be usable again soon.
Hello,
Is it usable again? I'm having problems using static IP. How can I check if I've the newest working version?
posted by 04 Apr 2017Hi,
Static IP or IP via DHCP are acting same for me, I get an error -3004 after one successful transmission (either using UDP or TCP socket - no errors from socket), Any ideas, updates?
posted by 06 Apr 20179 years, 2 months ago.
This has been an issue since 5.x was released. Not sure why it was not included. So far no announcements of static IP being re-included. Mbed? Anyone? Bueller?
After digging through the github repository I figured out how to set a static IP address. Unfortunately I can't seem to create a TCP Server now (This worked when using DHCP).
My Code:
#include "mbed.h" #include "TCPSocket.h" #include "EthernetInterface.h" #include "TCPSocket.h" #include "SocketAddress.h" EthernetInterface eth; TCPSocket socket; TCPServer tcpserver; RawSerial dbug(PTB17, PTB16); #define IP "192.168.1.100" #define GATEWAY "192.168.1.1" #define MASK "255.255.255.0" int main() { dbug.baud(115200); dbug.printf("Example network-socket TCP Server\r\n"); eth.disconnect(); int i=eth.set_network(IP,MASK,GATEWAY); dbug.printf("set IP status: %i \r\n",i); i=eth.connect(); dbug.printf("connect status: %i \r\n",i); const char *ip = eth.get_ip_address(); const char *mac = eth.get_mac_address(); dbug.printf("IP address is: %s\n\r", ip ? ip : "No IP"); dbug.printf("MAC address is: %s\n\r", mac ? mac : "No MAC"); SocketAddress sockaddr; i=tcpserver.open(ð); if (i<0) { dbug.printf("open error: %i \r\n",i); while(true) {} } dbug.printf("server open\r\n"); i=tcpserver.bind(ip,23); if (i<0) { dbug.printf("bind error: %i \r\n",i); while(true) {} } dbug.printf("Bound\r\n"); if (tcpserver.listen()<0) dbug.printf("listen error\r\n"); dbug.printf("Listening\r\n"); i = tcpserver.accept(&socket); if (i<0) dbug.printf("accept error: %i \r\n",i); dbug.printf("Socket Accepted\r\n"); }This is what I get on the debug terminal:
Example network-socket TCP Server
set IP status: 0
connect status: 0
IP address is: 192.168.1.100
MAC address is: 8a:42:7d:87:0c:b7
open error: -3004
Error -3004 is "not connected to a network"
posted by Dan Sexton 31 Dec 2016However I can ping the module on it's assigned IP address and it responds to the ping so we know the network is indeed connected.