5

I was just wondering if there was a way to send CoAP queries in the browser (using JavaScript?), but not using node.js.

Thanks!

niutech
  • 28,923
  • 15
  • 96
  • 106
Daryl Rodrigo
  • 1,387
  • 2
  • 11
  • 19

2 Answers2

8

Unfortunately this is not directly possible. Web browsers do not provide any JavaScript API for UDP sockets for security reasons.

If you need an in-browser app to communicate to a device via a CoAP interface, you may need to provide an intermediary service. For example, you could create a web service that is accessible via HTTP, and acts as a translator to CoAP.

Note that node.js does support UDP connections, and could be used to send CoAP messages. However, it is a server-side technology, and cannot be used in the browser. It could be used to build such a translator service; but would not be required.

Also, it appears that "Chrome Apps", which are based on HTML5 and JavaScript, but are distinctly different from web pages, do have access to UDP Sockets.

mbmcavoy
  • 2,628
  • 5
  • 23
  • 34
1

It is possible when using CoAP over TCP/IP or a CoAP-HTTP proxy, like Californium, jCoAP, SmartServiceProxy or Squid with CoAP-HTTP.

There is also a partial JavaScript implementation of CoAP - JSCoAP.

Community
  • 1
  • 1
niutech
  • 28,923
  • 15
  • 96
  • 106
  • is there any example for `JSCoAP` ?. I'm searching how to implement and use it in webpage. – Kaleem Ullah Mar 02 '16 at 13:46
  • @LukyBoy-KU Here you go: I have written the [JSCoAP API Reference with an Example](https://github.com/jdeblese/jscoap/wiki/API). – niutech Mar 03 '16 at 00:44
  • @nuitech please help me, I tried including JSCOAP in my html page. and then using javascript when I call this method with my coap url nothing happen. `var buffer = serialize(message, "coap://[aaaa::c30c:0:0:2]:5683/sensor/temperature");` please help me, i want to do AJAX call using CoAP URL which returns me response. I tried with FireFox Copper Addon and this URL works fine. but I want in AJAX call – Kaleem Ullah Mar 09 '16 at 16:32
  • You should contact the JSCoAP library owner Jan-willem De Bleser. – niutech Mar 14 '16 at 21:46