Sign inSign up

ibebbs/xmasstar

By ibebbs

Updated almost 7 years ago

A containerized .NET Core controller for the ModMyPi Programmable Christmas Tree Star

Image
0

1.3K

ibebbs/xmasstar repository overview

Christmas Star vs .NET Core

A .NET Core controller for the ModMyPi Programmable Christmas Tree Star

Background

A while ago, I submitted this suggestion to the dotnet/iot repository on Github. My idea was too provide functionality that would allow a PC to remotely control the GPIO pins on a Raspberry Pi running the 'pigpiod' daemon. The suggestion was well received so I submitted this PR providing an initial implementation. This garnered some excellent feedback which, unfortunately, I haven't yet had a chance to implement so the PR is still pending.

Then, a week or so ago, The Pi Hut put the Raspberry Pi Christmas Tree Star up for sale at ~£7. As most who know me know will tell you, I'm all for any opportunity to add tech to... well.... pretty much anything so, as we were about to go purchase our (locally and responsibly grown) Xmas tree, I thought this would be a fun play-thing.

This repository shows how the functionality I added to the dotnet/iot repository can be used to remotely control this star.

Feel free to play. I would very much welcome any additional patterns for the star or suggestions for improvements.

Security

A quick note on security: When you enable remote connections on the Pi, connections can be made to the Pi without any authentication at all. Therefore please only use this approach on a private network; an internet connected, compromised Raspberry Pi can provide quite a comprehensive entry point to your network!

Solution

The solution is comprised of several projects:

Star.Core

This project provides a Star class which connects to the 'pigpiod' daemon running on a Rasperry Pi Zero at a specific IP address and provides a WriteAsync(uint frame) method for controlling the LED's on the star. The WriteAsync method converts the specified 32-bit unsigned integer into a collection of 25 pin assignements via bitmasking as shown below:

Bit3231302928272625242322212019181716151413121110987654321
BCMncncncncncncnc2524151823143417272210911561319261620211278

Such that a 32-bit value of '00000001010101010101010101010101' would result in every other LED on the Star being lit.

NOTE: As the Pigpio implementation isn't currently available in the Iot.Device.Bindings (due to the PR not being ready to merge) locally build assemblies have been included in the .\lib directory.

Star.Marching.Console & Star.Twinkle.Console

These two projects run as a console application and show how to use the Star.Core library to display patterns on Star.

Star.Mqtt.Console
Description

This project employs the generic host to reliably run a service from within a docker container. The service was designed to do two things:

  1. Display frames received from an MQTT broker (as a 4 byte buffer) on the star.
  2. Generate and display patterns on the star when no message has been received from MQTT for 10 seconds.

It can be configured by supplying the following environment variables:

Star:Pi:Host - The IP address of the Raspberry Pi broker running the 'pigpiod' daemon
Star:Pi:Port - The Port to connect to the Raspberry Pi on (defaults to 8888)
Star:Mqtt:Broker - The IP address of the MQTT broker to receive frames from
Star:Mqtt:Port - The Port to connect to the MQTT broker on (defaults to 1883)
Star:Mqtt:Topic - The Topic to receive frames from (defaults to 'home/xmastree')

Docker

A dockerfile is provides so that the Star.Mqtt.Console application can be run from with docker. It can be build by running the following command from the '$\src' directory (relative to repository root):

docker build -f .\Star.Mqtt.Console\Dockerfile -t star:latest .

And then run with the following command:

docker run -e Star:Pi:Host=[IPAddres of Pi] -e Star:Mqtt:Broker=[IP Address of Broker] star:latest

Alternatively a pre-build image can be pulled and run from dockerhub using the following:

docker run -e Star:Pi:Host=[IPAddres of Pi] -e Star:Mqtt:Broker=[IP Address] ibebbs/xmasstar:latest
Mqtt

To quickly test interaction with the Star I use the following Node-Red flow:

node-red

[
    {
        "id": "475a2d52.bc7ebc",
        "type": "inject",
        "z": "16ce54a.befcb2b",
        "name": "",
        "topic": "",
        "payload": "[0,0,0,0]",
        "payloadType": "bin",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 130,
        "y": 340,
        "wires": [
            [
                "3a547207.c894b6",
                "88005ec3.62baf"
            ]
        ]
    },
    {
        "id": "3a547207.c894b6",
        "type": "mqtt out",
        "z": "16ce54a.befcb2b",
        "name": "",
        "topic": "home/xmastree",
        "qos": "",
        "retain": "",
        "broker": "adea6257.de843",
        "x": 360,
        "y": 340,
        "wires": []
    },
    {
        "id": "88005ec3.62baf",
        "type": "debug",
        "z": "16ce54a.befcb2b",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "x": 340,
        "y": 420,
        "wires": []
    },
    {
        "id": "adea6257.de843",
        "type": "mqtt-broker",
        "z": "",
        "name": "Local",
        "broker": "192.168.1.24",
        "port": "1883",
        "clientid": "NodeRed",
        "usetls": false,
        "compatmode": true,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]

Tag summary

Content type

Image

Digest

Size

74 MB

Last updated

almost 7 years ago

docker pull ibebbs/xmasstar