# Controlling things via the gateway using websockets

**URL:** <https://discourse.mozilla.org/t/controlling-things-via-the-gateway-using-websockets/55962>\
**Category:** WebThings\
**Created:** [March 15, 2020, 10:53am UTC](https://discourse.mozilla.org/t/controlling-things-via-the-gateway-using-websockets/55962 "2020-03-15T10:53:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaj856](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jaj856](https://discourse.mozilla.org/u/jaj856)\
**Post date:** [March 15, 2020, 10:53am UTC](https://discourse.mozilla.org/t/controlling-things-via-the-gateway-using-websockets/55962/1 "2020-03-15T10:53:11Z")

</div>

Hi,  
I’ve been able to use REST to control things via the gateway and am currently trying to do the same with websockets because I’d like the bi-directional communication websockets enables.

new WebSocket(“wss://xxx.mozilla-iot.org/things/http—w25.local-things-led”, “webthing”);

this connects but almost immediately disconnects with a 1005 (no status code was provided) error.

Are there any examples of using websockets to control things via the gateway?

TIA

---

<div class="post-metadata">

**Author:** ![mstegeman](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@mstegeman](https://discourse.mozilla.org/u/mstegeman)\
**Post date:** [March 15, 2020, 5:40pm UTC](https://discourse.mozilla.org/t/controlling-things-via-the-gateway-using-websockets/55962/2 "2020-03-15T17:40:25Z")

</div>

The biggest thing to know with the gateway is that you have to pass the JWT as a URL parameter when using the gateway, e.g. `new WebSocket('wss://xxx.mozilla-iot.org/things/http—w25.local-things-led?jwt=<your jwt>');`

The JWT can be your OAuth token or your user token.

---

<div class="post-metadata">

**Author:** ![jaj856](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jaj856](https://discourse.mozilla.org/u/jaj856)\
**Post date:** [March 16, 2020, 4:28pm UTC](https://discourse.mozilla.org/t/controlling-things-via-the-gateway-using-websockets/55962/3 "2020-03-16T16:28:25Z")

</div>

Thank you, connected and controlling the led thing 🙂
