Wednesday, November 25, 2015

Raspberry Pi 2, Windows IOT Core, and TP-Link TL-WN725N - overcoming windows IOT Core not supporting wifi dongle

This article may not have long-term relevancy as Microsoft continues to make Wifi Dongles Compatible with Windows IOT Core and/or release newer versions of Windows IOT Core.

At the time of this writing, the Windows IOT Core (Insider Preview) download is version "10556.0" :
https://ms-iot.github.io/content/en-US/Downloads.htm



If you take a look at The list of supported RPI2 Wifi Dongles, you will see that 2 wifi dongles are supported with Windows IOT Core:

  • The official Raspberry Pi Wifi Dongle
  • The TP-Link TL-WN725N


Unfortunately, the TL-WN725N does not work.
After following the RPI2 installation instructions,  It doesn't register in the WindowsIOTCoreWatcher:



Some investigation on the raspberry pie forums led me to 2 conclusions:
Microsoft apparently accidently stated that the TL-WN725N is compatible with Windows IOT Core.
There is a newer version of Windows IOT Core Preview (10586) that will work with the TL-WN725N
This version is hard to get, and is apparently buggy.  Thankfully, there is a download for it.
The catch is, If you install it, you will not be able to debug to your RPI2 in Visual Studio.

Thankfully there is a Technet Article / Blog Post that illustrates steps to make the newer (unreleased?) version work.
It's a bit hacky, as you will be copying and pasting files from the older version to the newer version.
I doubt this is officially supported, but it works!

Following the steps in the article allowed me to disconnect my ethernet cable and debug to my RPI2 using just the TL-WN725N wifi dongle!

I'm really just relaying my discoveries in one place.
Use at your own risk.
Hopefully Microsoft will release an updated version of Windows IOT Core Soon.

Alex

Friday, September 18, 2015

SQL Server AutoIncrement Issues



I am experimenting with SQL Server's AutoIncrement Functionality today, as I don't want to manually insert ID's into a database table every time I add a row, instead I would like to insert rows into the table and have the ID field automatically increment automatically based on each inserted row. I'm struggling getting the AutoIncrement functionality to work, as I am attempting to insert rows and I am getting the following error

     Cannot insert the value NULL into column 'PersonID', table      'MyLocalTestDataDB.dbo.Customers'; column does not allow nulls. INSERT fails.
     The statement has been terminated.

Let's start from scratch:

The MySQL Syntax is the following:
     CREATE TABLE Customers
     (
          PersonID int NOT NULL AUTO_INCREMENT,
          ...
     )

However, I'm using SQL Server, which uses a different Sytnax:

     CREATE TABLE Customers
     (
         PersonID int IDENTITY(1,1) PRIMARY KEY,
         ...
     )


The nice thing about this Identity([],[]) Syntax is that you have the flexibility to decide at which Number to begin incrementing from, and the interval between increments when each row is added.

IDENTITY(1,1) means the first row added will have an PersonID of 1, and each additional Row will be incremented by 1. (1,2,3, etc.)

IDENTITY(50,5) means the first row added will have a PersonID of 50, and each additional Row will be incremented by 5 (55, 60, 65, etc.)

You can make your Identity Column the Primary Key, or not make it the Primary Key if desired.


Back on track, why am I seeing the error?

It appears that the Column is not properly set as an AutoIncrement Column.  Since the column is a Primary Key, Null Values are not allowed.  When you insert a new row with an AutoIncrement Column, you can ignore adding data to the AutoIncrement column and let the AutoIncrement Functionality take over. 
In my case the AutoIncrement Column is also the Primary Key, so assuming the column is set to AutoIncrement, I can ignore populating data into this field with my T-SQL Insert Statement.

Since it's not being recognized as an AutoIncrement Column, it's interpreting the data entered into that column as null in the SQL Statement.  In the T-SQL Query Below, the PersonID Primary Key / AutoIncrement Field is intentionally absent from the query, under the assumption that the AutoIncrement behavior will take over.

     USE MyLocalTestDataDB;
     INSERT INTO [MyLocalTestDataDB].[dbo].[Customers] (LastName, FirstName, Address, City)
     VALUES ('Holmes', 'Sherlock', '221B Baker Street', 'London');

I performed some investigation. One potential approach is to validate and set the column as auto-increment in SQL Server Management Studio per the following steps:

Open your table in Design View




Select the Column and go to Column Properties
In the 'Identity Specification' section, set 'Is Identity' to 'Yes, AND 'Identity Increment' to '1'




When I try to save this table, I get the following message, preventing me from saving the changes:




This appears to effectively be the UI Equivalent of the T-SQL approach, and It appears that you are forced to re-create the table anyway.
          PersonID int IDENTITY(1,1) PRIMARY KEY

What was my Resolution?
I recreated the table with T-SQL instead of the UI and it worked perfectly.

     DROP TABLE Customers
     CREATE TABLE Customers
     (
          PersonID int IDENTITY(1,1) Primary Key,
          ...
     );

     USE MyLocalTestDataDB;
     INSERT INTO [MyLocalTestDataDB].[dbo].[Customers] (LastName, FirstName, Address, City)
     VALUES ('Holmes', 'Sherlock', '221B Baker Street', 'London');

Message:
     (1 row(s) affected)


What happened?
I potentially may have created the table without the AutoIncrement Definition IDENTITY(1,1) without realizing it.

OR:

My hypothesis is that because I created the table without the IDENTITY(1,1)
          PersonID int PRIMARY KEY
Then deleted and recreated using the IDENTITY(1,1)
          PersonID int IDENTITY(1,1) PRIMARY KEY
and somehow it got cached, or SQL Server Management Studio wasn't recognizing that I re-created it with the Identity(1,1).

At any rate, when in doubt, re-create the table! Assuming that this wasn't user error (which certainly is a possibility!), this solution might be the SQL Equivalent to the Windows Restart (when all else fails, reboot!).

I hope this may have been helpful for someone.



Wednesday, June 17, 2015

Build Tour 2015

I attended the Build Tour 2015 (not the same as the main Build Event), and I got acquianted with some of the new development technologies that Microsoft is introducing.

Here's some bulletpoints (not comprehensive):


  • Everything can be built using the new Universal App Template.  Windows Apps, Windows Phone Apps, Hololens Apps, XBox Apps, etc.
  • Universal Apps will be compatible with the new Hololens
  • The new Internet Explorer is Windows Edge, also known as Project Spartan.
  • There will be an HTTP2 protocol
  • Become an insider for Windows 10 updates by registering at insider.windows.com
  • Check out some of the new windows 10 development information at dev.windows.com
  • Tons of APIs at Machine Learning Gallery
  • There was a presentation on BabylonJS, which implements WebGL for 3d modeling in the browser.

I'm starting to dig into Windows 10 now in a Virtual Guest Environment.  the updated start menu is much better than windows 8.  My first voice command to Cortana was "Who is Master Chief" and she opened up Project Spartan.  I thought it was an inside joke at first, but she just took me to a bing search with my question.

The voice stuff is cool and I might try to play around with the API sometime later.

The Hololens API isn't available yet, but Microsoft recommends signing up for the insider program and getting familiar with Universal Apps in the meantime to prepare for hololens.

Saturday, January 24, 2015

I Recently used the JSTree plugin for the first time.  It has it's own API and it has quite a bit of functionality. 

In my experience, it is often not well-documented or easy to follow.
I decided to outline some highlights of how to use the plugin, areas that might not be well documented, discoveries that I made, and potential issues/bugs.

Hopefully, these might save time for others.
This is somewhat of a tutorial (not comprehensive)

Resources
JSTree's Home Page: http://www.jstree.com/
There is a corresponding GitHub site with alot of the Readme Information: https://github.com/vakata/jstree
You'll likely need to alternate between the two.

PART I.

Create Tree

You can create the JSTreea few different ways.  A couple examples:
 1. Create an initial HTML Structure, then call the jsTree function:
  <div id="myDiv">
   <ul>
    <li><a>Hello Thar!</a>
     <ul>
      <li><a>Good Day!</a></li>
     </ul>
    </li>
   </ul>
  </div>

 $(document).ready(function () {
  $("#myDiv").jstree();
 });

  Note: I first attempted to use multiple ajax calls to populate the html from a data source.  In my case, not all of the ajax calls returned before the .jstree() was called and not all of the content was converted from an unordered list into the tree.  Be careful with this.

 2. A better more practical way to create the tree: leave an empty <div> placeholder, and create your structure via the API:
  <div id="myDiv">
  </div>

  $(document).ready(function () {
   $("#myDiv").jstree();

   //Create Root Node and Child Node to match section "1" HTML structure
   var rootNodeRet = $("#myDiv").jstree('create_node', '#', { 'id': '#j1_1', 'text': 'Hello Thar!' }, 'last');
   $("#myDiv").jstree('create_node', rootNodeRet, { 'id': '#j1_2', 'text': 'Good Day!' }, 'last');
  });

  (I'll cover the API a bit later)

Plugins/Types:

 You can change or modify the base JSTree functionality by passing a JSON Object during the initial .jstree() call. 
 This includes built-in plugins, such as types or sorting.
 Plugins with examples are listed on the JSTree Site: http://www.jstree.com/plugins/

      Plugins Example:
 From the JSTree HomePage:
    $("#myDiv").jstree({
            "core" : {
      "check_callback" : true
       },
      "plugins" : [ "dnd" ]
    });

 In this example, the "dnd" plugin allows drag and drop functionality.  In the UI, You should be able to drag a node and place it at any level in the tree and it will automatically move there.
 The 'core' and 'check_callback' nodes of the json object are required for this particular plugin to work.

      Types Plugin:

  The Types Plugin is noteable.  There is a Themes plugin, with built-in themes that modify the Look and Feel.  I will not cover Themes, but Types are conceptually similar to a "custom theme."
  You can apply a type to a specific node, or the entire Tree Structure.
//Example:
      $("#myDiv").jstree({
            "core" : {
                "check_callback": true,
            },
            "types": {
                    "tree": {
                        "icon": "http://jstree.com/tree-icon.png"
                    },
                    "lightning": {
                        "icon": "glyphicon glyphicon-ok"
                    }
    },
     "plugins" : [ "types" ]
   });

  Both the "Tree" and "lightning" types can be set to a node with the following syntax:
  //  This only updates the root node icon/type
  $("#myDiv").jstree("set_type", "#j1_1", "tree");

  You can also override the default type to apply this to all of the nodes:
   $("#myDiv").jstree({
            "core" : {
                "check_callback": true,
            },
            "types": {
                    "default": {
                        "icon": "http://jstree.com/tree-icon.png"
                    }
    },
     "plugins" : [ "types" ]
   });

Interaction/API

      1. Node Attributes:
You can update the following common attributes (not comprehensive list) for each individual node in the tree:
 id         - set_id
 text      - set_text
 theme  - set_theme
 icon     - set_icon
 type     - set_type

 //An example of setting the node text to "Hi Thar!"
 //In this case of setting the text, pass #j1_1, which is the id of the node we are changing the text for
    $("#myDiv").jstree('set_text', '#j1_1', 'Hi Thar!');

  If you want to do a get, you need to use the same Syntax above:
   //get
    $("#myDiv").jstree('get_text', '#j1_1'); //'Hi Thar!'
    $("#myDiv").jstree('get_theme', '#j1_1'); //'default'

      2. Node Selection
If you want to perform the action of "selecting" a node in the Tree, there are multiple ways of accomplishing this.
Examples listed by the JSTree homepage:
 a. $('#myDiv').jstree(true).select_node('child_node_1');
 b. $('#myDiv').jstree('select_node', 'child_node_1');
 c. $.jstree.reference('#myDiv').select_node('child_node_1');
 "b" is probably the most current/common approach.

Strangely/Unfortunately, All this really does is selects the node in the UI, similar to clicking a node with the mouse.
 As criticism, in my opinion, the documentation concerning API isn't overtly clear concerning the differences between:
  * Getting a node object for updating properties/attributes
  * Selecting the node as a selected/clicked node in the UI

 You might assume that you can pass the selected node as an object to the set_(xyz) functions as a parameter, but this doesn't work:
   //Not the correct syntax
   var myRootNode = $('#myDiv').jstree('select_node', '#j1_1');
   $("#myDiv").jstree('set_text', myRootNode, 'Hi Thar!');

  Instead, you need to use the syntax indicated in Step 1 with the hardcoded string of the ID:
   //Correct syntax
   $("#myDiv").jstree('set_text', '#j1_1', 'Hi Thar!');

  You also cannot get the node ID From a select_node to pass into the set_text function, partially because there is no get_id function in the API
  (it would be redundant to do this anyway, because you used the ID to get the select_node object to begin with).

 After Selecting a node, you can deselect them in the UI with the following approaches:
  Deselect all nodes in the UI (select multiple nodes in UI with ctrl+ mouseclick):
   $('#myDiv').jstree('deselect_all');
  Deselect specific node based on the ID:
   $('#myDiv').jstree('deselect_node', '#j1_2');

3. Creation
You can create a node with the following syntax:
 $("#jstree").jstree('create_node', parentNodeObject, value, 'last');

The child node syntax (the 'value' parameter above) needs to be a JSON Object of a format similar to the following:
       {
         id : "string",
         text : "string",
         icon : "string",
         state :
         {
            opened : boolean
            disabled : boolean
            selected  : boolean
         },
        children : []
       }
 None of the nodes/options in this object are required.
 (Full information on node structure on JSTree site: http://www.jstree.com/docs/json/)


Like Setting Attributes, you can't create a node by using the 'select_node' function, then passing it as a parameter to the create_node function.
 //Wrong Syntax:
  //select parent node using 'select_node'
   var rootNodeRet = $('#myDiv').jstree('select_node', '#j1_1');

  //New node JSON Object
   var newNodeJs = { 'id': '#j1_1', 'text': 'Hello Thar!' };

  //Create Node under parent
   $("#myDiv").jstree('create_node', rootNodeRet, newNodeJs, 'last');

You can, thankfully, create a node with the hard coded id of the parent node.
 //Correct Syntax (using hardcoded ID[string]):
  //New node JSON Object
   var newNodeJs = { 'id': '#j1_1', 'text': 'Hello Thar!' };

  //Create Node
   var rootNodeRet = $("#myDiv").jstree('create_node', '#j1_1', newNodeJs, 'last');

For Creating a Root Node, use the "#" sign instead of a reference to a Parent Node:
 //Root Node Json Object
  var newNodeJs = { 'id': '#j1_1', 'text': 'Hello Thar!' };

    //Root Node Create Call passing newNodeJs
    var rootNodeRet = $("#myDiv").jstree('create_node', '#', newNodeJs, 'last');

Additionally, a useful approach might be to store your new nodes in var objects, such as the following:
After your initial Creation of the root node, you can pass a reference to the parent node object:
 // 1. Create the root node
  var rootNodeJsObject = { 'id': '#j1_1', 'text': 'Hello Thar!' };
  var rootNodeRet = $("#myDiv").jstree('create_node', '#', rootNodeJsObject, 'last');

 // 2. Create the child node with reference to Root Node Object you created (rootNodeRet)
  var firstChildNodeRet = $("#myDiv").jstree('create_node', rootNodeRet, { 'id': '#j1_2', 'text': 'Good Day!' }, 'last');

 // 3. Use firstChildNodeRet to add a third-level child inside the second level:
  $("#myDiv").jstree('create_node', firstChildNodeRet, { 'id': '#j1_3', 'text': 'Happy Festivus!' }, 'last');

  (In 2 and 3: The Node will be added regardless of whether you associate the function with a 'var' object or not)
 I spent a good amount of time troubleshooting why select_node wouldn't work as a parameter until a colleague/mentor discovered this for me.
 It might be helpful if this was documented more clearly on the JSTree site.

Monday, February 24, 2014

I've been enjoying using the JavaScript CSOM (Client Side Object Model) in SharePoint 2013 lately.  Here's some basic JavaScript for querying SharePoint list data.

//ensure loading of the sp.js file
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', spReady);

// The spReady() Function is the callback function
function spReady() {
// Create an instance of the current context.
// Get context based on current site -- this way you won't have to hardcode the url for the current site
    var clientContext = new SP.ClientContext.get_current();

    myList = clientContext.get_web().get_lists().getByTitle('<LISTNAME>');

//CAML Query to get all list items from the default list view
    var query = SP.CamlQuery.createAllItemsQuery();
// Get all of the list items based on the query
    spListItems = myList.getItems(query);

//Load the list items
    clientContext.load(spListItems);
        clientContext.executeQueryAsync(onLoadSuccess, onLoadFail);
}


function onLoadSuccess()
{
 var spListEnumerator = spListItems.getEnumerator();
        var item;
        var fieldvalue;

//Enumerate through each listItem
        while (spListEnumerator.moveNext())  {
            item = spListEnumerator.get_current();
//Get the field value in the current list item and display it as an alert.
            fieldvalue= item.get_item('<FIELDNAME>');
            alert(fieldvalue + " is the value of your requested SharePoint field!");
        }
}

Wednesday, March 27, 2013

Welcome!

Hello, Welcome to my SharePoint Blog. 
I will be updating it every so often, when I feel there is something worthy to contribute or when I have spare time.