Friday, December 19, 2014

beakn v0.3 : DIY Lync Status Light with a RaspberryPi, .NET, Mono and MQTT

P-737I’m continuing to build out “beakn” my DIY Lync Status light. This is what I’m calling a “maker experience” project. I want to know what a maker goes through to build things so I’m building it with as many different platforms as possible. I’ve built it with Arduino and Netduino. Version 0.1 brought us a USB connected light. Version 0.2 introduced Ethernet and MQTT. Version 0.3 includes the following:

  • RaspberryPi running a .NET Console app via Mono
  • Upgraded my breadboard to a custom shield.

P-729P-731

Up until a few days ago I didn’t realize (or it didn’t click) that we could run .NET applications on RaspberryPi. I’ve heard about Mono, but haven’t really have a chance to play with it enough for it to sink in.  MS Open Tech released ConnectTheDots.io (a site to help people get up and going with IoT devices and Azure) this week and in that they have a RaspberryPiGateway – which uses a .NET console app and Mono. I saw that. It clicked - and of course I had to give it a try for beakn, which led to this post.


I just did a post on “How to run .NET on RaspberryPi with Mono”, so start there to see how things work and then come back to build the beakn. I also recommend that you read through the v0.1 and v0.2 posts before moving on so you can see how we got to this point.


The “beakn” has three main components

1. A Windows desktop application that sends messages to an MQTT broker when your Lync status changes

2. An MQTT broker to receive the Lync status messages

3. A hardware app that responds to MQTT messages and sets the right LED. Red=Busy, Yellow=Away, Green=Free


#1 and #2 above have changed very little with this version and #3 is now a RaspberryPi instead of an Arduino or Netduino.


Here’s how to get v0.3 setup on  your own.


Step 0: Get the beakn Hardware setup

Supplies

1. Ping Pong Ball

2. Cardboard box

3. Breadboard or protoboard. I’m now using a protoboard instead of breadboard.  Mainly because I was taking this thing apart so many times and it was become a pain to get everything setup each time.

4. RaspberryPi Model B or any model with Ethernet

5. 3 10mm LEDs

6. Some Jumper wires. Number of wires depends on how you build.

7. 220ohm resistor


Everything (except the RaspberryPi is the same as v0.2 so please read through that first.


Connect the LEDs like so:

Board Pin 12: Red

Board Pin 16: Yellow

Board Pin 18: Green

Put a 220ohm resistor on the cathode.  See photos and circuit diagram for possible setup.

beakn.raspberrypiP-733P-737

As you can see my cardboard box has seen better days, but you’ll likely need to cut a few more holes to get the Ethernet and USB Power connected.

P-743

Step 1: Install or Build the beakn desktop application.

You can install the desktop app directly from GitHub here: https://github.com/jonbgallant/beakn/releases/download/v0.3/beakn.v0.3.msi

Or you can get the source and build it yourself

https://github.com/jonbgallant/beakn/tree/master/desktop

Step 2: Modify the beakn.exe.config file

Open a CMD prompt as Administrator and navigate to the beakn install directory.

Change the MqttPairingCode to something unique. Remember what you set this to because you’ll need it later when you install RaspberryPi app.

Restart beakn.exe. You go into Task Manager and kill it first. Sorry not having a better solution here. Will fix at some point.

Step 3: Install the RaspberryPi .NET Console app.

Go through my “How to run .NET on RaspberryPi with Mono” post to get Mono and working on Pi.

You can either copy the compiled version onto your Pi from this zip: https://github.com/jonbgallant/beakn/releases/download/v0.3/beakn.raspberrypi.v0.3.zip


Or you can get the source and built yourself:

https://github.com/jonbgallant/beakn/tree/master/raspberrypi/beakn.raspberrypi


The console app that runs on the Pi is plain jane stock .NET without Xamarin Studio. It uses the M2Mqtt library to talk with the MQTT broker and Raspberry.IO.GeneralPurpose library to talk to the RaspberryPi pins.


Step 4: Modify the RaspberryPi beakn.exe.config file

Open the config file and change the MqttPairingCode to the same code you used in Step 2 above.  You can do this directly on the Pi with “sudo nano beakn.exe.config” or you can do on desktop and copy over.


Step 5: Run the RaspberryPi beakn.exe using this command.

sudo mono beakn.exe

You should see something like this:

image

Step 6: Make RaspberryPi beakn automatically start

Linux uses /etc/rc.local to list projects that automatically start when the Pi is started.

This link was helpful: http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs


Open rc.local to edit.

sudo nano /etc/rc.local

Add this line, your path to beakn.exe is where you copied it to – likely different than below.

sudo mono /home/pi/beakn/beakn.exe &



That’s it! You should now see your beakn change color when your Lync status changes.


Jon

How to run .NET on RaspberryPi with Mono

I’ve spent a good part of the last 15 years doing .NET development. When I joined IoT and started getting ramped up, I quickly discovered that it is largely an unmanaged non-.net non-Microsoft world. I’m having a blast learning everything, but I can’t get over the hunch that there are a bunch of devs out there who want to be makers, but aren’t because of the disconnect in technology. I’m positive this mindset is out there: “I want to be a maker, but I don’t know Linux, I don’t know c++ and I don’t have a ton of time to learn everything”. My new passion is helping Microsoft learn about, discover and adapt to the maker movement and meet people where they are and to help Microsoft-tech developers become makers.


Microsoft-tech devs have a couple of options. You could get a Netduino or Gadgeteer - which run on the .NET Micro Framework.  You could get a Galileo – which runs Windows. But did you know that you could also use .NET on RaspberryPi with Mono? People typically use python on RaspberryPi, but if your comfort zone is .NET then .NET on RaspberryPi with Mono is worth checking out.


In this post we’ll build a standard .NET console app with Visual Studio and run it on a RaspberryPi with Mono. The only real magic is Mono, the rest is stock .NET. I don’t even need Mono on my Windows machine. I just write a Console app like I do any other Console app. Deploy it to my Pi and run it with Mono. Xamarin Studio is not required.


Let’s build a simple Blinky console app (which is the Hello World for maker projects). I’ll show you how to get your RaspberryPi setup with Mono, how to write to pins and how to deploy and run your code.


I’m using Visual Studio 2013, RaspberryPi model B and Windows 8.1.


RaspberryPi Setup

1. Setup Linux on Pi

Get Occidentalis v0.2

Make Occidentalis SD card

Run first time config

2. Configure Network

Plug Ethernet Cable into Pi

Setup Samba for NetBIOS name or give it a static IP. This is so you can deploy your code to the Pi

3. Setup Remote Desktop (Optional)

This is so you can use your main computer’s mouse and keyboard instead of having to go back and forth between the Pi and your desktop. I’ve found this link the quickest way with xrdp

http://www.maketecheasier.com/enabling-remote-desktop-access-on-raspberry-pi/

4. Setup SFTP

You are going to deploy your code from your Windows machine to your Pi via SFTP. Here’s how with FileZilla

http://trevorappleton.blogspot.com/2014/03/remotely-copy-files-to-and-from-your.html

5. Install Mono

Run this command from RaspberryPi terminal to install mono.

sudo apt-get install mono-complete

6. Setup LED

This is intentionally very simple because this post is about showing .NET on Pi versus what can be done with Pi.

  • 1x LED
  • 1x 220ohm resistor
  • 1x Breadboard
  • 2x Jumper Wires

There are two ways to look at Pi wiring Board layout and BCM, this is great resource for making sure you are using the right pin numbers: http://pi.gadgetoid.com/pinout. We’ll use the “Board” physical layout, so the 6th pin down from the outer rail is 12.


1. Place LED in breadboard

2. Connect Pin 18 to LED Annode (the long lead) via jumper wire.

3. Connect Ground to breadboard

4. Connect resistor from Ground to LED Cathode (the short lead)


dotnet-raspberrypi-mono

P-738-3P-750-3

C# Console App

We are going to use the stock Visual Studio C# console app template. Go ahead and create a Console app.

We are going to also use the Raspberry.IO.GeneralPurpose nuget package to talk to the GPIO pin 18. Go ahead and add a reference to that. GPIO = General Purpose Input Output

That library has a Toggle method so let’s just use it. The code is super simple. Just configure the pin, init a GpioConnection and call Toggle.

This code is also on GitHub: https://github.com/jonbgallant/dotnet-raspberrypi-mono

using Raspberry.IO.GeneralPurpose;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace dotnet_raspberrypi_mono
{
class Program
{
static void Main(string[] args)
{
OutputPinConfiguration pin12 = ConnectorPin.P1Pin12.Output();
pin12.Enabled = false;

using (GpioConnection connection = new GpioConnection(pin12))
{
while (!Console.KeyAvailable)
{
connection.Toggle(pin12);
Thread.Sleep(250);
}
}
}
}
}

Build the app in Visual Studio.


Deploy to RaspberryPi

If using samba w/ mapped drive, just output the code to the drive. If using FileZilla then just copy the bin/Debug folder to a folder in a directory such as /home/pi/dotnet-raspberrypi-mono


It’s just an xcopy deploy.


Run app on Pi

Log into your Pi. Open a terminal. Navigate to the exe you just copied over and execute this command.

sudo mono dotnet-raspberrypi-mono.exe


Your LED should now be blinking!


I hope this quick sample gets you going with RaspberryPi and .NET – and helps you become a maker.


Jon

Monday, December 15, 2014

What you should know about power-over-ethernet (PoE) when considering it for your maker project.

11361-01As I am building out my “maker experience” product “beakn” I’m constantly thinking about ways to improve it with the goal of getting it to be completely wireless. I started with it being USB connected (beakn v0.1), then Ethernet (beak v0.2) and now I’m looking into wireless communication. When I was looking at Ethernet I was researching Arduino ethernet shields and came across the Arduino Ethernet Shield with Power-over-Ethernet (PoE) Module. I didn’t research the requirements much, I just thought it would be great to have an Ethernet option and only run one cable and get both Ethernet and power – so I ordered it.



(Arduino Ethernet Shield with PoE)

What I didn’t realize is that power isn’t provided over ethernet by default. When I plugged the ethernet cable into the shield I thought it would power up, but it didn’t. I spent a lot of time researching settings or configuration for it, but found nothing. I bypassed my router and went directly to the source to see if it was an issue with my router.  Still no luck. I then (using this guide)built a cable that I thought could be used to get power out of the ethernet cable.IMG_1881

(My custom PoE cable)

It then came to me that power might not be provided by default.  So I searched for “router PoE” and discovered that there are indeed PoE enabled routers and I didn’t have one.

71NBj02-RNL._SL1500_

(PoE router)

I also at the same time pinged a co-worker, who is an EE – Hardware guru and he had this to say:


PoE means that every single device on the chain from PSE (power sourcing equipment) to PD (powered device) must be PoE capabled\aware.

In order to get PoE working the PD presents a certain signature on the line which PSE picks up on and initiates a short preamble (detection, classification, mark, class, startup) with PD.

Thus PoE is usually point to point -- as in, a power injector injects power just after the final switch.


In short that means that the Arduino Ethernet with PoE shield isn’t just going to work without a PoE enabled chain.  Yes, you could get a PoE router or midspan device, but this is where I drew the line for my project. I likely won’t have an Ethernet version (remember my goal of being completely wireless) and I definitely don’t want to require my users to have to purchase a PoE router or midspan device.


Going down this PoE path was a good learning experience, but I’m not going to pursue it for beakn. I’m going to keep going down the wireless / battery powered path and leave PoE for a future project.

Hope this saves you some time while researching PoE options.


Jon

Wednesday, December 10, 2014

beakn v0.2 : DIY Lync Status Light with an Arduino or Netduino, Ping Pong Ball and a Cardboard Box - Now Cloud Driven with MQTT

IMG_1827I’m working on a “maker experience” project called beakn.  It’s a Lync status light that lights up red, yellow or green based on your Lync status. beakn v0.1 was all about getting it working without it being too complex – so I opted for using the USB connection from my computer to the Arduino and then send Serial commands over that connection to tell the Arduino what LED to light up. My ultimate goal of the project is to get into the shoes of a maker and see what it takes to take a product from inception to proof of concept to prototype and finally to production.  The end product will be a completely wireless Lync status light that you place anywhere in your office, home or oil rig.

beakn v0.2 gets us one step closer by introducing Ethernet and MQTT (Message Queue Telemetry Transport), which is VERY light weight pub-sub messaging protocol for IoT devices (wikipedia). I spent a lot of time working with the Arduino WiFi shield as well, but I couldn’t get it stabilized in time for the v0.2 release. Also in that process I realized that WiFi is probably out of the picture because of the setup and config that is involved – you have to get the SSID and Password into the sketch and upload it via the IDE, which isn’t something I want my early adopters to have to do.  I will likely end up going with a gateway device connected to Ethernet that listens for MQTT events and sends commands to the beakn via Bluetooth LE or Xbee.  That was a rat hole I didn’t want to go down for this version. Also, with regard to power, I want it to run on battery – the problem is that the Uno and the WiFi shield together won’t run for very long on a 9V.  I dug into what it would take to power the beakn, but didn’t get too far. I’m thinking I’m going to have to deal with that in the prototype phase…I still consider this to be in the proof of concept phase.  Prototype will move away from Arduino and onto getting individual microcontrollers, surface mount LEDs, power management and a 3D printed enclosure.

This entire project is available on GitHub here: https://github.com/jonbgallant/beakn/

If you are new to beakn it might be a good idea for you to read through the beakn v0.1 post

Here are some pictures of the v0.2 build

IMG_1830IMG_1829IMG_1832IMG_1834

The design includes:

1. Arduino or Netduino with 3 LEDs

2. Ethernet Shield

3. MQTT

4. Desktop Application


The app flow is:

You have a desktop application that listens for Lync status change events and publishes a status message to the MQTT topic with the current status. The Arduino/Netduino subscribe to that same MQTT topic and changes the LED color based on the payload of the message.


Here are some of the changes in v0.2

  • The Arduino Uno does not come with an ethernet connectivity, so I had to get an ethernet shield. I opted for the Power Over Ethernet version – but didn’t focus on getting PoE working for this version – you need a power adapter for v0.2.
    • When I got to this point I realized that this little light is getting expensive.  The Uno is $25, the Ethernet Shield is $36 for non-PoE and $56 for PoE or $61 to $81. The price jump is obviously because of the need for Ethernet. That’s when I picked up Netduino Plus 2 for $60 – which comes with Ethernet.
    • Here’s what the guts of the Netduino beakn look like:

IMG_1835

    • If you are going to stick with Arduino and don’t have one yet, then get the Yun instead. It comes with an Ethernet port.
  • There are a couple of MQTT Arduino libraries out there and I decided to use the Arduino Client for MQTT because it looked simple enough and I got it running pretty quickly.
  • The beakn desktop application is much more stable and won’t lose connection when you sign in and out of Lync. It will lose connection if you completely exit Lync. I spent a bit of time researching that, but just decided to address that issue later.
  • For MQTT on the desktop app I decided to use M2Mqtt because it looks like it is the only game in town and they have a nuGet package.
  • There are a couple of free MQTT services out there to test things out and I decided to use a HiveMQ one here: http://mqttdashboard.com/info/broker. There also GnatMQ, but I couldn’t find a freely available version online. Obviously if you productionize this you are going to want to get your own MQTT server going.
  • The Arduino LED pin numbers have changed because the Ethernet shield uses some of the pins I was using before.


As a C#/JavaScript developer it was a big relief to work with the Netduino.  It’s nice to be back in Visual Studio and C# and it was great that the M2Mqtt library was available.  I didn’t get the Serial version working on Netduino, but that’s not important at this stage because of my wireless goal. I’m going to keep prototyping with the Arduino to see what is possible, but as a long time Microsoft developer the Netduino is definitely preferred.  Being able to use nuGet is sweet too.



Here’s what you need to do to build this yourself:

1. Follow the hardware instructions for beakn v0.1

  • Carve out a little more space in the back of the box for Ethernet and Power

IMG_1838

  • For Netduino
    • Wire the pins as follows:
      • Red: D10
      • Yellow: D11
      • Green: D12
  • For Arduino
    • Stack the Ethernet shield on top of the Uno or get a Yun
    • Wire the pins as follows:
      • Red: D5
      • Yellow: D6
      • Green: D7

2. Deploy the sketch to the Arduino or Netduino

  • For Arduino
    • Open this sketch in the Arduino IDE.
    • Change both topicName and clientName to something unique. It can be whatever you want it to be.
    • Deploy the sketch to your Arduino
  • For Netduino
    • Make sure you are all setup with the latest Netduino Firmware and VS2013 support. I have a blog post here to help with that.
    • Open this project in visual studio
    • Open the AppSettings file and only change the MqttPairingCode to something unique. Remember this code because you’ll need it later when you install the desktop app.
    • Deploy the project to the Netduino. The VS “Deploy” option didn’t work for me, so I just Hit F5 to get the bits out there on the Netduino.

3. Install the beakn v0.2 desktop app or get the code here and compile it yourself.

4. Update the beakn.exe.config file.

  • [Only do this if you installed via msi installer] Open CMD as Admin. Navigate to the beakn install directory. Execute “notepad beakn.exe.config”
  • Change the “MqttPairingCode” setting to something unique. It can be anything, but it must match the same MqttPairingCode that you used in your Arduino or Netduino app.


KNOWN ISSUES

  1. beakn will lose the connection if you completely exit Lync. You’ll need to restart beakn.exe if you close Lync.
  2. You must first plug in the ethernet cable, then power when you setup the beakn.  The init script runs when it boots and if the Ethernet isn’t there it will jus fail.


That should be all there is to it.


Let me know if you run into any other issues and follow me on twitter to get updates of future version.


Jon


p.s. Just for kicks – I wired up this full size traffic light in my office as a beakn – it’s super bright and very hot!

IMG_1837

How to trade in your old Canon camera for a discounted refurbished one with the Canon Loyalty Program

Canon has a program called the “Customer Loyalty Program” that allows you to send in your broken Canon camera and get a refurbished camera at a discount. There’s nothing about it on the Canon website, but it sounded legit when I called.

Here’s how it works:

1. Call this number:866-443-8002, Hit Option 2

2. Wait on hold for a really long time…at least 15 minutes

3. Ask them what cameras are available for the Canon Loyalty Program. List as of 12/10/2014 is below

4. Purchase the camera at the price they quoted you.

5. Get camera.

6. Send them your broken camera.  It can by any Canon branded camera.


Available cameras as of 12/10/2014

  • T3, 18-55 Kit $269.99
  • 60D Body $460.79, $431.99 until end of Decbemer
  • 7D Body $767.48
  • 6D Body $1367.28
  • 5D Mark III Body $2447.28