It's less about building a YouTube counter, but more about how to use an own MQTT broker with Kniwwelino. By default all the MQTT messages are send to the MQTT broker of Kniwwelino in a kind of sandbox. All topics for messages from users are normally prefixed by a kniwwelino/. You can define your own prefix-topic which is put right after the kniwwelino/, but you are still sending your messages to the sandbox. With the "Use MQTT broker at host"-Block the possibility to use your own broker is introduced to the Visual Programming Platform of Kniwwelino. You have now the possibility to install a Raspbery Pi with Mosquitto and Node-RED to keep your messages in-house and enables you to connect your Kniwwelino to the hole world of IoT.
As an easy example we build here a simple YouTube subscription counter. The data displayed on the Kniwwelino's LED matrix is harvested by a simple Node-RED flow from YouTube. As well the button events for button A, B and the combination of buttan A and B are send as well to the topic youtube/button/#
.
First you will need a Raspberry Pi with a SD card loaded with Raspbian. You can create it easily prepare it with Balena Etcher. Create the a file called ssh
in the boot partition for your SD card, to enable the ssh server on your Raspberry. Connect it by cable or WiFi to your home network.
Installing Mosquitto as MQTT broker on Raspberry Pi is quiet simple:
sudo apt-get install mosquitto
I will not go into details about installing Node-RED on Raspberry Pi, as it is already there in the Desktop version of Raspbian. And for installing it from scratch you should read the official instructions.
As a summary:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
sudo systemctl enable nodered.service
sudo reboot
You can access your Node-RED instance now by an other PC in your network via the browser on the URL IP-of-Raspberry:1880
With the Kniwwelino sketch that you can open the Visual Programming Platform, you can program the basic functionality to send and receive MQTT messages to your broker. Just replace in the broker block the IP by the one of your Raspberry. Username and password can be left as they are on a standard installation of mosquitto.
Import the flow attached to this write-up into your Node-RED then you will get 2 short flows. The pink MQTT nodes will have red dot after import, that because you have to configure your broker first. The first flow is to receive everything from the Kniwwelino.
After deploying the flow you should see in the debug messages something like this after pressing a button on the Kniwwelino:
The second part of the flow, does the magic. It requests every 5 minutes the YouTube channel of Kniwwelino and extracts the contend of the span with the class="yt-subscription-button-subscriber-count-branded-horizontal subscribed yt-uix-tooltip" you need to escape the spaces in the class by \
to use several classes. Finally the MQTT node sends the extracted number to the LED matrix of the Kniwwlino.
Now you can tinker around with the incoming messages from the buttons and the possibilities of Node-RED... ;-)
Build an enclosureI used the lower part of an old iPad box to build a "picture frame" for the YouTube counter.
To power the Kniwwelino I added Micro-USB breakout board in the back of the box and fixed it with a substantial blob of hot glue.
To make the front nice I printed the logos on a nice sheet of photo inkjet paper and laminated it with self adhesive film. To mount the Kniwwelino I glues a Kniwwelino shell on it.
After bringing the cables from the Micro-USB breakout to the front. I soldered them to the battery connector and snapped the Kniwwelino into the shell.
Finally doneWe know there is not much now in the YouTube channel of Kniwwelino, but if you subscribe we will see it within 5 minutes ;-)
Comments
Please log in or sign up to comment.