obniz API

Let use a hardware as API

All things via API

obniz is fully controllable by sending json via Websocket API.
Turning IO on/off, sending/receiging data via UART/SPI, using BLE/OLED etc,,,

This is a new way to control things from the internet.

Especially, Websocket api let you to use obniz from your html and bi-directionaly communication.
obniz.js warps this API.

This page shows API details and specifications.

Endpoint

Each obniz has different API Endpoint.

Websocket API

wss://obniz.io/obniz/{obniz_id}/ws/1

Example javascript usage

<!-- HTML Example -->
<html>
<body>
<script>
  // Simplest example
  var host = 'wss://obniz.io'

  function connect() {
    var socket = new WebSocket(host + '/obniz/OBNIZ_ID_HERE/ws/1');

    socket.onmessage = function (event) {
      var arr = JSON.parse(event.data);
      for (var i=0; i<arr.length; i++) {
        var obj = arr[i];
        if (obj.ws && obj.ws.redirect) {
          host = obj.ws.redirect;
          socket.onmessage = null;
          socket.close();
          connect();
        }
        if (obj.ws && obj.ws.ready) {
          socket.send(JSON.stringify([{display:{clear:true}}, {display:{text:"Works fine."}}]));
        }
      }
    }

  }

  connect();

</script>
</body>
</html>

REST API

Not only Websocket API. Post json via HTTP REST API.
But you can't get any values from obniz via this API. Just sending.

POST https://obniz.io/obniz/{obniz_id}/api/1

reqeust content type must be application/json and body must contain json object.

Curl example.

curl https://obniz.io/obniz/1234-5678/api/1 -H "Content-Type: application/json" -X POST -d '[{"display":{"clear":true, "text":"Works fine."}}]'

Security

After obniz has been owned by someone's account, obniz API can be used with API keys. This is optinoal But recommended.
See more details on each obniz setting page. It will appear on your account page after registration.

JSON Formats

All communication on Websocket is JSON.
Control obniz by sending JSON and get values by receiving JSON from obniz.

See obniz websocket format