Qb method node

This page documents an earlier firmware release. Read this page for the latest release

The Blickfeld Qb Method node of Blickfeld Flow calls methods of the gRPC API. It addresses either the sensor the flow runs on or other sensors in the network, and the request and the response are defined and processed as messages within the flow.

The node editor

Drag a blickfeld-qb2-method node into a flow and double-click it to open the editor.

Edit dialog of a blickfeld-qb2-method node named Event/Stream with Connection Local device, Method percept_processing.Event/Stream, Request, Response, Response Format JSON, Timeout, Auto reconnect server-side streams on error and Reconnect interval
Figure 1. The Blickfeld Qb Method node editor

Connect to a sensor

Connection selects how the node reaches the sensor:

Connection What it does

Local device

The default. Connects to the sensor the flow runs on, as qb2.local, a name that only resolves on the sensor itself. No key is needed.

Device configuration

Uses a shared blickfeld-device configuration node. Use it for another sensor in the network, or when several method nodes talk to the same sensor.

Legacy configuration

Shows the fields IP or FQDN and Key on the method node itself, for older flows.

With Local device and Legacy configuration, the incoming message can override the connection:

  • msg.fqdn addresses another sensor instead of the one the flow runs on. With Legacy configuration it applies only while IP or FQDN is empty.

  • msg.key sets the application key.

With Device configuration, the node ignores both.

When addressing another sensor in the network, provide an application key of that sensor, in a blickfeld-device node or in msg.key.

The blickfeld-device configuration node

A blickfeld-device node stores the connection details of one sensor, which any number of method nodes can use. Add one from the Device field of a method node (select Add new blickfeld-device…​ and click Pencil), or from Menu > Configuration nodes.

Dialog to add a blickfeld-device config node with Name, IP or FQDN, Serial, Key with a Test button and Auth timeout, and below them Username, Password and Generate application key
Figure 2. The blickfeld-device configuration node
Setting What it does Default

IP or FQDN

The address of the sensor. When it is set, the node connects and reads the Serial of the sensor.

Empty

Serial

Filled in from the sensor once IP or FQDN is set; there is nothing to enter. The node checks the TLS identity of the sensor with it.

Detected

Key

The application key, stored as an encrypted credential and never written to exported flows. Click Test to check it; the node also checks it when the dialog opens.

Empty

Auth timeout

How long to wait for the sign-in, in seconds.

10

To get an application key, see Create an application key.

Select a method

Choose the API method in the Method field (for example diagnostics.Health/Get). Below the field, a short summary shows the call style, the description of the method and a View request / response schema link that opens the full schema in a dialog. The call style is Single request / response, Server stream (multiple responses), Client stream (multiple requests) or Bi-directional stream.

View the request and response schema

The schema of the selected method is available in the Help sidebar (the Help tab of the sidebar, or Ctrl+H), under API reference at the end of the help of the node, or in a dialog through the View request / response schema link. It lists the nested request and response fields with their types, enum values, repeated/oneof markers and the documentation of each field from the protocol.

Help sidebar with the API reference of diagnostics.Health/Get: the description of the method and the nested fields of the response with their types and enum values
Figure 3. The method schema in the Help sidebar

Build the request interactively

With Request set to JSON, the API reference becomes interactive: every request field gets a ⊕ icon. Click it to insert the field at its full path into the request JSON, with any parent objects and a placeholder value. Assemble the request by clicking fields, then fine-tune the JSON. The full-screen JSON editor is the recommended view for this: open it with the …​ button of the Request field, and each field you click appears in it right away.

Help sidebar with the API reference of percept_processing.Event/Stream: the request fields id and reverse, each with a plus icon in front of it
Figure 4. Interactive request builder in the Help sidebar

Map the request and the response

Setting What it does Default

Request

What the node sends as the request:

  • Forward complete message: msg.payload as the whole request.

  • JSON: a fixed JSON value set on the node, see Build the request interactively.

  • request. with a field path: msg.payload in that request field.

A method without request fields offers only Empty request.

Response

What the node puts into msg.payload of the outgoing message: one field of the response with response. and a field path, or the whole response with Forward complete message.

Response Format

JSON, Protobuf-ts Object or Protobuf Binary Buffer.

JSON

Timeout

In seconds, for calls that are not streams. Empty for server-side streams.

10

With the Response Format JSON, the whole response leaves out every field that has its default value, such as false, 0 or an empty text. A flow that reads msg.payload from Forward complete message has to treat a missing field as that default. With response. and a field path, the field is included even when it has its default value.

Test a method in the editor

Click Test method to run the call against the sensor without deploying the flow. The dialog shows the response or the error. This works for self-contained calls, whose request is empty or set here as JSON; a call that needs an incoming msg cannot be tested on its own. For a stream, the dialog shows the first message.

Edit dialog of a method node with Method diagnostics.Health/Get, and below Test method the result Success and the response as JSON
Figure 5. Testing a method in the editor

Trigger with a button

For a self-contained call, tick Show a trigger button on the node (replaces the input). The node then shows a button on the canvas, like an inject node, that runs the deployed call, for example to read the health or toggle a setting.

Method node diagnostics.Health/Get on the canvas with a button at its left instead of an input, wired to a debug node
Figure 6. A method node with a trigger button

Streaming and auto-reconnect

Server-side streaming methods (such as Health/Watch or Event/Stream) stay open and emit one message per received item.

To stop a running stream, send a message with msg.reset set to true, for example from an inject node. The node ends the call and does not reconnect.

Auto reconnect server-side streams on error keeps a stream alive: after an error or an unexpected end, the node tries to restore the connection at the interval set in Reconnect interval. It still reports the error of every failed attempt to a connected catch node and in the status of the node. The setting is on by default and appears only when a server-streaming method is selected.

Examples

To import an example flow of the node:

  1. Open the Import dialog: Menu at the top right > Import, or Ctrl+I.

  2. Select the Examples tab on the left.

  3. Expand flows > node-red-contrib-blickfeld-qb2-method and choose an example.

  4. Choose current flow or new flow and click Import.

Import nodes dialog with the Examples tab open, events_fetching selected under flows and node-red-contrib-blickfeld-qb2-method, and Import to set to new flow
Figure 7. Importing an example flow from the Examples tab
events_fetching

Imports the flow Fetch perception events, which streams the perception events with auto reconnect.

The Fetch perception events flow has an inject node that starts the stream, the method node, and a catch node that reports reconnect errors:

Canvas with a comment Fetch perception events, an inject node Start streaming wired to the method node Event/Stream and a debug node event, and a catch node stream errors wired to a debug node reconnect error
Figure 8. The imported events-fetching example flow

Its JSON:

[
    {"id":"ex_events_inject","type":"inject","z":"f","name":"Start streaming","props":[],"once":true,"onceDelay":0.5,"topic":"events","x":200,"y":120,"wires":[["ex_events_method"]]},
    {"id":"ex_events_method","type":"blickfeld-qb2-method","z":"f","name":"Event/Stream","device":"","fqdn":"qb2.local","key":"","method":"/blickfeld.percept_processing.services.Event/Stream","request":"","request-type":"*","response":"","response-type":"*","response-format":"json","timeout":"","autoReconnect":true,"reconnectInterval":"5","x":430,"y":120,"wires":[["ex_events_debug"]]},
    {"id":"ex_events_debug","type":"debug","z":"f","name":"event","active":true,"tosidebar":true,"complete":"payload","x":650,"y":120,"wires":[]},
    {"id":"ex_events_catch","type":"catch","z":"f","name":"stream errors","scope":["ex_events_method"],"uncaught":false,"x":210,"y":200,"wires":[["ex_events_error"]]},
    {"id":"ex_events_error","type":"debug","z":"f","name":"reconnect error","active":true,"tosidebar":true,"complete":"error","x":440,"y":200,"wires":[]}
]

References