Rob Chartier ~ Contemplation...

.NET, C#, Work, etc.

News






www.flickr.com
This is a Flickr badge showing public photos from Rob & Kat Chartier. Make your own badge here.


Even Quicker Links

Electric Imp–A Simple LED, but on what Pin?

 

My Electric Imp decided to show up in the mail the other day, so I decided to start the hacking adventures.  This post is intended to document my initial experience and steps follows to get a working prototype in place in order to turn on and off a LED.

Parts List:

imp card
April Development Board
MiniB (yes a MiniB, not A) USB Cable
5V USB Power Supply 5V 1A (1000mA) USB port power supply - UL Listed
Breadboard

Half-size breadboard

330 Ohm Resistor (orange, orange, brown, gold)

I actually purchased a pack similar to this, which comes with a whole line up of resistors for all your hacking fun.
E-Projects - 330 Ohm Resistors - 1/4 Watt - 5% - 330R (100 Pieces)
LED

Again, shop around for a pack of LED’s on the cheap.

Super Bright White 5mm LED (25 pack)

 

Getting Online & the IDE

The first thing you need to do is get your imp online via your WiFi network.  In order to make this happen you need to have an iOS or Android device.  The kind folks at Electric Imp have provided a “BlinkUp” app for each platform, which essentially allows you to point the Imp at your screen, and with a series of flashes it will program your device.

Download the iOS App or download the Android App now.

In my instance, my dev Android device has a fairly cracked screen, which simply did not work to flash the Imp, luckily I had an iPhone around, and it just worked out of the box, first try. 

The Imp uses a cloud based development environment, found here, and in order to pair your shiny new Imp with your online account, you will need to setup an account on their website, and enter those credentials into the BlinkUp App prior to flashing your imp.

Now lets flash the imp:

  1. Launch the BlinkUp app,
  2. Enter your credentials, and select the correct Wifi AP.
    1. Be sure to set your WiFi password in the UI; it is not automatically provided for you.
  3. Plug the Imp into the April Development Board
  4. Plug the MiniB USB cable into the Development board
  5. Plug the other end of the USB Cable into your 5V USB Power supply, and then that into a receptacle.
    1. At this time you should see the Imp blinking yellow
    2. This means it is ready to be flashed
  6. Hit the “Send BlinkUp” button on your mobile device
  7. At this time you have about 3 seconds to point the Imp to the screen of the mobile device.  I pointed them about 1 inch apart, with the LED on the Imp pointing towards the screen. 
    1. I noticed that once the pairing was in progress the internal LED light on the imp stuttered and blinked at a different rate. 
    2. Give it time.
    3. Eventually the Imp’s LED will stop blinking yellow, and go through a few different colors until it reaches a nice green color.  This means it is now online!

Now that your Imp is online, lets get going on the IDE. 

image

On the left you have a list of your Imp Devices (New Devices) and Inactive models.  Your new Imp should be showing up as device on the left.  Along with devices, you also have the concept of “Models”.  Models are a way to describe the applications you will write.  Each Model can be active on a device, or in the “Inactive Models” section.  This allows you to share Models (Apps) across Imp Devices, and to be able to swap in and out different apps per Imp.  Simple and easy to use.

Each Model consist of two blocks of code. One which rums on the Electric Imp’s Cloud Server (Agent), and another block which runs on the Imp (Device) itself.  Both of these code blocks run code using the Squirrel language, a high level and lightweight language.

Take time now to setup the hardware and software based on this guide and then this guide.

At the end of these samples you will be able to control your Imp, from a URL on the Electric Imp’s Cloud server.

Lets Code!

I decided to hack the second guide, and allow to be able to send the Pin which the LED is sitting on, via the URL as well!  Here is my Model.

Agent Code

   1:  // Log the URLs we need
   2:  server.log("Turn LED On: " + http.agenturl() + "?led=1");
   3:  server.log("Turn LED Off: " + http.agenturl() + "?led=0");
   4:   
   5:  function requestHandler(request, response) {
   6:    try {
   7:      
   8:      local pin = 9;
   9:      
  10:      if("pin" in request.query) pin = request.query.pin.tointeger();
  11:        
  12:      // check if the user sent led as a query parameter
  13:      if ("led" in request.query) {
  14:        
  15:        // if they did, and led=1.. set our variable to 1
  16:        if (request.query.led == "1" || request.query.led == "0") {
  17:          // convert the led query parameter to an integer
  18:          local ledState = request.query.led.tointeger();
  19:   
  20:          // send "led" message to device, and send ledState as the data
  21:          device.send("led", ledState + "," + pin); 
  22:        }
  23:      }
  24:      // send a response back saying everything was OK.
  25:      response.send(200, "OK");
  26:    } catch (ex) {
  27:      response.send(500, "Internal Server Error: " + ex);
  28:    }
  29:  }
  30:   
  31:  // register the HTTP handler
  32:  http.onrequest(requestHandler);

Notice that I added the ability to pass in a “pin” parameter, and I send that along to the device via the “device.send()” command.  Pretty nifty that these guys actually have a single method call to push a payload from the cloud server down to the device.  Some great work here!

 

Device Code

   1:   
   2:  function setupPin(pin) {
   3:      local led = getPin(pin);
   4:      // configure led to be a digital output
   5:      led.configure(DIGITAL_OUT);
   6:      return led;
   7:  }
   8:   
   9:  function getPin(pin) {
  10:      if(pin == "1") return hardware.pin1;
  11:      if(pin == "2") return hardware.pin2;
  12:      if(pin == "3") return hardware.pin3;
  13:      if(pin == "4") return hardware.pin4;
  14:      if(pin == "5") return hardware.pin5;
  15:      if(pin == "6") return hardware.pin6;
  16:      if(pin == "7") return hardware.pin7;
  17:      if(pin == "8") return hardware.pin8;
  18:      return hardware.pin9;
  19:  }
  20:   
  21:  // function to turn LED on or off
  22:  function setLed(ledState) {
  23:    local b = split(ledState + "", ",");
  24:    server.log("Set LED: " + b[0]);
  25:    server.log("On Pin: " + b[1]);
  26:    local led = setupPin(b[1]);
  27:    led.write(b[0].tointeger());
  28:  }
  29:   
  30:  // register a handler for "led" messages from the agent
  31:  agent.on("led", setLed)

You will notice that I did do a bit of rewrite on the sample code.  I setup two functions which will first allow you to translate a string with a number from 1-9 into the correct hardware pin (getPin function), and moved the configuration of our pin into another function (setupPin function), and finally the setLed function utilizes the string split command to bust apart our previously concatenated values, calls the setupPin function, and finally writes our value to the LED. 

Now in order to control an LED on any Pin, all I need to do is hit this Url:

https://agent.electricimp.com/{ImpID}?led={0/1}&pin={1-9}

Where ImpID is the unique id provided by the Electric Imp cloud server.  The “led” parameter will take a 0 to turn off, and a 1 to turn on, and finally the pin will take a number from 1 to 9, relating to the Pin you need to control.

Halloween 2013 Build using a Raspberry Pi

 

This year for Halloween I wanted to start to scratch the surface of what I could do with a Raspberry Pi in order to bring a “haunted” experience to my front yard. My guidance/inspiration was from here.

Overall, I wanted to have a single motion sensor trigger a sequence of scenes where each scene would incorporate one or more lights, one or more audio tracks and be limited to about 30 seconds or less.

Parts List

I broke the parts list up into two groups, the first is the items you probably would need to buy online, the second you should be able to get most of them from your local Home Depot, Lowes or other hardware store.

Online parts list:

  1. 1 x Raspberry Pi, Model b

Raspberry Pi Model B 512MB RAM

  1. 1 x USB Powered Speakers (externally powered)

USB Powered Speakers

  1. 1 x PIR Motion Sensor

PIR (motion) sensor

  1. 1 x Breakout board/Extension wires, Male->Female, 4 to 6 inches in length

Premium Female/Male 'Extension' Jumper Wires - 40 x 12

  1. 5v 1 x 1Amp USB Port power supply with an A/Micro B cable

5V 1A (1000mA) USB port power supply - UL ListedUSB cable - A/MicroB

  1. 1 x 4GB SDHC MicroSD Memory Card

4GB SD card for Raspberry Pi preinstalled with Raspbian Wheezy

  1. 1 x Low-Profile microSD card adapter for Raspberry Pi

Low-profile microSD card adapter for Raspberry Pi

  1. 6 x Solid State Relays, 3v to 110v+
    1. Essentially you apply 3 volts to one pair of terminals, which will turn on the 100v pair.

SSR-10DA Solid State Relay - White + Silver

Optional online parts:

  1. You may need a HDMI (Male) to VGA Adapter if you do not have an HDMI compatible TV or Monitor.  To initially install the Pi OS, you will need a way to output the video.
  2. You may also need some sort of USB keyboard, wired or wireless, most just work.  If you don’t have one one hand, you should consider getting one of the smaller form factor wireless keyboards which you can reuse and is portable along with your Pi’s.
  3. Finally you also need a way to give this device access to your network.  If you have a router with a spare LAN port you can use it, just be sure you have a Cat5e networking cable (male on both ends) available for the project.  Otherwise a hub will be just as suitable.  As an alternative you can find many mini WiFi USB dongles that are compatible for the Pi. I chose to NOT use the WiFi dongle because it is an additional cost.  I will not cover of WiFi configuration in this post, there are many online articles outlining the process.

You can buy most of these from adafruit.com, dx.com, or any other favorite retailer. 

 

Hardware store parts list:

  1. 4 x (double) receptacle wall sockets [NEMA 5-15 (15A/125V earthed) Type B] Commercial Duplex Receptacle 15 Amp 125v, Gray
  2. 3 x electrical boxes
    1. 1 x single width
    2. 1 x double width
    3. 1 x triple width

  1. 1 x double electrical face plate, “blank” or cover
  2. 1 x single receptacle wall socket face plate
  3. 1 x triple receptacle wall socket face plate

 

1 Gang Duplex Receptacle Plate, White - 10 Pack 3-Gang Midway Nylon Blank Wallplate, in White

 

  1. 20 x twist-on wire connectors

Can-Twist One size fits all Wire Connector  300/tub

  1. 1 x 50 feet of electrical cable, of appropriate gauge for your country
  2. 1 x Bag of electrical cable staples, probably need 50 to 60GB GB 1/2 In Plastic Staple, White (15-Pack)
  3. 1 x bag of wood screws, 3” long, at least 24 screws
  4. 1 x bag of wood screws, 2” long, at least 12 screws
  5. 1 x Plywood, 2 feet squared, about 1” thick  (bottom base)
  6. 2 x 2x4, 2 feet in length (sides of base)
  7. 1 x 1x2 2 feet in length (front)
  8. 1 x Plywood, 1.5 feet squared, (back / relay anchor)

Box Construction:

Take the base plywood (2x2x2) and secure the 2x4’s to each opposite side.  Add the 1x2 to one end, and finally the 1.5 foot squared plywood to the back. 

This will form an awkward sided box without a lid.  This is by design.  It will provide enough room for you to secure the two larger electrical box’s to the front left and right, and the smaller box on the left side, in the middle.  Finally each relay can be secured to the back / relay anchor piece.

Since a picture is worth a thousand words, here are a few to help out.

WP_20130920_004WP_20130920_006WP_20130920_005WP_20130920_007WP_20130920_008WP_20130920_009WP_20130921_001WP_20130921_003WP_20130921_002

Notice the smaller receptacle box on the left.  It is “Always On”, meaning we hardwire power directly to both of those receptacles.  The larger box on the right, with the three pairs of receptacles, those are run through the relay switches.  Finally, the box on the front left is where we take the main line from the house, and split it into 7 (Always on, and the 6 via the relays).

Note: If I were to do this box again, I would probably use a terminal strip, instead of the lower left box to split the house main into the 7. 

Here is a photo of the same box, with the relay switches installed:

WP_20131127_004

Next secure your relay switch’s to the back, like you see in the above picture.  Do your best to make them level, straight and in the middle of the box. 

Take your 50 feet of electrical wire and run a single line to the Always On box, and then 6 to the back, up and over, and then down and forward to the 6 receptacles on the front right.  You will need to split the “HOT” of each of these lines up on the back and wire each HOT into the relay switch.  Take care to find out online which exact color is “HOT” / “Phase” / “Live” for your house electrical wiring.  For example, in Canada, black is set to be “Live” or “HOT”.  Split it, to the set of terminals on the relay switch.  Notice I also use secure each split with an appropriate and twist caps.

Use the electrical staples to secure each line down to the box as best as you can, and clean up the box until you are happy with it.

WP_20131127_001WP_20131127_003WP_20131127_008WP_20131127_010WP_20131127_011WP_20131127_012

 

Raspberry Pi Construction

You will need to first download the NOOBs installation media, and follow the instructions here to perform the installation of the “Rasbian” operation system.  It is essentially Linux slimmed down for the Pi.  Be sure to use the MicroSD card you ordered for the project earlier.

Now unbox the RaspberryPi, MicroSD Adapter, and USB Power.  Plug your MicroSD card into the adapter, and that into your Pi.  I personally use the HDMI output to my living room television, and you will need some sort of video to perform the initial install on the Pi itself; ensure that this is plugged in as well.  Make sure you also plug in your keyboard and your networking cable from a switch or router.

Finally apply power to the device with your USB Power adapter.

If it is not that obvious of what is what on the Pi, here is useful image outlining the position of each component.

NOTE: The Raspberry Pi does not have any sort of onboard protection for hot-swapping anything from USB, HDMI, or other GPIO Ports.  Make sure you shut the device down appropriately before trying to plug anything in or out of it. Failing to do so may result in frying the little guy!

Follow the instructions to finish the installation of the “Rasbian” operating system, and eventually you should end up at a login prompt.  Take note of the IP Address, it should be near the login prompt.  Login with the default user name and password (pi / raspberry) for the Rasbian operating system.    If you missed the IP Address on the login screen, use the command “ifconfig” in the terminal, its output will contain the device’s IP address.

Right now you should be able to login to the Pi, via SSH.  If you are on Windows, putty is a suitable tool which you can SSH into the machine.  Use the IP address to connect via putty to SSH on your Pi.

Raspberry Pi & Python

Rasbian comes with python already installed, test it out by typing: 

python

At the command prompt, which then you should end up in the python “RELP” (Read, Eval, Print, Loop),  try this command:

>> import this

You should see “The Zen of Python”, some guidelines for writing python code.

   1:  >>> import this
   2:  The Zen of Python, by Tim Peters
   3:   
   4:  Beautiful is better than ugly.
   5:  Explicit is better than implicit.
   6:  Simple is better than complex.
   7:  Complex is better than complicated.
   8:  Flat is better than nested.
   9:  Sparse is better than dense.
  10:  Readability counts.
  11:  Special cases aren't special enough to break the rules.
  12:  Although practicality beats purity.
  13:  Errors should never pass silently.
  14:  Unless explicitly silenced.
  15:  In the face of ambiguity, refuse the temptation to guess.
  16:  There should be one-- and preferably only one --obvious way to do it.
  17:  Although that way may not be obvious at first unless you're Dutch.
  18:  Now is better than never.
  19:  Although never is often better than *right* now.
  20:  If the implementation is hard to explain, it's a bad idea.
  21:  If the implementation is easy to explain, it may be a good idea.
  22:  Namespaces are one honking great idea -- let's do more of those!
  23:  >>>

In order to exit the python REPL, you need to hit Control-Z.

 

Creating your first python script

  1. 1. At the SSH prompt, type:
    1. touch hello.py
    2. chmod +x hello.py
    3. nano hello.py

“touch hello.py” will create a new, empty file in the current folder.

“chmod +x hello.py” will set the “execute” flag on hello.py, this allows us to execute it directly.

“nano” is a simple text editor available on the Pi, you should be in the editing window, “hello.py”, which is now empty.  Type in the following code:

 
   1:  #!/usr/bin/env python
   2:  print("Hello, world")

Save the document by hitting Control-O, then hit enter.  To exit, hit Control-X.  This should dump you back out to the command prompt.  In order to execute our script we type:

./hello.py

This should simply print out “Hello, world”, and then exit you back to the prompt.

Success!

Also installed by default is the ability to use the GPIO (General Purpose Input/Output) ports in python.  We will use the GPIO ports to apply 3v’s to our Solid State Relays. 

You will notice that on the PI, there are two rows of Pins sticking out, these are the GPIO pins, here is a diagram which explains each Pin:

Raspberry-Pi-GPIO-Layout-Revision-2

 

Take note of all of the Green GPIO pins.  They are what we will be connecting to our Relay Switch’s.  We will cover more about these GPIO pins and Python in a section further down.

 

Raspberry Pi and the Box

Wiring the Pi up to the Box, more specifically the Solid State Relays, is done by first taking a single ground wire from each Solid Sate Relay’s negative/ground terminal (-) to each other in a chain, like the following image.

WP_20131127_007

You can take the Breadboard wires and use them, strip of the plastic tips and about 1/2 inch of the wire sheath to expose the bare metal wire inside.  I actually take a single wire from the first to the second, and another from the second to the third and so on, after the final relay you take a final wire out to the Ground pin on the Pi.  On this final wire, leave the Female tip which will make it easy to plugin into the Pi.  That solves the common ground for each Solid State Relay.

In order to finish this you will need to take a single breadboard wire (female end) from a GPIO port on the PI to the Solid State Relay (male end), positive terminal.  Repeat this for each GPIO to Relay terminal.  It does not really matter which GPIO port is used, just write each down and their relationship to the final receptacle box of 6.

In the end you will see the following:

WP_20131127_002

Now that you have the Pi online, connected to the Box via the Relay Switch's, and the switch's controlling power to our bank of 6 receptacles, we are ready to start writing more python scripts to control the lights!

 

Sample Scripts

The best way to get started programming for the Raspberry PI and its GPIO pins is to read over the RPi.GPIO module basics. Please review that prior to continuing.

Below is a set of scripts which should be enough to get you started with working with python and GPIO ports.  I did my best to document the code where it was appropriate.  If you need more assistance with python there are a plethora of online tutorials which you can learn from. 

on_off.py

   1:  #!/usr/bin/env python
   2:  import time 
   3:  import RPi.GPIO as io 
   4:   
   5:  # https://code.google.com/p/raspberry-gpio-python/wiki/BasicUsage
   6:  io.setmode(io.BCM)
   7:  io.setwarnings(False)
   8:   
   9:  light_one = 24
  10:   
  11:  io.setup(light_one, io.OUT)
  12:   
  13:   
  14:  def light(light_pin, state):
  15:      print("light control:" + str(light_pin) + " " + str(state))
  16:      io.output(light_pin, state)
  17:   
  18:  print("Turning light on")
  19:  light(light_one, True)
  20:  time.sleep(1)
  21:  print("Turning light off")
  22:  light(light_one, True)
  23:  print("All done")

allon_off.py

   1:  #!/usr/bin/env python
   2:  import time 
   3:  import RPi.GPIO as io 
   4:   
   5:  # https://code.google.com/p/raspberry-gpio-python/wiki/BasicUsage
   6:  io.setmode(io.BCM)
   7:  io.setwarnings(False)
   8:   
   9:  light_one = 24
  10:  light_two = 23
  11:   
  12:  io.setup(light_one, io.OUT)
  13:  io.setup(light_two, io.OUT)
  14:   
  15:   
  16:  def light(light_pin, state):
  17:      print("light control:" + str(light_pin) + " " + str(state))
  18:      io.output(light_pin, state)
  19:   
  20:  print("Turning lights on")
  21:  light(light_one, True)
  22:  light(light_two, True)
  23:  time.sleep(1)
  24:  print("Turning lights off")
  25:  light(light_one, True)
  26:  light(light_two, True)
  27:  print("All done")

That should be enough to get you started with controlling your receptacles.  Next we dive into some sample code for playing sound.  Plug in your speakers to the audio jack.  I found some sample sound bytes online, and used Audacity to convert them to 2 Channel MP3s if they were not already in that format.

playsound.py

   1:  #!/usr/bin/env python
   2:  import pygame 
   3:  import os
   4:  import time
   5:   
   6:  pygame.mixer.init()
   7:  pygame.init()
   8:   
   9:   
  10:  def playTrack(track):
  11:      print("playing track:" + track)
  12:      pygame.mixer.music.load(track)
  13:      pygame.mixer.music.play()
  14:      while pygame.mixer.music.get_busy():
  15:          time.sleep(0.5)
  16:   
  17:   
  18:  print "ready to rock"
  19:   
  20:  while True:
  21:      for files in os.listdir("."):
  22:          if files.endswith(".mp3"):
  23:              print files
  24:      sound = raw_input("Song? ")
  25:      playTrack(sound)
  26:      time.sleep(1)

Our last sample script demonstrates using the PIR motion sensor with the Pi, in this example I’m using GPIO port 25.  Notice that it is setting the io port to io.IN instead of io.OUT like our switch’s above.

motion.py

   1:  #!/usr/bin/env python
   2:  import time 
   3:  import RPi.GPIO as io 
   4:   
   5:  io.setmode(io.BCM)
   6:  io.setwarnings(False)
   7:   
   8:  pir_pin = 25
   9:  io.setup(pir_pin, io.IN)
  10:   
  11:  def onMovement():
  12:      print("movement!")
  13:   
  14:  print "ready to rock"
  15:  while True:
  16:      if io.input(pir_pin):
  17:          onMovement()
  18:      time.sleep(300)

 

In this script we setup an infinite loop with the “While True”.  This allows for our script to sit and wait for motion.  Once the PIR detection motion we immediately call the “onMovement” function.

Remember for each script file you create to run the “chmod +x script.py” on the pi.  This will allow you to test it by just running the script name itself at the command line:

[$] > playsound.py

 

Putting it all together

Here is my final script for executing scenes based on motion.

   1:  #!/usr/bin/env python
   2:  import time 
   3:  import RPi.GPIO as io 
   4:  import pygame 
   5:  import subprocess 
   6:  import time 
   7:   
   8:  io.setmode(io.BCM)
   9:  io.setwarnings(False)
  10:   
  11:  pygame.mixer.init()
  12:  pygame.init()
  13:   
  14:  pir_pin = 25
  15:  light_4 = 4
  16:  light_17 = 17
  17:  light_18 = 18
  18:  light_23 = 23
  19:  light_22 = 22
  20:  light_24 = 24
  21:   
  22:  playing = False
  23:  io.setup(pir_pin, io.IN)
  24:  io.setup(light_4, io.OUT)
  25:  io.setup(light_17, io.OUT)
  26:  io.setup(light_18, io.OUT)
  27:  io.setup(light_23, io.OUT)
  28:  io.setup(light_22, io.OUT)
  29:  io.setup(light_24, io.OUT)
  30:   
  31:  def allOff():
  32:      light(light_4, False)
  33:      light(light_17, False)
  34:      light(light_18, True)
  35:      light(light_22, False)
  36:      light(light_23, False)
  37:      light(light_24, True)
  38:   
  39:  def scene1():
  40:      print "scene 1, scream"
  41:      light(light_22, True)
  42:      playTrack("scream.mp3")
  43:      light(light_22, False)
  44:   
  45:  def scene2():
  46:      print "scene 2, baby"
  47:      light(light_17, True)
  48:      playTrack("rosie.mp3")
  49:      light(light_17, False)
  50:      time.sleep(2)
  51:   
  52:  def scene3():
  53:      print "scene 3, torture"
  54:      light(light_4, True)
  55:      playTrack("torture.mp3")
  56:      light(light_4, False)
  57:   
  58:  def endScene():    
  59:      light(light_24, True)
  60:      light(light_23, True)
  61:      playTrack("laugh.mp3")
  62:      time.sleep(2)
  63:   
  64:   
  65:  def onMovement():
  66:      print("movement!")
  67:      light(light_18, False)
  68:      scene1()
  69:      scene2()
  70:      scene3()
  71:      endScene()
  72:      allOff()
  73:   
  74:   
  75:  def light(light_pin, state):
  76:      print("light control:" + str(light_pin) + " " + str(state))
  77:      io.output(light_pin, state)
  78:   
  79:  def playTrack(track):
  80:      print("playing track:" + track)
  81:      pygame.mixer.music.load(track)
  82:      pygame.mixer.music.play()
  83:      while pygame.mixer.music.get_busy():
  84:          time.sleep(0.5)
  85:   
  86:   
  87:  allOff()
  88:   
  89:  print "ready to rock"
  90:  while True:
  91:      if not(playing):
  92:          if io.input(pir_pin):
  93:              print "starting"
  94:              playing = True
  95:              onMovement()
  96:              playing = False
  97:              print "ended"
  98:      time.sleep(300)

Action!

A video of the build in action:

 

That’s all for now!

Extending your Home Automation network with Raspberry Pi

 

Just thought I would share that last night I decided to throw some code together which will mash up the Raspberry Pi along with the zVirtualScenes server

In reality you could deploy the scripts to any machine capable of running python (OSX, Windows, *nix, etc..).  All communication is done via UDP using Multicast groups, so every node on the network will send to this single group, and all other nodes will receive the events.

Interesting idea.

 

Here are some screen grabs from zVirtualScenes connected to a Raspberry Pi, with a PIR motion sensor:

1. Enabling the “SensorNet” adapter

ActivateAdapter

 

2. Auto-discovery working.  The server sends a “RegisterRequest” message to the group, and each node starts to report in with their capabilities.

DeviceAutoDiscovery

 

3. All motion values are stored in zVirtualScenes server, and can be used for triggering events

RaspberryPi with zVirtualScenes

 

4. Triggering an event based on motion detected on the RPI:

TriggerBasedonRpiMotionDetection

 

 

The idea here is that you can use the Raspberry Pi (base cost of $35) to setup a sensor network, a command network, etc.. on your LAN for all of your Home Automation needs.

 

Some examples


Have your garage door wired with a Pi and a Solid State Relay Switch (http://dx.com/p/ssr-10da-solid-state-relay-white-silver-230994), and have that device/switch show up in zVirtualScenes and also to be able to easy control it.

 

sku_230994_1[1]

 


You could setup a series of cheap Sensors in your home wired to a single or many Pi's, and have each readable/actionable in zVirtualScenes.  Some examples:

Triple-axis analog accelerometer - for measuring motion and tilt
Force sensitive resistor - for sensing pressure/force
Temperature sensor - for measuring from -40 to over +125 degrees C
10K breadboard potentiometer
Hall effect sensor - for sensing a magnet
Piezo - can be used as a buzzer or a knock sensor
Ball tilt sensor - for sensing orientation
Photo cell sensor - for sensing light
IR sensor - for sensing infrared light pulsing at 38KHz
IR LED - for use with the IR sensor

FYI, you can by ALL of those sensors, for $35 right now: http://www.adafruit.com/products/176

 

basicsensors_LRG[1]


Have XBMC announce what’s playing information, and to be able to control XBMC via zVirtualScenes



Monitor and control remote OSX, Windows, Linux desktops via zVirtualScenes
   Disk SMART status, watch dog for apps & services, etc.. and trigger events in your Home Automation network based on these events.



Have a different device in your network Monitor zVirtualScenes events and respond accordingly.  This really allows us to break out of just controlling z-wave enabled devices, to being able to control ANY device on your network. 


There is really no limit of the possibilities here.

 

Show me the code!

Right now it is a bit too early to share all of my code. I do plan on opening it all up under some no-limit license, once it gets to an acceptable point for publishing.

With that said, here is the gist of getting a PIR Motion sensor on a PI on the network - it is in python, so tread lightly... :)




import GPIO 
from App import App

app = App("RPI-Upstairs");  ##give this device a unique name on your network

##Import your sensors 
from sensors.zMotionSensor import zMotionSensor as MotionSensor

##register your sensors 
pin7pir = MotionSensor("Main Entry Motion Sensor (PIR)", #unique display name for this sensor on this device 
    7,              ## GPIO port used 
    GPIO,  app )     ##just ignore these, we are injecting our dependencies


pin7pir.monitor()  #setup this sensor to start monitoring for input


app.wait()  ## setup our wait loop for our daemon, to allow for the magic to happen


 

On the zVirtualScenes side of things, all you need to do is enable the "SensorNet" adapter, and all will be recognized and registered automatically. 

ActivateAdapter


 

How can I get my own Pi?


Sample shopping cart items to get a basic PI with a motion sensor.

 

998_LRG[1]
Raspberry Pi Model B 512MB RAM - $39.95
http://www.adafruit.com/products/998

 

 

pirsensor_LRG[1]

PIR Motion Sensor - $9.95
http://www.adafruit.com/products/189

 

 

ID501_LRG[1]

***5V 1A (1000mA) USB port power supply - $5.95
http://www.adafruit.com/products/501

 

 

microusbcable_LRG[1]

***USB cable - A/MicroB - 3ft - $3.95
http://www.adafruit.com/products/592

 

SD102_MED[1]

***4GB SD Card - $7.95
http://www.adafruit.com/products/102

 

Most of these items you should be able to get locally or even cheaper from any vendor, ebay, monoprice, amazon, etc..  On adafruit check out the “Distributors” tab, for local options.

Total cost so far, from adafruit.com, is about $68, which is cheaper than any z-wave enabled Motion detector on the market today!


Once the base costs are covered for the Pi, you can add a bunch of cheap, additional sensors to this device (and thus your network).

More to come.

Getting started with Developing for the AGENT SmartWatch

Updated to include screenshots from the read Agent Installer, and project templates, and a few Amazon book references.

Prerequisites : Tools and SDK’s

Now that the AGENT : The World’s Smartest Watch has been successfully funded with Kickstarter its time for the developer community to kick into gear and start writing watch faces and apps so when the time comes for the release of the store we can have hundreds of not thousands of available applications ready for mass consumption!

If you are a hobbyist, or a new developer that has that killer idea for a face or app for the AGENT, or you just want to tweak someone else's idea this post is for you!

First and foremost you will need a Windows machine.  I prefer Windows 8 but Windows 7 will do just fine. 

If you already have Visual Studio .NET (VS.NET) installed, skip over this step.  Otherwise Download Visual Studio Express 2012 from here. (Direct) –Start it now and then read on…

A bit of nomenclature:

VS.NET is an IDE (Integrated Development Environment – picture notepad on steroids).   It allows you to author applications using a variety of languages (most common is C#) for a variety of scenarios.

.NET is a Framework.  It provides a comprehensive and consistent programming model for building applications – a set of APIs.  It can be consider it as an abstraction above other lower level API’s.

.NET Micro Framework is a tiny subset of the .NET Framework which is targeted and streamlined for Micro (tiny) devices.  It does not include many, many features, and API’s from the larger .NET Framework - keep this in mind when you are reading online documentation; you will soon find out that the .NET Framework supports a much needed API call but find out that it has NOT been ported to the .NET Micro Framework.  This can be confusing for many folks that are new to the .NET Micro Framework.

C# is a programming language.

Essentially you will use VS.NET, write code in C#, and target the .NET Framework and in our case here we will be targeting the .NET Micro Framework.

If you are looking for an introduction to C#, consider these resources:

  1. MSDN Introduction to C#
  2. Introduction to the C# Language and the .NET Framework
  3. CSharp Book by Christoph Wille
  4. CSharp Station’s Tutorial
  5. Pluralsite : C# Fundamentals Part 1
  6. Embedded Programming with the Microsoft® .NET Micro Framework
  7. Expert .NET Micro Framework (Expert's Voice in .NET)

More specifically if you want a beginners guide to C# and the .NET Micro Framework here is a PDF to download.

So by now your download should be finished.  At the time of writing this, the download was an ISO.  Since I’m using Windows 8 I’m able to right click that ISO and mount it as a DVD right there. 

image

For Win 7 users you may need to download a tool like UltraISO, Gizmo, or Virtual CloneDrive which will be able to take that ISO that you downloaded and “mount” it (or treat it) as a DVD drive on your system.  If that doesn’t work for you, go old school and burn the ISO to a DVD.

Start the installer by double clicking the wdexpress_full application on the DVD.

 

image

 

Once the installer is ready you will be prompted with the installation tool:

image

Be sure to hit the “I agree…” checkbox and optionally check the checkbox to Join the Customer Experience Improvement program if you like and the hit INSTALL.

 

image

Now its time to go for a coffee, or you could use the time that it takes to install VS.NET to review the sites above get (re)acquainted with C# and the .NET Micro Framework!

Eventually….

image

Hi Launch.

image

Click the “Register Online” button to launch your browser for registration.  You will be required to have a Microsoft Live account to proceed, so either login or create a new account.

Once you are logged in, fill out the required information in their registration tool and finally you will be given your product key.

 

image

Copy and paste your key, and allow for VS.NET to apply the product key to your installation.

image

And finally success!

image

NOTE: Typically VS.NET will ship periodic updates.  The version of the express SKU we just downloaded included the most recent update (Update 2); so we will NOT need to also download and install that.  Further updates should ship via the normal Windows Update process; you should be notified via that channel.   Good news!


Now that you have Visual Studio fully installed, lets proceed to get the .NET Micro Framework SDK installed.  If you also have this installed (make sure it is the MICRO framework installed), skip this step.

Download .NET Micro Framework SDK v4.3 from here and start the installation.  Be sure to WAIT until VS.NET is installed completely along with any Updates prior to installing this SDK – and also make sure that you completely exit VS.NET prior to running this installation.

Side Note:

SDK means “Software Development Kit”.  Typically SDK’s provide a set of software development tools that allow for the creation of applications for a certain software package, service framework, hardware platform, etc.. In this case we will be giving VS.NET the ability to work with our custom hardware platform – Micro devices. 

In fact this SDK gives you the ability to work with a plethora of Micro devices from NetDuino’s, the Gadgeteer platform and a whole laundry list of other hardware!

Lets get the SDK installed.

image

Hit Next, and choose “Complete” and then hit Next again.  Finally the SDK will be installed.

image

 

Lastly, the team behind the AGENT SmartWatch have shipped their own specific SDK which adds on the ability for a custom (and cool) emulator, not to mention some cool Project Templates for VS.NET; download it here and install it.

image

 

image

image

Here is a screen shot of the emulator in action (more on this in a bit):

image

Now that we have all of the prerequisites ready, lets move onto the development environment!

Sample Watch – Big Digits Watch Face

Very early on, the guys behind the AGENT project made available some source code for a sample Watch Face called “Big Digits”, we will use it as our starting place to work from. Download it here, unzip it and double click the BigDigitsWatchface.sln file which should open VS.NET Express 2012.

Lets take a quick trip around the Solution, top to bottom just to familiarize yourself with what is at your finger tips.  On the right hand side, you should see the “Solution Explorer” if it is not visible, you may need to go to the View menu and choose “Solution Explorer”.

At the top of the Solution Explorer you should see our BigDigitsWatchFace solution, and just under it you should see the BigDigitsWatchFace project.  Right click the project node and go to properties.

Pro Tip: You can get to a project properties window by double clicking the “Properties” node under the Project node as well.

image

The only real thing to take note of on this first screen is the "Target framework” drop down list, it should be set to “.NET Micro Framework 4.3”.  If you also installed any other previous or later versions of the SDK, they should be available in this drop down.

Feel free to take a look at each other tab down the list on the left; there is sufficient documentation online describing what each and every option is if you are curious enough.

Open up the last tab, “.NET Micro Framework”.

image

First notice the options for the Transport.  If you actually have an Agent Device, and it is plugged in to the USB port you should be able to choose it now (or choose USB).  If not, just use the Emulator.  At the time of writing this I have a pre-release version of the Emulator and the device (as seen above) is listed as the “AGENT Emulator”.  The important thing to really take away from this screen is this is the place where you change change where you want to debug your application with; the emulator or the real device, etc..

Feel free to close this window now.

Next up, if you expand the Properties folder in the Solution Explorer you should see a file “AssemblyInfo.cs”, double click to open it.  Update the Description, Company name, product name, and version information in this file.  This data will be used to identify your application, and its version moving forward.  Once your satisfied with the values, close the file.

Right click the References folder, and choose “Add Reference”.  References are additional files which we can optionally import into our project which give us greater abilities through the .NET Framework API. 

Pro Tip: The general rule of thumb is to ONLY include references to other files that you actually need.   If your project does NOT need these other API’s, don’t include them.  Less is better!

image

Also notice that you have a variety of options for references.  The .NET Tab represents the libraries that are available and are installed into your system.  The Projects tab represents libraries that exist in the same solution that you are currently using.  Finally the Browse tab allows you to search your local hard drive for a file to be added as a reference – the typical use case for this is if you download a 3rd party library from the web that you want to include.

Hit the Cancel button, and then lets skip all the way down to the “Resources.resx” file.  Double click to open it.

image

Since we downloaded this project from the web, the creators already packed in a set of images for each number.  We will soon see how to use these resources to render the clock face.  For now, consider the “Add Resource” button at the top.  This is the way you import resources into your project to be used by your code.  For example Images, Fonts, Icons, or if you plan on localizing your application into multiple languages you can manage the Name/Value pairs for each language.

Pro Tip: Typically localization is done using multiple projects, one for each language –which ONLY contain the strings resources.  Then you can load in that other file at runtime, and read these resource strings for that language – a topic for another day.

Once you add in a resource you should also notice that the actual file is also added under the “Resources” folder.  Expand that now, and you should see corresponding files for each number as we saw in the Resources.resx file.

When adding your own artwork, you really need to pay attention to size, bit depth, etc..  Since the screen is only 128x128 pixels in size, and only supports 1bit depth you wont be able to get any grey scaled images, etc..  Just plain black and white images.  Pre-scale any images to fit what you need; don’t rely on the framework for scaling either.

Show me the Code!

Now that you have the brief tour, lets dig into some of the code behind this watch.  Start off by double clicking “Program.cs”.

Lets walk through each set of related code here.

image

The “using” statements are used to “Import” other API’s from our list of references for the application.  It’s an easy way to make those namespaces available to the current code in this file and if you are trying to import a reference and intellisense is generally not working double check that you do have the actual reference added to the project, and that the version that reference targets is the version of the Micro Framework your working with (in our case here it is 4.3).

A “namespace” is a way to logically divide your code, and can be any arbitrary value. 

Pro Tip: It is best practice to keep the namespace to match the Project and Folder structure.  For example if we add a folder into this project called “API”, the namespace should be BigDigitsWatchFace.API.

A class is a way to encapsulate a set of code in your application, generally referred to as being an “object”.  In our example our class name is “Program”.

Pro Tip: It is good practice to have a single class per file, and the name of the class should match the name of the file.

 

image

This next set of code sets up some global variables in our class which are shared.  In our case we set some useful constants which relate to the specifications/limitations of the device -the screen height and width, also if we should show 12 or 24 hour time, and if a bottom border should be shown, etc…

Ever application needs an entry point, and that is typically a method that is marked with static, has a return type of void and is typically called Main (can also be set in project, properties).  This is where our code starts to be executed once our watch face is started.

image

The first thing we need to do is create a new Bitmap object.  We pass in the MaxWidth and MaxHeight variables in order to get a full screen image.  Consider this as our canvas, we will paint everything the user sees on this canvas.

The call to UpdateTime() we will cover in a second.

As the comments indicate, we setup a timer to automatically call the “UpdateTime” method once every minute.  Notice the _updateClockTimer = new Timer…. call.  This is instructing the app to call that “UpdateTime” method once every “period” – more on this in a second.

Lastly we instruct our application to just go to sleep for an infinite amount of time.  Without this, our app will just exit.  What we need to do is keep the app alive, and allow for the Timer to keep ticking away calling our Update method.

image

The last set of code (and scroll all the way down) deals with how we update the screen every “period” as discussed above.  There are a few essential details to be aware of:

// clear our display buffer
_bitmap.Clear();

This will clear out the entire screen, leaving it empty.

 

_bitmap.DrawImage(….);

This is how we are drawing our images.

 

And finally we make a call to Flush().

// flush the display buffer to the display
_bitmap.Flush();

This will force the screen to update.

Do take time to review the rest of the code in the Program.cs file, although much of it is around just getting the values to display on the screen, you will familiarize yourself with the style and abilities of the framework.

Now that you have had a look around, hit the F5 Key on your keyboard.  F5 is a short cut which will actually build all of this code, resources, etc.. and package them; gets them ready to run on our emulator.  Once the build is complete it will launch the emulator (or connect to your actual watch) and then deploy the watch face on to it.  If your using the Emulator it should just automatically pop open!

image

Tip: I noticed that after lots of usage the emulator will not really start (the debugger doesn’t actually attach).  In this case just hit F5 again and retry.  If it persist exit VS.NET and try it all over again.  If it persist even further you may have reached your memory limit for the device.

Now that all of the pieces are together, hit the close button on the emulator to exit and return to VS.NET.

Lets customize it!

I’m sure most of us would love a super cool, customized watch face with our own name on it, right?  Lets do that now.

The first thing we will need to do is import a font into the project resources, so double click Resources.resx and hit the “Add Resources” drop down, and choose “Add Existing File…”

image

Browse to

C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Fonts

or if you are on a 32 bit OS

C:\Program Files\Microsoft .NET Micro Framework\v4.3\Fonts

In the File Name text box at the bottom, put a * and hit enter.

image

The fonts should show up now.

Double click the “small.tinyfnt” file, and it will automatically be added into your project – hit save now.

Tip: Keep in mind that like references you do not want to add very many “large” resources.  They will take up the very minimal and valuable space on your device!

In some cases, if your application or watch face is too large it might not even deploy to the emulator or watch, it will just seem like it exit’s!

 

At or about line 92 of Program.cs, lets add some code which will display our name.  Lets first bring in our font:

var smallFont = Resources.GetFont(Resources.FontResources.small);

And then draw some text on the canvas:

_bitmap.DrawText("Rob", smallFont, Color.White, 0, SCREEN_HEIGHT - smallFont.Height);

Lets break this down…

_bitmap is our canvas.

DrawText() allows us to literally draw arbitrary text on the canvas.

“Rob” is the text we are going to draw.

smallFont is the font we want to use when drawing.

Color.White – draw the text with a white brush.

0 is the X or (left and right) coordinate on your device to start drawing

SCREEN_HEIGHT - smallFont.Height is the Y or (top to bottom) coordinate on the device to start drawing.  So what we do here is take the entire screen height 128 minus the height of the font, and start drawing from there down.

This will place the text “Rob” at the bottom left side of the screen, like so:

image

Its hard to see, but notice that our name is now painted over the minute value on the screen.  Take time now to change the above code to write it on the top left of the screen instead of the bottom left.

Pro Tip: Order does matter.  Since we painted “Rob” after the minutes above it was literally painted on top of the 2 in the above screen shot.  Try changing the Color to Black and you will see it in action.  If we were to paint “Rob” first and then the 2, the 2 would cover our text.  This matters when painting a variety of other things on the screen and you need to have one thing painted on top of the other.

VS.NET Templates

Previously we installed the AGENT SDK and along with the new cool emulator, pictured above, you will find two additional project templates to get you started.  In VS.NET, go to File, New Project… and on the left choose Visual C#, Micro Framework you will find the two new templates.

image

 

The Watch face sample running in the Emulator:

image

 

and the Watch Application sample:

image

 

 

Conclusion

This should give you a decent understanding of how to get started using VS.NET and the .NET Micro Framework to develop watch faces and applications for the AGENT SmartWatch.

AGENT: The World's Smartest Watch

AGENT: The World's Smartest Watch

by Secret Labs + House of Horology

Disclaimer:

Most if not all of this content has been gleaned from the comments on the Kickstarter project page and comments section. Any discrepancies between this post and any documentation on agentwatches.com, kickstarter.com, etc.., those official sites take precedence.

Overview

The next generation smartwatch with brand-new technology. World-class developer tools, unparalleled battery life, Qi wireless charging.

Kickstarter Page, Comments

Funding period : May 21, 2013 - Jun 20, 2013

MSRP : $249

Other Urls

http://www.agentwatches.com/

https://www.facebook.com/agentwatches

http://twitter.com/agentwatches

http://pinterest.com/agentwatches/

http://paper.li/robchartier/1371234640

Developer Story

The first official launch of the preview SDK and emulator will happen on 20-Jun-2013.  All development will be done in Visual Studio 2012, using the .NET Micro Framework SDK 2.3.  The SDK will ship with the first round of the expected API for developers along with an emulator.

With that said, there is no need to wait for the SDK.  You can download the tooling now and get started with Apps and Faces immediately.  The only thing that you will not be able to work with is the API; but for example, watch faces, you can start building the basic face rendering with the Bitmap graphics drawing in the .NET Micro Framework.

 

Does it look good?

Before we dig into any more of the gory details, here are a few photos of the current available prototype models.

 

The watch on the tiny QI Charter

 

If you wander too far away from your phone, your watch will let you know with a vibration and a message, all but one button will dismiss the message.

 

An app showing the premium weather data!

 

image

Nice stitching on the straps, leather and silicon will be available, along with a few lengths to choose from (short, regular, long lengths).

On to those gory details….

Hardware Specs

Processor

  • 120MHz ARM Cortex-M4 processor (ATSAM4SD32)
  • with secondary AVR co-processor

Flash & RAM

  • 2MB of onboard flash and 160KB of RAM
  • 1/4 of the onboard flash will be used by the OS
  • The flash is permanent (non-volatile) storage.

Bluetooth

  • Bluetooth 4.0 BD/EDR + LE
  • Bluetooth 4.0 is backwards compatible with Bluetooth 2.1, so classic Bluetooth functions (BD/EDR, SPP/AVRCP/PBAP/etc.) will work fine.

Sensors

  • 3D Accelerometer (Motion) ST LSM303DLHC
  • Ambient Light Sensor
  • Hardware power metering
  • Vibration Motor (You can pulse it to create vibration patterns, not sure about the vibration strength - driven with PWM)
  • No piezo/speaker or microphone.

Other

  • QI Wireless Charging, no NFC, no wall adapter included
  • Custom LED Backlight
  • No GPS in the watch. It uses the GPS in your phone.
  • AGENT watch apps are deployed and debugged wirelessly from your PC via Bluetooth.
  • RoHS, Pb-free

Battery

  • Expected to use a CR2430-sized rechargeable battery – replaceable (Mouser, Amazon)
  • Estimated charging time from empty is 2 hours with provided charger
  • 7 Days typical with Bluetooth on, 30 days with Bluetooth off (watch-face only mode)
  • The battery should last at least 2 years, with 100s of charge cycles.

Physical dimensions

  • Roughly 38mm top-to-bottom on the front face
  • 35mm left-to-right on the front face
  • and around 12mm in depth
  • 22mm strap
  • Two ~1/16" hex screws to attach the watch pin
  • The top watchcase material candidates are PVD stainless steel, brushed matte ceramic, and high-quality polycarbonate (TBD).
  • The glass lens is mineral glass, Anti-glare glass lens

Strap options

  • Leather and silicon straps will be available
  • Expected to have three sizes

Display

Buttons

  • Custom "Pusher" buttons, they will not make noise like a mouse click, and are very durable.
  • The top-left button activates the backlight; bottom-left changes apps; three buttons on the right are up/select/down and can be used for custom purposes by apps.
  • Backup reset procedure is currently activated by holding the home/menu button and the top-right user button for about ten seconds

Device Support

  • Android 2.3 or newer
  • iPhone 4S or newer
  • Windows Phone 8 or newer
  • Heart Rate monitors - Bluetooth SPP or Bluetooth LE (GATT) is what you'll want the heart monitor to support.
  • Almost limitless Bluetooth device support!

Internationalization & Localization

Full UTF8 Support from the ground up.

AGENT's user interface is in English. Your content (caller ID, music tracks, notifications) will be in your native language. We have a plan to cover most major character sets, with Latin characters pre-loaded on the watch.

Simplified Chinese will be available

Feature overview

  • Phone lost alert
  • Caller ID
  • Music Control (possible volume control)
  • Wireless Charging
  • Timer
  • Stopwatch
  • Vibrating Alarm (possibly custom vibrations for caller id)
  • A few default watch faces
  • Airplane mode (by demand or low power)
  • Can be turned off completely
  • Customizable 3rd party watch faces, applications which can be loaded over bluetooth.
  • Sample apps that maybe installed
  • Weather

Sample Apps not installed

  • Exercise App

Other

  • Possible Skype integration over Bluetooth.

They will provide an AGENT app for your smartphone (iPhone, Android, Windows Phone). You'll be able to use it to load apps onto the watch..

You will be able to cancel phone calls. With compatible phones you can also answer, end, etc. They are adopting the standard hands-free profile to provide these features and caller ID.

The Store : Observations from the first week after the release.

 

In order to start this post I want to take a big step back first talk about communities.

Communities, at the base level, really boil down to social interactions of organisms with each other. These organisms coexist in a society. Societies can be thought of people that are related to each other, that share common expectations and/or authority.

Seems simple enough, right?

If we dig a bit deeper into the social interactions of organisms we can begin to get an idea that there are a variety of types of people – as defined by their behaviour. Typically there are 4 types that really stick out, at least for me.

  1. Socializers
    1. This is the biggest group of any community. Usually about 80% of the population.
    2. They are seeking light-weight, non-confrontational easy to reciprocate social interactions with other people.
  2. Achievers
    1. These folks go to great lengths to achieve rewards simple for the prestige of having it.
  3. Explorers
    1. They are involved in the community for the social credit of having discovered something. They love to discover an unknown glitch or a hidden Easter egg.
  4. Killers
    1. These types thrive on competition with others in the community, in order to win and their expense.

Think of each community you belong to and what type of behaviour you typically exhibit. How your actions/interactions impact the overall state of the community.  What is your typical tone within those communities.  Also, are you typically a positive person or do you “bring the hammer” with negativity?  Maybe your a realist? 

No matter your behaviour type and the tone you use, you do impact the community.

 

So why all the preamble?

Its important to understand the nature of our community - DotNetNuke and the smaller/sub community of The Store.  As, essentially, the “authority” for The Store we must keep our eyes and ears open to all input from the community.  We must adapt and change with the “expectations” of our community.  We must learn from each other.  The very second we stop listening to the community (to you) we all lose.

While doing so we are sensitive to the fact that there will always be those people that are very positive – they are looking out for the community and want to see it foster and grow; and then there are the negative types.  I would almost always agree that they too are looking out for the greater good of the community they just express themselves in a slightly different manner.

You must develop a pretty thick skin for those that exhibit a very high level of negativity about any change (good or bad) within the community – after we all cant put our biggest smile on every day, right?

Both of those types serve a huge purpose for the Community and do play an essential role to our collective success.

In this past week, since we launched what we are calling version 2 (v2.0) of The Store we have directly come into contact with pretty much every type of personality out there: Socializers, Achievers, Killers, Positive types, negative types, etc..   Everyone is coming out of the woodworks…

This is awesome!

The most encouraging thing for us right now is that feedback.  Have confidence that we are tracking all items and triaging/fixing the high priority issues as soon as humanly possible.  Gemini (bug tracker) and TFS (source control) are very active with frequent changes.  We are doing our best to keep on top of the list and publishing to production as soon as it makes sense.  Based on twitter there are many of you out there that have directly experienced the fast turn around we strive for, we will do our best to keep that pace going.

Right now, the best way for us to receive feedback is to either email us at  store [at] dnncorp [dot] com, or by using our Help Desk.

 

We need you to communicate, no matter your style - keep it coming!

SnowCovered.com finally gets an upgrade

When we (DNNCorp) originally took ownership of SnowCovered.com from Brice Snow it was running on DotNetNuke 2.1.2 (Release date was June 14, 2004), v1.0 of the .NET Framework and on a low-end hosting provider. Looking back, I recall that we were lucky to get 80% to 90% uptime in any given month. It was on its last legs. We knew, the community knew, we HAD to take action.

Fast forward a little while, and just over a year ago we launched an internal “Upgrade” project for SnowCovered.com. Here is how that story played out…

Our first initiative was to upgrade from the low-end hosting to our own infrastructure which brought up our stability immediately to 99.9% uptime. This was a huge gain for us and the community as a whole. It was nice to be able to rely on solid infrastructure. All of the negativity around the amount of downtime simply fizzled.

Our first significant win!

The next step was to tackle the DNN 2.1.2 issue. For those of you that don’t recall the history of DNN, 2.1.2 was release before the ASP.NET Team release the (then) new Personalization and Membership pieces. The team here spent hours ensuring that every single user in the SnowCovered membership database was upgraded. Countless tests and dry runs were performed, and in the end we prevailed. All users can and will be upgraded fully.

Another win for the team.

The largest task was the actual code base itself. There was a significant amount of rework and simply replacing much of the codebase (VB.NET to C#) as we transitioned it all to the 6.x family of the core framework. At that time we had just hired Nathan Rover and put him on this challenge. He gladly accepted and took the lead. For those of you want have not yet met Nathan, he is a marathon runner – just the man suited for this marathon upgrade and release schedule.

Over the year they took inventory of the feature points, upgraded code, reviewed artwork & designs, cried/yelled/screamed, held design meetings, drank a few gallons of redbull/monster/beaver buzz, QA, upgrade meetings, daily scrums, Unit Tests, more QA, frequent vendor reviews & demos. Project plans were scraped, created and scraped again. We have had churn in almost every aspect of the project.

The team kept running.

There were a few points over the past year were we almost gave up. The stress was high; the light at the end of the tunnel was just barely visible. Nathan and the team pushed on. We persisted.

The team kept running.

Finally the light was blinding. We invited many (~100) of the vendors in for a private Beta; received well over 40 issues, all of which were addressed with great care and attention, and finally accepted the final list of bugs in for the initial RTM release. The team worked day and night nailing these issues down in order to meet our aggressive release schedule, without sacrificing the level of quality we demanded in this release.

As of 3:00AM PST February 9th, 2012 we crossed the finish line!

We are proud to announce that we have released initial public release of "DotNetNuke, The Store"

Congrats goes out to the entire team!

Here is a before screenshot, as of July 19, 2012:

 

image

 

and now…

 

image

 

 

..we are just getting started…

Getting DotNetNuke to render correctly in IE9

As we all download the Beta of IE9 we are faced with the challenge of many sites having breaking changes to the UI.  This becomes more apparent when you have rich functionality provided by vendors such as Telerik, the FCK Editor, or whatever you have chosen internally.

For example, here is a screen shot of DotNetNuke, using our default skin, breaking under IE9 when using the default “IE9 Standards” mode.

 

image

 

What you see above is the Telerik Editor Provider when editing content using the Text/HTML module.  In order to correct the above issue, you must switch IE9 to use a more compatible mode. 

If you bring up the IE9 Developer tools, which are standard now as part of the browser installation, by hitting the F12 key.

You will see the tool shown at the bottom of the browser:

 

image

 

 

Notice the “Browser Mode: IE9” and the “Document Mode: IE9 standards”.  You only need to change the “Document Mode:” drop down to “IE8 Standards”:

 

image

 

You page will refresh with the new Document Mode, and it should now properly be showing the right UI.

 

 

.NET BC : A Lap around WebMatrix; With a dash of Razor

 

Last night most of the DotNetnuke team and I traveled into Burnaby, to the BCIT campus where I gave a real quick (1 hour) presentation on the WebMatrix Beta, and Razor Syntax.

I was happy to see that we had over 60 people attend.  It was awesome to see the turn out on a hot summer evening. 

Download the Slide Deck

There were a number of questions which came up, I will try to remember them all here.

 

Working with Data – the db.Query() execution, can it be parametrized?

@{
var db = Database.OpenFile("SmallBakery.sdf");
var selectQueryString = "SELECT * FROM Products ORDER BY Name";
}
@foreach (var row in db.Query(selectQueryString)){
<tr>
<td>@row.Id</td>
<td>@row.Name</td>
<td>@row.Description</td>
<td>@row.Price</td>
</tr>
}

Yes, you can.  Here is an example.

@{
var db = Database.OpenFile("SmallBakery.sdf");
var Name = Request["Name"];
var Description = Request["Description"];
var Price = Request["Price"];
var insertQuery = "INSERT INTO Products (Name, Description, Price) VALUES (@0, @1, @2)";
db.Execute(insertQuery, Name, Description, Price);
}

What and Who is WebMatrix and Razor targeted to?

Essentially the breadth developer.  Those folks that possibly come from a PHP background or even are new to the development world.  This will allow for them to onboard with a few minor tweaks to existing projects to get up and running as fast as possible.

 

Why is Web Matrix even needed when we have Visual Studio?

The initial thoughts are that this product is going to be free.  It will have a bare minimum feature set targeted to the scripter.  The UI is far simpler than what VS.NET Users are used to.  You could consider it as a a stepping stone into VS.NET.

 

There was some discussion around Razor Syntax and MVC.  Using it as a view engine.  Here are some resources to help with this answer.

http://gurustop.net/blog/2010/07/06/thoughts-on-razor-microsofts-new-asp-net-mvc-view-engine/

and

http://www.dotnetcurry.com/ShowArticle.aspx?ID=561

The topic of LightSwitch came up as well.  Here is the product page

http://www.microsoft.com/visualstudio/en-us/lightswitch

SIMPLEST WAY TO BUILD BUSINESS APPLICATIONS FOR THE DESKTOP, WEB AND CLOUD

Microsoft Visual Studio LightSwitch gives you a simpler and faster way to create professional-quality business applications for the desktop, the web, and the cloud. LightSwitch is a new addition to the Visual Studio family. Visit this page often to learn more about this exciting product.

 

Conclusion

All in all I felt the talk went well.  As usual I went a mile a minute and really tried to slow things down near the end.  Luckily there were enough questions to push us for the full hour.  If you attended feel free to send me feedback and ask questions.  I will do my best to get you the answers – just keep them on topic!

 

 

Resources for the discussion

http://www.asp.net/webmatrix

http://netbc.ca/DNCal/EventDetail.aspx?date=2010/08/24

Sql Scripts - Delete all Tables, Procedures, Views and Functions

In a shared environment you typically don't have access to delete your database, and recreate it for fresh installs of your product. 

I managed to find these scripts which should help you clean out your database.

Use at your own risk.

 

Delete All Tables

--Delete All Keys

DECLARE @Sql NVARCHAR(500) DECLARE @Cursor CURSOR
SET @Cursor = CURSOR FAST_FORWARD FOR
SELECT DISTINCT sql = 'ALTER TABLE [' + tc2.TABLE_NAME + '] DROP [' + rc1.CONSTRAINT_NAME + ']'
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc1
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc2 ON tc2.CONSTRAINT_NAME =rc1.CONSTRAINT_NAME
OPEN @Cursor FETCH NEXT FROM @Cursor INTO @Sql
WHILE (@@FETCH_STATUS = 0)
BEGIN
Exec SP_EXECUTESQL @Sql
FETCH NEXT FROM @Cursor INTO @Sql
END
CLOSE @Cursor DEALLOCATE @Cursor
GO
EXEC sp_MSForEachTable 'DROP TABLE ?'
GO

Delete All Stored Procedures

declare @procName varchar(500)
declare cur cursor
for select [name] from sys.objects where type = 'p'
open cur

fetch next from cur into @procName
while @@fetch_status = 0
begin
if @procName <> 'DeleteAllProcedures'
exec('drop procedure ' + @procName)
fetch next from cur into @procName
end

close cur
deallocate cur

 

Delete All Views

 

declare @procName varchar(500)
declare cur cursor
for select [name] from sys.objects where type = 'v'
open cur

fetch next from cur into @procName
while @@fetch_status = 0
begin
exec('drop view ' + @procName)
fetch next from cur into @procName
end
close cur
deallocate cur

 

Delete All Functions

 

declare @procName varchar(500)
declare cur cursor
for select [name] from sys.objects where type = 'fn'
open cur

fetch next from cur into @procName
while @@fetch_status = 0
begin
exec('drop function ' + @procName)
fetch next from cur into @procName
end

close cur
deallocate cur
More Posts Next page »