wozzit

A simple communications system for the Internet of Things

View the Project on GitHub mrpjevans/wozzit

Wozzit Message Object Reference

Requirements

External Dependancies

Creating an Instance

import wozzit

msg = wozzit.Message([json])

Properties

Message.protocol

Array Default: [0, 0, 1]

A three-element array representing the Wozzit protocol version in semantic versioning format (symver). The current protocol version is 0.0.1 so the content of Message.protocol is [0, 0, 1] by default.

The protocol is used by the server to determine whether it can process the message. This will allow for changes in the Wozzit Message specification in future.

The object has internal values that determine what version of message it can support, so may reject a message when deserialising if the protocol given is not supported.

Message.schema

String Default: “wozzit.null”

A string in reverse-DNS notation determining what the message contains. It is expected that you use your own domain/identity as the prefix to any types of schemas you create. This is to try and avoid collisions where we have multiple type of messages sharing the same schema name. So, if you have ‘example.org’ then prefix all your schema names with ‘org.example.’. the only exception is the prefix ‘wozzit.’ which is reserved for system use.

Message.version

Int Default: 1

As schemas can change, version is provided to specify which version of the schema is being implemented in the message. The header is mandatory but it’s up to you how you use it so long as it remains an integer.

Message.ip

String

Only populated in received messages. This property is set by the receiving server so you check from where the message was sent. This is to allow filtering by IP address if required.

Message.psk

String

A pre-shared key. You can add security to your messages by ensuring each device transmits the PSK with their messages. You can then add it as a match requirement for incoming messages. There are no constraints on what is contained.

Message.payload

Variant

The actual content of the message. The content, whether it be a number, string or dictionary, is determined by the rules laid down in the schema. If a schema states that the payload content is either a simple True or False, it is reasonable for you to only check for that. There’s no reason why a payload couldn’t contain much more complex information such as nested database records or encoded binary data.

Methods

Message.toDict()

Returns the message serialised into a Python dictionary

Message.toJSON()

Returns the message serialised into JavaScript object notation.

Message.loads(data, [ip])

Deserialise either a Python Dictionary or JSON message into the object. Returns either an ‘wozzit.error’ message object or True. The ip argument is for server use.

Message.send(to)

Not using a server instance? This shortcut allows you to send the current message to another server. to must be the full URL including port. Returns a requests response object.

Examples

Create a Wozzit Message and send it to a server.

import wozzit

msg = wozzit.Message()
msg.schema = "com.mydomainname.colours"
msg.payload = "green"
msg.send("http://192.168.0.2:10207/")

Receive a message and parse it

import wozzit

def incoming(json):
	msg = wozzit.Message(json)
	if msg.schema == "com.mydomainname.colours"
		print "Today's colour is " + msg.payload

A more complicated payload and server

import wozzit

msg = wozzit.Message()
svr = wozzit.Server()

msg.schema = "com.mydomainname.user"
msg.payload = {
	"username": "john",
	"firstName": "John",
	"secondName": "Doe"
}

svr.send(msg, "http://192.168.0.2:10207/")