# Websocket Disconnect

**URL:** <https://community.tempest.earth/t/websocket-disconnect/1184>\
**Category:** Developers\
**Created:** [June 7, 2018, 3:23pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184 "2018-06-07T15:23:52Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![btst.online](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/btst.online/32/16538_2.png) [@btst.online](https://community.tempest.earth/u/btst.online)\
**Post date:** [June 7, 2018, 3:23pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/1 "2018-06-07T15:23:52Z")

</div>

Emailed Support about this…  
Is there any way to force a disconnect? The docs say that a client will be disconnected after 60 minutes of being idle.

However, in my app, if I close the connection from my end… and reconnect after a few minutes, I get N+1 ‘connection\_opened’ messages (one for each time I connect)… so on the 2nd close and 3rd connect, I get 3 of the ‘connection\_openend’ messages.

If I could send a JSON disconnect packet …  
–Sam

---

<div class="post-metadata">

**Author:** ![GaryFunk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/garyfunk/32/5729_2.png) [@GaryFunk](https://community.tempest.earth/u/GaryFunk)\
**Post date:** [June 7, 2018, 3:26pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/2 "2018-06-07T15:26:17Z")

</div>

For each “listen” you sent you need to send a stop:

{  
“type”:“listen\_stop”,  
“device\_id”:1110,  
“id”:“2098388936”  
}  
{  
“type”:“listen\_stop\_events”,  
“station\_id”:2594,  
“id”:“2098388541”  
}  
{  
“type”:“listen\_rapid\_stop”,  
“device\_id”:1110,  
“id”:“2098388587”  
}

It’s documented here:

[https://weatherflow.github.io/SmartWeather/api/ws.html](https://weatherflow.github.io/SmartWeather/api/ws.html)

---

<div class="post-metadata">

**Author:** ![btst.online](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/btst.online/32/16538_2.png) [@btst.online](https://community.tempest.earth/u/btst.online)\
**Post date:** [June 7, 2018, 3:30pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/3 "2018-06-07T15:30:51Z")

</div>

I do that already. I even force my WS connection closed on my end… but still get the extra ‘connection\_opened’ responses when I reconnect.

---

<div class="post-metadata">

**Author:** ![GaryFunk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/garyfunk/32/5729_2.png) [@GaryFunk](https://community.tempest.earth/u/GaryFunk)\
**Post date:** [June 7, 2018, 3:32pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/4 "2018-06-07T15:32:25Z")

</div>

When you send the stop, do you get back the ACK?

---

<div class="post-metadata">

**Author:** ![GaryFunk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/garyfunk/32/5729_2.png) [@GaryFunk](https://community.tempest.earth/u/GaryFunk)\
**Post date:** [June 7, 2018, 3:45pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/5 "2018-06-07T15:45:36Z")

</div>

> [@btst.online](#):
>
> I even force my WS connection closed on my end

What method to you use to close the connection?

---

<div class="post-metadata">

**Author:** ![btst.online](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/btst.online/32/16538_2.png) [@btst.online](https://community.tempest.earth/u/btst.online)\
**Post date:** [June 7, 2018, 3:51pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/6 "2018-06-07T15:51:11Z")

</div>

I do get an ‘ack’ for each stop message I send. Just verified that…

I have two otions, a ‘close’ command and an ‘abort’ command. Both close the connection, just ‘close’ sends any pending data, while ‘abort’ does not.

Using ether route, I get the same results.

I’m pretty sure it’s because on the WF side:

> Other Useful Information  
> A client should only open one websocket connection.  
> A client will be disconnected after 60 minutes of idle time.  
> All messages are JSON strings.

---

<div class="post-metadata">

**Author:** ![GaryFunk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/garyfunk/32/5729_2.png) [@GaryFunk](https://community.tempest.earth/u/GaryFunk)\
**Post date:** [June 7, 2018, 4:00pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/7 "2018-06-07T16:00:30Z")

</div>

I’ve never had the issue. Something is not being closed properly.

After you is issue the stop commands, wait two minutes before you discount to see if any data comes in.

After you send the disconnect command send a listen command and see what is returned.

---

<div class="post-metadata">

**Author:** ![btst.online](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/btst.online/32/16538_2.png) [@btst.online](https://community.tempest.earth/u/btst.online)\
**Post date:** [June 7, 2018, 4:30pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/8 "2018-06-07T16:30:21Z")

</div>

Ok. Issued the stop commands… and waited for over 5 minutes… no new messages came in.

What ‘disconnect’ command? Do you mean after my ‘close’ or ‘abort’?

---

<div class="post-metadata">

**Author:** ![btst.online](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/btst.online/32/16538_2.png) [@btst.online](https://community.tempest.earth/u/btst.online)\
**Post date:** [June 7, 2018, 4:36pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/9 "2018-06-07T16:36:18Z")

</div>

As a result, I am getting multiple messages pushed… if I do the start/stop multiple times, then I get that number of messages (ie, 4 stop.starts on my AIR, I get 4 obs\_air messages).

---

<div class="post-metadata">

**Author:** ![peter](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/peter/32/1365_2.png) [@peter](https://community.tempest.earth/u/peter)\
**Post date:** [June 7, 2018, 4:39pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/10 "2018-06-07T16:39:20Z")

</div>

I use the websocket functionality in my Python code and have never observed this issue. I concur with @GaryFunk that this isn’t an issue with the WF websocket, and it must be to do with how your code is closing (or not closing) the connection.

---

<div class="post-metadata">

**Author:** ![GaryFunk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/garyfunk/32/5729_2.png) [@GaryFunk](https://community.tempest.earth/u/GaryFunk)\
**Post date:** [June 7, 2018, 4:49pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/11 "2018-06-07T16:49:23Z")

</div>

When you want to disconnect from a web socket, you send a packet with an opcode 8 to the server.

---

<div class="post-metadata">

**Author:** ![btst.online](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/btst.online/32/16538_2.png) [@btst.online](https://community.tempest.earth/u/btst.online)\
**Post date:** [June 7, 2018, 4:58pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/12 "2018-06-07T16:58:47Z")

</div>

Got it figured out… seems you have to invalidate your websocket object to get it to fully disconnect. So yes… it is on my end.

Along those lines… when does the 60 minute close come into play?

---

<div class="post-metadata">

**Author:** ![peter](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/peter/32/1365_2.png) [@peter](https://community.tempest.earth/u/peter)\
**Post date:** [June 7, 2018, 5:17pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/13 "2018-06-07T17:17:10Z")

</div>

My impression is that if the device you are connected too stops sending data, the connection will be closed after 60 minutes. Happy to be corrected though!

---

<div class="post-metadata">

**Author:** ![btst.online](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/btst.online/32/16538_2.png) [@btst.online](https://community.tempest.earth/u/btst.online)\
**Post date:** [June 7, 2018, 6:42pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/14 "2018-06-07T18:42:08Z")

</div>

Since the docs say:  
A client will be disconnected after 60 minutes of idle time.

And the client only waits for data from the server… When is the client considered “idle”?

---

<div class="post-metadata">

**Author:** ![GaryFunk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/garyfunk/32/5729_2.png) [@GaryFunk](https://community.tempest.earth/u/GaryFunk)\
**Post date:** [June 7, 2018, 7:06pm UTC](https://community.tempest.earth/t/websocket-disconnect/1184/15 "2018-06-07T19:06:20Z")

</div>

I will suggest the idle state starts after a packet is sent from the server AND received by the client.
