Monogram API
Search…
⌃K

Read Inputs

Now that the bundle is loaded into Creator, implement a way for your application to receive messages from Monogram.

WebSockets

To communicate with Monogram, your application must have to ability to connect to and receive data from a WebSocket server.
Here are some example WebSocket libraries:
Platform
Library
JavaScript
C/C++
Objective-C
C#
Qt

Connecting to Monogram

Monogram's WebSocket server is bound to localhost port 59177 when Creator is running.
Open a connection to the Monogram WebSocket Server. You can do this with a WebSocket test client. The URL must have the following format:
ws://localhost:59177/{App ID}/{Connection Name}
So MyPhotoEditor must open a WebSocket connection to
ws://localhost:59177/com.example.myphotoeditor/MyPhotoEditorConnection
Once the socket is open, Monogram sends input commands over this connection when modules assigned to your app's inputs are actuated.

Example Input Commands

Messages received over the socket are formatted in JSON. Most look like this.
On button press:
{ "input": "Import", "operation": "", "params": [] }
On dial rotation:
{ "input": "Likes", "operation": "+", "params": [1] }
{ "input": "Likes", "operation": "+", "params": [-1] }
On slider move:
{ "input": "Saturation", "operation": "=", "params": [42] }
On orbiter disc move:
{ "input": "Temperature", "operation": "+", "params": [1] }
The full input format is documented in Socket Protocol.

Example Read Code

The following JavaScript code is used in the sample myphotoeditor/index.html application to receive commands from Monogram.
var socket = new WebSocket('ws://localhost:59177/com.example.myphotoeditor/MyPhotoEditorConnection')
socket.addEventListener("message", function (event) {
var data = JSON.parse(event.data)
switch (data.input) {
case "Exposure":
handleExposure(data.operation, data.params)
break
// ...
case "Previous Photo":
previousPhoto()
break
}
})