Implementation of Web Thing API specification by Mozilla IoT
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
routes
.gitignore
LICENSE
README.md
requirements.txt
vertex.py

README.md

Vertex

Web Thing API implementation of the Mozilla WOT Specification

Dependencies

  • python

Build Instructions

  • Get the python dependencies
$ pip install -r requirements.txt

Running the Thing API Server

$ python vertex.py server [port]

Importing Web Thing Devices

$ python vertex.py import toaster https://raw.githubusercontent.com/unifiedthings/schematics/master/toaster/v1.json

Using the Web Thing API

  • Get a list of all things
$ curl localhost:3000/things
 
[
  {
    "actions": {
      "pop": {
        "description": "Pop up the toast",
        "href": "/things/toaster/actions/pop",
        "input": {
          "type": "number"
        }
      }
    },
    "description": "A web connected toaster",
    "events": {
      "ready": {
        "description": "Your toast is ready!",
        "href": "/things/toaster/events/ready"
      }
    },
    "links": [
      {
        "href": "/things/toaster/properties",
        "mediaType": "application/json",
        "rel": "properties"
      },
      {
        "href": "/things/toaster/events",
        "mediaType": "application/json",
        "rel": "events"
      },
      {
        "href": "/things/toaster/actions",
        "mediaType": "application/json",
        "rel": "actions"
      }
    ],
    "name": "UnifiedThings Toaster",
    "properties": {
      "on": {
        "description": "Whether the toaster is currently heating bread",
        "href": "/things/toaster/properties/on",
        "type": "boolean"
      },
      "timeRemaining": {
        "href": "/things/toaster/properties/timeRemaining",
        "type": "number",
        "unit": "seconds"
      }
    },
    "type": "toaster"
  }
]
  • Get details for a particular thing
$ curl localhost:3000/things/toaster

{
  "actions": {
    "pop": {
      "description": "Pop up the toast",
      "href": "/things/toaster/actions/pop",
      "input": {
        "type": "number"
      }
    }
  },
  "description": "A web connected toaster",
  "events": {
    "ready": {
      "description": "Your toast is ready!",
      "href": "/things/toaster/events/ready"
    }
  },
  "links": [
    {
      "href": "/things/toaster/properties",
      "mediaType": "application/json",
      "rel": "properties"
    },
    {
      "href": "/things/toaster/events",
      "mediaType": "application/json",
      "rel": "events"
    },
    {
      "href": "/things/toaster/actions",
      "mediaType": "application/json",
      "rel": "actions"
    }
  ],
  "name": "UnifiedThings Toaster",
  "properties": {
    "on": {
      "description": "Whether the toaster is currently heating bread",
      "href": "/things/toaster/properties/on",
      "type": "boolean"
    },
    "timeRemaining": {
      "href": "/things/toaster/properties/timeRemaining",
      "type": "number",
      "unit": "seconds"
    }
  },
  "type": "toaster"
}
  • Setting a thing property
$ curl localhost:3000/things/toaster/properties/on -XPUT -d '{"on": "true"}'

{
    "on": "true"
}
  • Getting a thing property
$ curl localhost:3000/things/toaster/properties/on

{
    "on": "true"
}
  • Requesting an action
$ curl localhost:3000/things/toaster/actions -XPOST -d '{"pop": {"input": 10}}'

{
  "pop": {
    "href": "/things/toaster/actions/pop/a4a4aec2-1fa2-4abf-ace7-86bdf8e6e47b",
    "input": 10,
    "status": "pending"
  }
}
  • Getting the actions queue
$ curl localhost:3000/things/toaster/actions

[
  {
    "pop": {
      "href": "/things/toaster/actions/pop/32ddeb33-bdc2-42d2-9bed-c5f5d0a2678a",
      "input": "12",
      "status": "completed",
      "timeCompleted": "2018-04-06 15:21:00.394353",
      "timeRequested": "2018-04-06 15:21:00.382574"
    }
  },
  {
    "pop": {
      "href": "/things/toaster/actions/pop/a4a4aec2-1fa2-4abf-ace7-86bdf8e6e47b",
      "input": "10",
      "status": "completed",
      "timeCompleted": "2018-04-06 15:20:21.675748",
      "timeRequested": "2018-04-06 15:20:21.665374"
    }
  }
]
  • Getting the action status
$ curl localhost:3000/things/toaster/actions/pop/32ddeb33-bdc2-42d2-9bed-c5f5d0a2678a

{
  "pop": {
    "href": "/things/toaster/actions/pop/32ddeb33-bdc2-42d2-9bed-c5f5d0a2678a",
    "input": "12",
    "status": "completed",
    "timeCompleted": "2018-04-06 15:21:00.394353",
    "timeRequested": "2018-04-06 15:21:00.382574"
  }
}
  • Pushing an event
$ curl localhost:3000/things/toaster/events -XPOST -d '{"ready": {"data": true}}'

{
  "ready": {
    "data": true
  }
}
  • Getting the event log
$ curl localhost:3000/things/toaster/events

[
  {
    "ready": {
      "data": "True",
      "timestamp": "2018-04-06 15:23:08.115557"
    }
  }
]