The Flic Hub Studio lets you connect to your Flic Hub using our online IDE to write packages that can run on the hub.
Packages are written in Javascript and are stored locally on the hub.
The connection between the online IDE and the Flic Hub happens locally over a websocket so to connect you need to be on the same LAN as the Hub and connect using its local IP address. The local IP address can be found by connecting to the hub using the Flic app and check under Settings, or by finding it through your routers admin interface.
To access the Flic Hub Studio, please follow these steps:
Device Managed Hubs are not automatically discovered by Flic Hub Studio. You need to enter the Hub's IP address directly.
Older Hub firmware might not support the WebRTC security used by recent Chrome versions. Updating the Hub firmware is recommended. To do so, make sure a newer firmware is assigned to the hub through Device Manager, then trigger a firmware update with the Flic app or by pressing the pin hole button for 2-5 seconds. As a temporary alternative, disable WebRTC PQC for DTLS by opening chrome://flags/#webrtc-pqc-for-dtls in Chrome, relaunch the browser, and try again.
Any changes made to modules on a Device Managed Hub using Flic Hub Studio will eventually be overwritten by the Device Manager configuration.
The code you write on the hub are divided into packages. Each package has a main.js which will be executed when the package runs.
Different hub features, such as button management, network, http etc, are accessed through modules.
You can include a module using the require(); semantics:
var buttonManager = require("buttons");
More information about available modules can be fount in the Flic Hub Studio Module Documentation.
You can choose to run packages with or without the "Restart after crash" flag.
This flag will ensure that the package is re-run after a crash or boot.
A simple command prompt is available through the online IDE with some simple commands to manage buttons and WiFi configurations.
List all buttons and print all the information in JSON format to the console:
const buttonManager = require("buttons");
let buttons = buttonManager.getButtons();
for (var i = 0; i < buttons.length; i++) {
let button = buttons[i];
console.log(JSON.stringify(button));
}
Listen for click events and send a request with button serial number and click type to specified endpoint:
const buttonManager = require("buttons");
const http = require("http");
const url = "YOUR_URL_HERE";
buttonManager.on("buttonSingleOrDoubleClickOrHold", function(obj) {
let button = buttonManager.getButton(obj.bdaddr);
let clickType = obj.isSingleClick ? "click" : obj.isDoubleClick ? "double_click" : "hold";
http.makeRequest({
url: url,
method: "POST",
headers: {"Content-Type": "application/json"},
content: JSON.stringify({"serial-number": button.serialNumber, "click-type": clickType}),
}, function(err, res) {
console.log("request status: ", err, res);
});
});
console.log("Started");
Toggle a Matter On/Off device on button click
const buttonManager = require("buttons");
const matter = require('matter');
let nodeId = "MATER_NODE_ID";
let endpointId = "MATER_ENDPOINT_ID";
buttonManager.on("buttonSingleOrDoubleClickOrHold", function(obj) {
matter.sendCommand(nodeId, endpointId, "On/Off", "Toggle", {}, (error, response) => console.log(JSON.stringify(error) + ", " + JSON.stringify(response))); // Toggle
});
console.log("Started");