---
title: "How to detect unplugged LAN cable ?"
url: "https://maker.wiznet.io/forum/14122"
markdown_url: "https://maker.wiznet.io/forum/14122/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "kejuqeju"
created: "2021-01-19T09:58:46+09:00"
last_activity: "2021-01-20T09:12:47+09:00"
language: "en"
views: 1771
replies: 2
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# How to detect unplugged LAN cable ?

## Question

Asked by kejuqeju on 2021-01-19 in Ethernet Chips.

Hello there…
i am having problem with detecting unplugged LAN cable.
i read that i must turn on the keep alive timer, so if the remote client/server doesnt reply when keep alive timer send 1 byte data, W5500 will generate timeout interrupt, and then i can close the socket.

And then i found something weird. I did 3 type of testing. the result is:

TESTING 1

1. set socket 0 to TCP server

2. socket 0 OPEN

3. set keep alive timer to 1 (5 secs)

4. socket 0 LISTEN

5. remote TCP Client connecting to W5500

6. connected, socket status become 0x17

7. TCP client send some data, received normally by W5500

8. and then i unplugged the LAN cable

9. after some time, socket TIMEOUT occurs (as expected)

10. socket 0 closed, back to point 2

TESTING 2

1. set socket 0 to TCP server

2. socket 0 OPEN

3. set keep alive timer to 1 (5 secs)

4. socket 0 LISTEN

5. remote TCP Client connecting to W5500

6. connected, socket status become 0x17

7. W5500 send some data, received normally by remote TCP client

8. and then i unplugged the LAN cable

9. after some time, socket TIMEOUT occurs (as expected)

10. socket 0 closed, back to point 2

TESTING 3

1. set socket 0 to TCP server

2. socket 0 OPEN

3. set keep alive timer to 1 (5 secs)

4. socket 0 LISTEN

5. remote TCP Client connecting to W5500

6. connected, socket status become 0x17

7. do nothing

8. and then i unplugged the LAN cable

9. i waited, but no timeout at all.

i am confused about TESTING 3. do i have to send/receive data first, so the timeout will occur? or there is another way to detect unplugged cable?

## Replies

### Reply 1 by Yaumen, 2021-01-20

Hi.
I determine a link link this:

- linked: (getPHYCFGR() & PHYCFGR_LNK_ON)

- unlinked: !(getPHYCFGR() & PHYCFGR_LNK_ON)

### Reply 2 by kejuqeju, 2021-01-20

Hello Yaumen,
thank you for your advice. I implemented it, and it worked OK.

---

Source: https://maker.wiznet.io/forum/14122
