Category: Fun and Games

  • Dad Status Indicator

    Dad Status Indicator

    It’s April, 2020. Since mid-March we have been told to work exclusively from home. Schooling has moved to ‘distance learning.’ Statewide ‘stay-at-home’ orders have been issued across the country and beyond. This is COVID-19 and the new realities facing ours and every culture worldwide.

    How do I respond? Build something.

    Working from home isn’t new to me, but WFH with all my kids also in the house is a totally different dynamic. And with most of my workday spent interacting with my coworkers via web calls, the need for some aspect of privacy is more important than ever.

    Hence, the Dad Status indicator.

    A simple way to show my family whether or not I am available to solve their problem, hear their tale of woe about the terrible thing their sibling did, or make lunch.

    The Dad Status Indicator (DSI) is a simple IoT rig using a Particle Photon and a couple colored LEDs. I also put together a quick web-app so I can toggle the status from my browser or phone.

    Materials

    • Picture frame
    • foam core
    • colored card stock
    • 1 Particle Photon
    • breadboard
    • 1 RED LED
    • 1 GREEN LED
    • LED holders
    • 1 2.2k resistor
    • 18 gauge wire

    After printing the status message and text on to the card stock, I cut the foam-core to size to fit right in the picture frame. The card stock panels are then glued to the foam core.

    I used a nailset to punch the holes through for the LEDs to be inserted.

    There is no glass on the frame, mostly due to how the LEDs project out a bit.

    Wiring

    I used 2 digital pins on the Photon for the LEDs, and put the resistor inline with GND. Remember with LEDs the short leg is GND and the long leg is power.

    Code

    Particle is largely an event based platform, so subscribing to an event stream is pretty straightforward.

    Subscribe

    Here’s the Firmware code used to receive messages from the event topic and act accordingly:

    // Daddy status indicator
    
    int greenLed = D0; 
    
    int redLed = D3; 
    
    void setup() {
      #if defined(DEBUG_BUILD)
        Mesh.off();
        BLE.off();
      #endif
    
      // init pins
      pinMode(greenLed, OUTPUT);
      pinMode(redLed, OUTPUT);
      
      // subscripbe for events  
      Particle.subscribe("daddy/status", statusHandler);
      
      // init status as available
      digitalWrite(redLed, LOW);
      digitalWrite(greenLed, HIGH);
    
    }
    
    // loop method not needed
    void loop() {
    }
    
    
    // event subsription handler
    void statusHandler(String event, String data) {
        if (data == "available")
        {
            digitalWrite(redLed, LOW);
            digitalWrite(greenLed, HIGH);
        }
        else if (data == "occupied") 
        { 
            digitalWrite(redLed, HIGH);
            digitalWrite(greenLed, LOW);
        }
    }
    

    Since the events are published using the Particle API, you do need to subscribe using the ALL_DEVICES parameter, and publish the event as a Public event.

    More information about the Particle.subscribe() usage can be found on the Particle Docs site.

    Publish

    To publish the events, I’m using the REST API provided by Particle. You need to generate an access token (I used the Particle CLI tool for this) and include that in your API Post.

    Here’s the bit of Javascript used to publish to the API

    var available = 1;
    var occupied = 0;
    
    var apiUrl = "https://api.particle.io/v1/devices/events";
    var token = "[[insert Particle access Token here]]";
    
    function UpdateAvailability(state) {
        var data = {
            name: "daddy/status",
            data: state ? "available" : "occupied",
            private: "false",
            ttl: "60"
        };
    
        fetch(apiUrl, {
                method: 'POST', // or 'PUT'
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': 'Bearer ' + token
                },
                body: JSON.stringify(data),
            })
            .then((response) => response.json())
            .then((data) => {
                console.log('Success:', data);
                WriteSuccess(state);
            })
            .catch((error) => {
                console.error('Error:', error);
            });
    }
    
    function WriteSuccess(state) {
        var feed = document.querySelector("#messages");
    
        let newEl = document.createElement('li');
        newEl.classList.add('list-group-item', 'text-white');
        newEl.classList.add(state ? 'bg-success' : 'bg-danger');
        newEl.innerText = 'Status set to ' + (state ? 'available' : 'occupied') + ' at ' + new Date().toLocaleString();
        feed.prepend(newEl);
    }

    After each post, I am displaying a status message in a feed.

    Web app

    The web app is super simple. Just a couple buttons to trigger the post and a feed showing the history.

    As the buttons are clicked you can see the message list update.

    All the code for this project can be found on Github at https://github.com/smithderekm/daddy-status-indicator

    Future Enhancements

    Now that the foundation is set, we can build upon it.

    • Use Dash button intercept to change status – single click for Occupied; double-click for Available;
    • Subscribe to Outlook calendar to get meetings feed and automatically update status at start and end of each meeting.

  • How to Use Cortana to control your Hue lights

    How to Use Cortana to control your Hue lights

    For Raleigh Code Camp this year I thought I’d stay in the realm of IoT, but also bring together some latest and greatest sweetness.  So my talk is titled “Hey Cortana, turn on the lights” and is a fun walkthrough of using Cortana, Universal Windows apps on Windows 10, the Azure Service Bus, and the Hue API to control your lighting with your voice.

    Here are all the reference articles I used in preparing the talk, and the slides, code, and video will be posted after the event.

    https://www.instructables.com/id/Use-RPi-Azure-and-Cortana-to-Automate-your-Home/?ALLSTEPS – this article was my inspiration and provides a good overview of the various elements of this solution.  I updated for Windows 10, and did not use a Raspberry Pi (though now with the RPi 2 and Windows 10 IoT Core it would not be that difficult.)

    https://talkitbr.com/2015/07/13/integrando-a-cortana-em-seu-aplicativo-windows-10/ – this one is in Portuguese, but still shows how to structure the Voice Command Definition file.

    https://dev.windows.com/en-us/speech – the official page for the Speech SDK from Microsoft

    https://msdn.microsoft.com/library/windows/apps/xaml/mt185598.aspx – Cortana Interactions – good overview with example for adding VCD to your Windows 10 app

    https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CortanaVoiceCommand/cs/AdventureWorks/Common – this is a sample project provided by Microsoft.  It seemed slightly out of date, but was a good reference.

    https://www.visualstudio.com/products/visual-studio-community-vs – Download page for Visual Studio 2015 Community edition.  You need VS2015 to do universal app development

    https://www.developers.meethue.com/ – the Phillips Hue developer site.  To get access to the full API docs you’ll need to register, but they have a getting started page here as well.

    https://github.com/Q42/Q42.HueApi– a .NET wrapper for the Hue API.  I didn’t use this directly, but modeled my own wrapper after it, and found it helpful for some of the JSON handling.

    https://azure.microsoft.com/en-us/documentation/articles/service-bus-dotnet-how-to-use-topics-subscriptions/ – article with code samples for interacting with the Azure Service Bus as a publish and subscriber

    https://blogs.recneps.org/post/Raspberry-Pi2-Iot-Core-and-Azure-Service-Bus – example of using the Service Bus REST api since the full SDK is not yet available for Windows 10

    https://msdn.microsoft.com/en-us/library/azure/hh690922.aspx – how to send messages using REST to the Service bus queue

    https://azure.microsoft.com/en-us/documentation/articles/service-bus-queues-topics-subscriptions/ – another overview of the Service Bus with code samples

     

     

  • Clash of the fictional companies

    Clash of the fictional companies

    What happens when your company is so large that one product group’s fictional company collides with another?  I found myself in this situation while prepping a demo for next week’s talk at the TriSPUG meeting.

    contoso+aw

    It made me feel the same way as when I see people mixing Nike shoes with Adidas shorts, or a Bulls cap with a Duke t-shirt.

    Thankfully, there are compile lists of Microsoft Fictional Companies available for your review.

  • Fun with Guids – SharePoint 2010 edition

    While working this week on a SharePoint 2010 installation,  I noticed the following entries in the web.config file.  Kind of a Guid easter egg.
    <Action id="0ff1ce14-0001-0002-0000-000000000000" sourceFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\config\webconfig.osrv.xml" />
    <Action id="0ff1ce14-0001-0003-0000-000000000000" sourceFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\config\webconfig.osrv.xml" />
    <Action id="0ff1ce14-0001-0004-0000-000000000000" sourceFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\config\webconfig.osrv.xml" />
    <Action id="0ff1ce14-0001-0005-0000-000000000000" sourceFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\config\webconfig.osrv.xml" />
    <Action id="0ff1ce14-0001-0006-0000-000000000000" sourceFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\config\webconfig.osrv.xml" />

    I have to imagine these are the 3am decisions that go on at Microsoft during the height of product development.