Pleemans
Published © Apache-2.0

Connect Flic Buttons on AllThingsTalk Maker

Connecting bluetooth Flic buttons to AllThingsTalk Maker using a Raspberry Pi

IntermediateFull instructions provided2 hours2,069
Connect Flic Buttons on AllThingsTalk Maker

Things used in this project

Story

Read more

Code

Node-RED Flow

JavaScript
[
    {
        "id": "20b8d8ac.7596a8",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "2a52c35a.a9600c",
        "type": "flic",
        "z": "20b8d8ac.7596a8",
        "name": "80:e4:da:76:e1:2f Button Down",
        "button": "6cae9ab2.34d1e4",
        "event": "ButtonDown",
        "topic": "flic",
        "x": 170,
        "y": 160,
        "wires": [
            [
                "c5f0c22b.8df1e",
                "8882bb0b.408658"
            ]
        ]
    },
    {
        "id": "8882bb0b.408658",
        "type": "debug",
        "z": "20b8d8ac.7596a8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 470,
        "y": 60,
        "wires": []
    },
    {
        "id": "c5f0c22b.8df1e",
        "type": "change",
        "z": "20b8d8ac.7596a8",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload.deviceId",
                "pt": "msg",
                "from": ":",
                "fromt": "str",
                "to": "",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 530,
        "y": 180,
        "wires": [
            [
                "5ece2c30.551ca4"
            ]
        ]
    },
    {
        "id": "5ece2c30.551ca4",
        "type": "function",
        "z": "20b8d8ac.7596a8",
        "name": "MQTT Topic constructor",
        "func": "var gatewayId = \"<enter your gateway ID here>\"\nvar deviceId = msg.payload.deviceId\nmsg.topic = \"gateway/\" + gatewayId + \"/device/\" + deviceId + \"/asset/Button/state\"\nif (msg.payload.clickType === \"ButtonDown\") {\n   msg.payload = {\"value\": true }\n}\nif (msg.payload.clickType === \"ButtonUp\") {\n   msg.payload = {\"value\": false }\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 670,
        "y": 260,
        "wires": [
            [
                "a244eb78.81edd8"
            ]
        ]
    },
    {
        "id": "a244eb78.81edd8",
        "type": "mqtt out",
        "z": "20b8d8ac.7596a8",
        "name": "",
        "topic": "",
        "qos": "0",
        "retain": "false",
        "broker": "b03f7b5.87b8788",
        "x": 830,
        "y": 140,
        "wires": []
    },
    {
        "id": "e30db9a2.2b6718",
        "type": "flic",
        "z": "20b8d8ac.7596a8",
        "name": "80:e4:da:76:e1:2f Button Up",
        "button": "6cae9ab2.34d1e4",
        "event": "ButtonUp",
        "topic": "flic",
        "x": 160,
        "y": 220,
        "wires": [
            [
                "c5f0c22b.8df1e",
                "8882bb0b.408658"
            ]
        ]
    },
    {
        "id": "6cae9ab2.34d1e4",
        "type": "Flic Button",
        "z": "",
        "address": "80:e4:da:76:e1:2f",
        "name": "Flicbutton",
        "host": "127.0.0.1",
        "port": "5551"
    },
    {
        "id": "b03f7b5.87b8788",
        "type": "mqtt-broker",
        "z": "20b8d8ac.7596a8",
        "name": "ATTALK",
        "broker": "api.allthingstalk.io",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": true,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]

Credits

Pleemans

Pleemans

7 projects • 23 followers
IoT enthusiast and Founder of AllThingsTalk, an open IoT platform for makers and developers

Comments