Christian Moll
Published © CC BY

Using Kniwwelino with Node-RED and your own MQTT Broker

This project shows you how to use a custom MQTT broker and Node-RED with Kniwwelino to build a YouTube subscription counter.

BeginnerFull instructions provided1.5 hours568
Using Kniwwelino with Node-RED and your own MQTT Broker

Things used in this project

Story

Read more

Code

Node-RED flow to show MQTT messages and extract youtube channel subscriptions

JSON
Import to your Node-RED
[
    {
        "id": "8b734ea8.52eea",
        "type": "mqtt in",
        "z": "8a3ae97e.aee128",
        "name": "",
        "topic": "youtube/#",
        "qos": "2",
        "datatype": "auto",
        "broker": "94fcb17f.c439a",
        "x": 360,
        "y": 100,
        "wires": [
            [
                "e9fd5ba9.f73398"
            ]
        ]
    },
    {
        "id": "e9fd5ba9.f73398",
        "type": "debug",
        "z": "8a3ae97e.aee128",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 570,
        "y": 100,
        "wires": []
    },
    {
        "id": "ae42d176.b91b7",
        "type": "http request",
        "z": "8a3ae97e.aee128",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": false,
        "url": "https://www.youtube.com/channel/UCZwwe6NYPhCnPdZ6Unls7-g",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 1300,
        "y": 100,
        "wires": [
            [
                "dbf7a66a.1e97f8"
            ]
        ]
    },
    {
        "id": "3597b863.220bf8",
        "type": "inject",
        "z": "8a3ae97e.aee128",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "*/5 6-15 * * 1,2,3,4,5",
        "once": true,
        "onceDelay": 0.1,
        "x": 1130,
        "y": 100,
        "wires": [
            [
                "ae42d176.b91b7"
            ]
        ]
    },
    {
        "id": "dbf7a66a.1e97f8",
        "type": "html",
        "z": "8a3ae97e.aee128",
        "name": "subscribers",
        "property": "payload",
        "outproperty": "payload",
        "tag": "span[class=yt-subscription-button-subscriber-count-branded-horizontal\\ subscribed\\ yt-uix-tooltip]",
        "ret": "html",
        "as": "multi",
        "x": 1470,
        "y": 100,
        "wires": [
            [
                "57b7c6ae.62e488",
                "b56b7d37.f5bce"
            ]
        ]
    },
    {
        "id": "57b7c6ae.62e488",
        "type": "debug",
        "z": "8a3ae97e.aee128",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 1710,
        "y": 60,
        "wires": []
    },
    {
        "id": "b56b7d37.f5bce",
        "type": "mqtt out",
        "z": "8a3ae97e.aee128",
        "name": "",
        "topic": "youtube/MATRIX/TEXT",
        "qos": "",
        "retain": "",
        "broker": "94fcb17f.c439a",
        "x": 1780,
        "y": 120,
        "wires": []
    },
    {
        "id": "94fcb17f.c439a",
        "type": "mqtt-broker",
        "z": "",
        "name": "",
        "broker": "localhost",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]

Kniwwelino YouTube counter

XML
Please open this code in https://code.kniwwelino.lu in order to upload it on your Kniwwelino.
Adapt the block to your MQTT broker settings.
<xml xmlns="http://www.w3.org/1999/xhtml">
  <block type="kniwwelino_MQTTsetGroup" id="iwIS@yT`|ZWom7`LKq(l" x="110" y="57">
    <field name="GROUP">youtube</field>
  </block>
  <block type="kniwwelino_MQTTsetUserBroker" id="PXJxJhCk*Wj/4/+,,,.i" x="111" y="88">
    <field name="BROKER">192.168.0.111</field>
    <field name="PORT">1883</field>
    <field name="USER">myUser</field>
    <field name="PASSWORD">myPassword</field>
  </block>
  <block type="kniwwelino_MQTTconnectRGB" id="Xy7xmV9fR=`[!YCMUBUP" x="113" y="121"></block>
  <block type="kniwwelino_MQTTconnectMATRIX" id="mI*9w.~g/6[J0E~!)(T[" x="384" y="123"></block>
  <block type="arduino_functions_setup" id="?@}vWpL7F3LVasAakMrx" x="26" y="259">
    <statement name="SETUP_FUNC">
      <block type="kniwwelino_MATRIXdrawIcon" id="z|O_2XS,QToP3}nuK4[8">
        <value name="ICON">
          <block type="kniwwelino_MATRIXdrawIconCreator" id="(B?I:UH3jE.sO8mzkn]^">
            <field name="1_1">FALSE</field>
            <field name="1_2">FALSE</field>
            <field name="1_3">FALSE</field>
            <field name="1_4">FALSE</field>
            <field name="1_5">FALSE</field>
            <field name="2_1">FALSE</field>
            <field name="2_2">TRUE</field>
            <field name="2_3">FALSE</field>
            <field name="2_4">TRUE</field>
            <field name="2_5">FALSE</field>
            <field name="3_1">FALSE</field>
            <field name="3_2">FALSE</field>
            <field name="3_3">FALSE</field>
            <field name="3_4">FALSE</field>
            <field name="3_5">FALSE</field>
            <field name="4_1">TRUE</field>
            <field name="4_2">FALSE</field>
            <field name="4_3">FALSE</field>
            <field name="4_4">FALSE</field>
            <field name="4_5">TRUE</field>
            <field name="5_1">FALSE</field>
            <field name="5_2">TRUE</field>
            <field name="5_3">TRUE</field>
            <field name="5_4">TRUE</field>
            <field name="5_5">FALSE</field>
          </block>
        </value>
      </block>
    </statement>
  </block>
  <block type="arduino_functions_loop" id="PXoI52Z{V}_)%#~m7{Lo" x="424" y="252">
    <statement name="LOOP_FUNC">
      <block type="controls_if" id="wc@o%_nsuENTf4)/pAPe">
        <mutation elseif="2"></mutation>
        <value name="IF0">
          <block type="kniwwelino_BUTTONclicked" id="iq!g)q+3eJ:K7?9#r)65">
            <field name="BUTTON">AandB</field>
          </block>
        </value>
        <statement name="DO0">
          <block type="kniwwelino_MQTTpublish" id="?Xzg/j[4HgfqxsE4u)Rt">
            <value name="MESSAGE">
              <shadow type="text" id="SkIDcl~mHRiB6qT6mw5_">
                <field name="TEXT">1</field>
              </shadow>
            </value>
            <value name="TOPIC">
              <shadow type="text" id="hV~@s,mZt7VbHKon29qw">
                <field name="TEXT">button/3</field>
              </shadow>
            </value>
            <next>
              <block type="kniwwelino_MATRIXwrite" id="cnwUqIPVC.C9rI14SBav">
                <field name="TYPE">ONCE</field>
                <value name="TEXT">
                  <shadow type="text" id="}m%1^AT?`]1t6(mLa*K5">
                    <field name="TEXT">Hello Kniwwelino</field>
                  </shadow>
                  <block type="kniwwelino_getSSID" id="8:{w{zSg-R}i[;z`E-VT"></block>
                </value>
              </block>
            </next>
          </block>
        </statement>
        <value name="IF1">
          <block type="kniwwelino_BUTTONclicked" id="kHV9GV|pOFw0lqJO!kw?">
            <field name="BUTTON">A</field>
          </block>
        </value>
        <statement name="DO1">
          <block type="kniwwelino_MQTTpublish" id="|UGo}K2j/jZwC`qx`WR{">
            <value name="MESSAGE">
              <shadow type="text" id="|a5xyVM-PTex-SlzpH4b">
                <field name="TEXT">1</field>
              </shadow>
            </value>
            <value name="TOPIC">
              <shadow type="text" id="MXNQStofPd*{E|SGS*p.">
                <field name="TEXT">button/1</field>
              </shadow>
            </value>
          </block>
        </statement>
        <value name="IF2">
          <block type="kniwwelino_BUTTONclicked" id="eGBGz/(y-jLKkr603ll_">
            <field name="BUTTON">B</field>
          </block>
        </value>
        <statement name="DO2">
          <block type="kniwwelino_MQTTpublish" id="h2veRYxXp-k#5OTpw}iT">
            <value name="MESSAGE">
              <shadow type="text" id="@F[[02xt@IRJss_gcrH!">
                <field name="TEXT">1</field>
              </shadow>
            </value>
            <value name="TOPIC">
              <shadow type="text" id="[^Catu*3O;9Cvz+8H@2O">
                <field name="TEXT">button/2</field>
              </shadow>
            </value>
          </block>
        </statement>
      </block>
    </statement>
  </block>
</xml>

Credits

Christian Moll
3 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.