Agent Emulator & Bluetooth Device Communications

Yay the Agent smart watch preview SDK is available. You can find it here:

http://www.agentwatches.com/

One of the 1st questions that springs to mind is how do we go about some sort of Bluetooth communication with anything from the emulator? Then I spotted this in the comments section of the Agent kickstarter page:

image

So that got me looking onto how this works so I set about following the instructions and here is the results of my findings:

PC Settings

image

The diagram above depicts how your host PC should be set up . Basically what you see here is that standard Bluetooth on the host machine is capable of providing COM Port based communication.

COM ports go back to the days of RS232 serial and Centronics parallel communication.They take care of the transmission of bytes between machines, Once you have a COM port open each device can send bytes down the wire.

To enable paired devices to open the COM port on your host PC you need to ensure that there is an incoming com port this is done in the Bluetooth settings:

image

You need one incoming COM port, this is done by tapping the add button and selecting incoming as the connection type.

Emulator settings

When you install the Agent SDK it installs the emulator with a standard settings configuration file if you have used the defaults then this config file will be located here:

C:\Program Files (x86)\Secret Labs\AGENT SDK\Emulator\v4.3\AGENT Emulator.exe.emulatorconfig

Open this file and you will see the following section

    <PhysicalSerialPort id="COM1">
      <ComPortHandle>Usart1</ComPortHandle>
      <PhysicalPortName>COM3</PhysicalPortName>
    </PhysicalSerialPort>

Here you set the PhysicalPortName to the name of the port that you have ben given in the Bluetooth settings,

You are now ready to start writing code within your agent application that accepts connections from external paired devices.

Paring a windows phone

image

One area where people get bogged down in when paring a phone with your local PC is that after paring the phone does not stay connected. They tap on the phone in the list and it says connected but then appears to drop the connection after a short period of time.

To understand this you have to ask yourself why would the phone want to be connected via Bluetooth in the first place.The answer being that there isn’t any reason for it. There are no shared services that are part of each OS that require a connection so when the phone realises this it drops the connection.

It’s not until your application opens a connection to a service on the paired PC that the connection becomes active.

From what I know and given this scenario it is not possible for the Agent application to initiate communications with the paired device.

The Agent Application

NOTE: The rest of the code mentioned here will be based upon the AGENT SDK v0.1.1 (June 2013, Preview Release) and will be subject to change as the SDK gets closer to it;s version 1 release.

Given that the Agent emulator has a virtual COM port all the work is carried out using Stream based objects. The System.IO.Ports.SerialPort object is derived from System.Stream, so if you are familiar with working with streams then this should be familiar territory.

To add a serial port to your code that uses the host Bluetooth connection you just add the following line of code:

var serial = new SerialPort(“COM1″);

To make the serial port ready for data then you just open it:

serial.Open();

Ok so now we need to know when data is being sent to the application.This is best done by adding an event handler to the DataReceived event.

serial.DataReceived += _serial_DataReceived;

static void _serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
{

//get data here

}

Agent app wise that’s it for this blog post if you want to see more implementation then have a look at the demonstration code linked at the bottom of this article.

The Windows Phone Application

A good place to start when writing a Bluetooth application for Windows Phone 8 is the Bluetooth App to device sample.

NOTE: One thing to remember when writing a Windows Phone application that uses Bluetooth is to set the ID_CAP_PROXIMITY app capability within your WMAppManifest.xml file (double click the file within VisualStudio) :

image

My example uses some simplified code to connect to the target machine and then send some data to the agent application.

image

When the connect button is pressed the following code is called:

private async Task<bool> SetupDeviceConn()
{
   
//Connect to your paired host pc using BT + StreamSocket (over RFCOMM)
    PeerFinder.AlternateIdentities[“Bluetooth:PAIRED”] = “”
;

    var devices = await PeerFinder.FindAllPeersAsync();

    if (devices.Count == 0)
    {
       
MessageBox.Show(“No paired device”
);
       
await Windows.System.Launcher.LaunchUriAsync(new Uri(“ms-settings-bluetooth:”
));
       
return false
;
    }

    PeerInformation peerInfo = devices.FirstOrDefault(c => c.DisplayName.Contains(“****YOUR PC NAME HERE***”));
   
if (peerInfo == null
)
    {
       
MessageBox.Show(“No paired device”
);
       
await Windows.System.Launcher.LaunchUriAsync(new Uri(“ms-settings-bluetooth:”
));
       
return false
;
    }

    _socket = new StreamSocket();
   
await _socket.ConnectAsync(peerInfo.HostName, “{00001101-0000-1000-8000-00805f9b34fb}”
);

    _dataWriter = new DataWriter(_socket.OutputStream);

    return true;
}

This code is initialises the peer finder service then gets a list of  devices. After that it users a filter of the list to find the peer that contains the name that is given by you (replace the ****YOUR PC NAME HERE*** with the name of your PC as it appears in the devices list).

If the function returns true then a socket connection to the Agent application has been made.

The second button “send stuff” sends the contents of the text box to the agent application. The button tap  calls the following code:

private async void CmdSendStuff_OnTap(object sender, System.Windows.Input.GestureEventArgs e)
{     _dataWriter.WriteString(txtText.Text + '');     await _dataWriter.StoreAsync();
}

In this case the sending of data is simple because we have the use of the DataWriter class to make things easy for us.

The source code can be found here:

https://projects.developer.nokia.com/agentexamples/browser/agentexamples

Useful Links:

http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207007(v=vs.105).aspx

http://forums.agentwatches.com

Tagged with: ,
Posted in Agent, C#, Windows 8, Windows Phone

External NFC (Proximity sensor) for Windows Store Apps

If you are looking for a way to add NFC support to your windows store applications then  you have two options. The first is make sure you buy your hardware with an in built proximity sensor. This option is quite a layout of cash if you already have a desktop/laptop etc that you do your development on.

The second option is to purchase an external NFC card reader. For this your options are limited because of Windows 8 driver support. There is one however that was found by both  Peter Footand Craig Hawker this is the FeliCa RC-S380 compact USB NFC reader and it is available in the UK from NFC Stuff at £88.68 (delivered).

If you do purchase this reader you will find that it does not install the drivers when you plug it in. to rectify this you will need to download and install the NFC Port Software from here: http://blog.felicalauncher.com/en/?p=594

Once installed you will see the sensor listed within the proximity devices list in device manager:

image

That’s it you now have a machine that will allow you to develop NFC enabled Windows Store applications.

Here is a couple of links to help you on your way…

http://blogs.msdn.com/b/windowsappdev/archive/2013/04/18/develop-a-cutting-edge-app-with-nfc.aspx

http://www.silverlightshow.net/items/Near-Field-Communication-in-windows-8-part-1.aspx

Thanks once again to Peter for helping me out.

Tagged with: , , , , , ,
Posted in NFC, Windows 8

Windows Phone – Notifications & Companion Devices

Hello again! It sure has been a while since I last posted but I am now going to get back into the swing of things, to start things off here are some thoughts I have had in regards to notifications and companion devices on the windows phone platform (A cross post from a forum post I made on the verge that can be found here: http://www.theverge.com/2013/2/15/3991692/windows-phone-notifications) .

Thoughts …

People say that Windows Phone lacks a notifications centre. This isn’t totally true there is a notifications area within Windows Phone here it is from my phone:

image

What is lacking is that the application notifications are missing. These notifications are the toast notifications that can be pushed to your phone by an external service or raised by one of the background services running on the phone (don’t get me started on those).

I admit this is a little hidden and maybe could do with an easier route UX wise. But IMHO all that is required is that this list is added to when a notification is raised. It’s the simplicity of this that confuses me when Microsoft say they couldn’t get this into WP8 before release.

One area that I see related to this and something that the people at MS need to act upon very quickly stems from a whole new device type that is gaining some traction and rising consumer expectation. That is wearable tech like the Pebble smart watch and others:

http://www.theverge.com/2013/1/28/3925364/pebble-smartwatch-video-review

Others:
http://www.theverge.com/2013/1/8/3852340/cookoo-smartwatch-hands-on-pictures http://www.theverge.com/2012/1/10/2697038/im-watch-hands-on-pictures

If you do a search on the WindowsPhone user voice site for Pebble you will see 5 existing suggestions with about 600 votes for support:

http://windowsphone.uservoice.com/forums/101801-feature-suggestions?query=pebble

Not a great number I know but how many people do you know that use the User Voice site ;)

All of this adds up to the need to be able to push the notifications including the number of unread emails, TXTS etc. out from the device onto an external display via a third party service. Something that the sandboxed environment that developers are provided with just does not allow.

Another problem is that the background tasks that the API provides are now allowed to run as regularly as is required or a task like keeping a companion device updated.

The way I see it is that the API requires a new app capability that is associated with a request for access to the user to allow the application to gain access to the notifications and read information like email, texts and calls (calendar and contacts are already a feature).

This will also require an event based hook so then an application can register to be notified when a relevant phone based event happens rather than having to run an agent in the background.

All lot of work to be done please MS please make it so!

UPDATE: There is a new kid on the block that should make things easer for app developers. Check out the Agent smart watch :)

Posted in Uncategorized

Moving on…

PicturesLab_Lomo_FX_2011-10-14_14-19-37Friday 28th October will be my last day working for Sequence a talented full service Digital Agency in Cardiff.

I started in Sequence back in January 2007 where I had my sites firmly set on being a development team manager. After a year of trying I found that I had actually re-discovered my love for crafting code and designing / developing systems so I settled back into the position of Senior Developer.

During my time at Sequence I have had the pleasure of working on a variety of projects that have ranged in size from a small application to a large enterprise system. All of them in some way or form being web based.

The one project that really stands out for me and will actually go down as the highlight of my career so far was the Snow+Rock Pathfinder application. This Windows Phone 7 application started life as a pitch to Microsoft for a showcase application that was passed over in terms of showcase application in favour of other bidders. Luckily for Sequence one of these other bidders pulled out and left a gap that because of our designs and how the application was shaping up we were able to fill.

This resulted in me working closely with the Microsoft DPE team working very hard to get the application to pass the high Microsoft quality baseline right up to the make or break point before it got installed on  a bunch of press phones for the pre launch event.image

The biggest highlight was when Paul Foster of the DPE sent an email letting me know that the app panoramic had been used during the professional developers conference (as you can see in the pic).

Pathfinder is still winning awards and only last week won an award at the Cardiff Design Festival.

The other technologies that I have had the pleasure of using have included Azure, SharePoint, Silverlight and Dynamics CRM this goes to show that the whole of the Microsoft product stack is what interests me and I enjoy producing solutions with.

Why leave?

Sequence has built a reputation for great design and do constantly deliver well designed web sites but the opportunity to work in any medium other than HTML are scarce. Now the time is right and I feel that I would like to work on some projects that push my buttons, I find XAML a much more exciting way to build UI’s that feels so much more right and polished then HTML. That said I won’t be totally abandoning Web based projects but variety is the spice.

I would like to take this opportunity to thank the people at Sequence for making the last 4 years hectic, interesting, taxing … well everything you would expect when working at an agency!

So what’s next?

I am moving on to a much smaller firm that’s a little closer to home. Here I will have the opportunity to push those buttons of mine.

What about the Cardiff WPUG

Up until now Sequence have been kind enough to help with the group even going as far as providing the drinks. Another thing that I would like to thank them for. The group is however going with me and I will continue to organise events. Yes things have been quiet recently and I do apologise for that but plans are afoot so expect some news soon.

Posted in Uncategorized

Adding a map image to a secondary live tile.

Does your app use live tiles to pin a tile that relates to a location that has a known Latitude and Longitude? If so did you know that it is easy to have a map of that location appear on that tile. This is done by using the Bing maps imagery service.

For starters lets look at how you create the tile in code:

var secondaryTile = new StandardTileData                  
{  
    Title = "Title Title",
    Count = null,
    BackgroundImage = new Uri("/Background.png", UriKind.Relative),
    BackBackgroundImage = new Uri("/BackBackground.png", UriKind.Relative)                 
};

ShellTile.Create(navUri, secondaryTile);

As you can see both the BackgroundImage and BackBackgroundImage take a Uri in the code above. The Uri above is specified as Relative this means that the images can be located within the apps content (as part of the XAP file) or within the applications isolated storage.

You are however not restricted to relative Uri’s you can specify Absolute Uri’s for the image. This opens up the ability to have the image come from an external web server. This is where the Bing maps imagery API comes in.

The API is a RESTfull service which means that all calls to get an image is nothing more complicated than a Uri Smile

Here is how a call to get a map image looks:

http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/47.644829750061,-122.141661643982/15?mapSize=190,190&&key=****ENTER A KEY HERE***

This produces the following image:

You can find out more about using the Bing maps Rest services here : link with the  details of the imagery services found here: link You will also need to get yourself an application key so that you can use the service. Details can be found here: link

so for adding the image to a live tile all you need to do is get the Uri in the correct format and set that to be the source image of the tile here is an example how how I go about this:

string strURi = string.Format(
	"http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/{0},{1}/15?mapSize=190,190&&key={2}", 
	lat, lon, key); 

var secondaryTile = new StandardTileData 
{ 
	Title = selectedLI.Name, 
	Count = null, 
	BackgroundImage = new Uri("/Background.png", UriKind.Relative), 
	BackBackgroundImage = new Uri(strUri, UriKind.Absolute) 
}; 

ShellTile.Create(navUri, secondaryTile); 

The lat, lon and key variables have all been set prior to calling this code.


This is how the tile looks in the emulator:

2011-09-09 08h16_02

As you can see this is a rather simple way of adding some extra information to one of your tiles.

In the next blog post I hope to extend this further and add some additional graphics to the background. I will also be making use of the powerful WP7Contrib library.

Posted in C#, Live Tiles, Windows Phone, WP7

I passed!

2011-07-14 08h25_06

There was I thinking that my exam didn’t go well but this morning I got notification that I had passed the exam!

This is the 1st time that I have been an MCP in any way. I am well chuffed!

Tagged with: , , ,
Posted in Phone

An end to the good times before they even start? …

On may the 18th I published an article that actually managed the biggest view numbers that I have had on any blog post that I have previously written:

More good times for app developers?

I think this is mainly down to the fact that it was an attempt to spread some good news for developer who develop .net applications using XAML and c# or VB.

As of now there are 20K+ applications for windows phone 7 and this list is growing at quite an impressive rate. This rate of growth is because of the ease at which these developers can write applications. People who work for large corporates developing enterprise applications using .NET can now become app publishers and can deviate from writing anonymous code that drives a cog of large enterprise systems.

These people I have met at our growing local user group. They are loving the application development platform that Microsoft have put together for them and have a hunger for more.

If you are a developer that has been developing code for Android or iPhone then you will have started with a single form factor in which your code runs on and found that that the available form factors has increased and you now not only develop for the phone but your apps can be made to run on the new and emerging tablet based devices.

Microsoft have made great strides with Windows 8 to ensure that it has the capabilities to run on a multitude of form factors. It is here that they are hedging their bets on windows running anywhere.

So where will we stand when it comes to Tablets and native development when can we start re-using our code from within those 20K+ applications so that we can start reaping the benefits of the next set of platforms.

Well from what Microsoft have disclosed in regards to the Windows 8 developer experience so far that just won’t be happening.

There has just been no message from Microsoft that states that don’t worry we still do native, and it will work within this snazzy new UI.

It’s all been HTML and JS as a brand new application development platform.

If this stays the case then once you are a Windows Phone developer you will be staying a Windows Phone developer and if you have a great app then you will have to port it.

Right now the message is that people will have to wait for the Build conference to actually find out what the developer story will be. And of course more and more FUD will enter the mind of us developers as time goes on.

One item that may enter peoples heads is that Microsoft are shifting their developer strategy and application platform to HTML and JS even on Windows Phone (ARM and SOC means that Win 8 can power a phone at some point – phones are mentioned in the Intel article).

If people start experiencing this kind of fear and uncertainty they are going to stop developing apps and the rate at which the marketplace is building will slow down if not stop.

We so need to know what’s happening and we need to know sooner rather than later.

Tagged with: , , , ,
Posted in ARM, C#, Phone, Silverlight, Windows 8, WP7
Follow

Get every new post delivered to your Inbox.