FD1 Client Protocol

Fieldpine FD1 Temperature Example

This example shows a very simple web page opening an Fd1 firehose and subscribing to temperature sensor messages. The server connected too is a Fieldpine test server and it has a real temperature sensor nearby broadcasting over bluetooth. While this isn't a common retail requirement, this serves as an excellent example of receiving realtime data over a web socket.

View Live

This very simple example opens a websocket and then requests a firehose

FdlServerSocket.send(JSON.stringify({
    a: "fd1.firehose.open_firehose",
    rq: "dev",
    v: {
        event: "device.event"
    },
    q: {
        "_sc":"device.bluetooth.announcement",
        "temp(>=)": -90
    }
}));

The two lines in the "q" object specify that the server should only send us bluetooth announcements, and the temperture should be above -90

An onmessage handler receives the messages and updates the web page

Use "view source" to see the complete code. It is all inside a standalone HTML file to keep things simple. You can also use the browser debugger to view the individual messages received over the websocket.