Sunday, April 22, 2012 #

Fixing issues with PhoneGap for WebOS on 64-bit Windows

Problem

Recently I was told that in near future I might start working on a project using PhoneGap to create a pilot application for iOS and possibly later use it for other mobile platforms. I have been working with HTML/JavaScript/CSS stack for quiet a while  but I had no experience with mobile development in general and toolset that PhoneGap provides in particular. So I decided that I would start playing with it as soon as I find some spare time so that when time for the project is allocated, I will have some basic understanding of the platform. I do not have an iPad or any OS X devices at home, but I do have Windows machines and TouchPad I picked up during the fire sale which is left unused most of the time, so I decided I will go ahead and use it for PhoneGap development. As it happens sometimes when you start working with a new toolset, you are up to a bumpy start having the development environment set up.

After following the instructions and installing Java, webOS SDK, cygwin and downloading the latest copy of PhoneGap I proceeded to deploying and running the “Hello World” app on my TouchPad. Before I got it actually running, I had to solve the following problems:

  • Running make in cygwin resulted in "palm-package: Command not found Makefile:36: recipe for target 'package' failed make: ***[package] Error 127"
  • Running make after fixing the problem above resulted in "error: 64-bit java required"

If you came across the same problems, here is how to solve them.

 

 

Solution: Short version

  • Go to "directory_where_you_extracted_PhoneGap\lib\webos" folder. Open the Makefile file in the text editor of your choice and search for the term “palm-“. You will find three entries: palm-package, palm-install and palm-launch. Change them by appending “.bat” to the end of the commands, so that they become palm-package.bat, palm-install.bat and palm-launch.bat. Save the file.
  • Now make sure that you installed 64-bit version of Java. You can check it by running “java –version” command in cmd.exe. Next, add path for the Java’s bin directory (typically “C:\Program Files\Java\jre6\bin”) to the Path environment variable (Computer->Properties->Advanced system settings->Environment variables). Make sure to restart cygwin’s bash terminal if it was open, since it copies the windows’ environment variables when it starts.

 

 

Solution: Long version

After having all the prerequisites installed, I opened the PhoneGap\lib\webos directory in cygwin’s bash terminal and ran make command per documentation. Instead of getting the app up and running on my touchpad I was presented with palm-package: Command not found error:

palm_package_error

To verify that the command is indeed unavailable and it’s not just some problem with the Makefile itself (the Makefile is the target for the make command), I ran “which” command:

which_palm_package

My first suspicion was that webOS SDK did not add itself to the Path environment variable. So I fired up cmd.exe and tried palm-package command to see if it works outside cygwin:

cmd_palm_package

As you can see, it works just fine in cmd.exe. So I went to %ProgramFiles(x86)%/Palm/SDK/bin to check what palm-package command actually resolves into:

explorer_palm_package

Palm-package command resolves into palm-package.bat file. Interesting, looks like cygwin is able to call *.exe files just fine, but *.bat files are not found. To verify this I ran “which” command in cygwin’s terminal for palm-package.bat:

which_palm_package_bat

Well, cygwin found it! Quick trip to Google also confirms that this is a known problem. Now that I knew what the problem is the only thing left was to change the Makefile to use [command].bat instead of [command]. Searching inside the Makefile revealed 3 entries in the file that needed to be changed:

makefile_original

So I added .bat extension to the commands:

makefile_modified

Now it all should work and I should finally see my app running on my TouchPad. But wait, what is this?

64bit_java_required_error

I knew for sure that Java was installed. Running “java –version” in cmd.exe showed that it is indeed installed. One thing that I noticed though, was that  I actually have 32-bit version of Java installed and webOS SDK requires 64-bit version. Turned out that there is almost an unnoticeable link “all Java downloads here” on Java download page, which lets you pick between 32- and 64-bit versions of Java. I quickly uninstalled the 32-bit version and installed 64-bit one, ran make in cygwin, but still got the same error. This time I actually went  to Computer->Properties->Advanced system settings->Environment variables and added “C:\Program Files\Java\jre6\bin” to the system’s Path variable. I restarted cygwin’s terminal (it copies Windows environment variables when it starts), changed directory to _PhoneGap_folder/lib/webos, ran make command one more time and voilà – the application is up and running on the TouchPad!

Posted On Sunday, April 22, 2012 2:56 PM | Comments (0)

Monday, June 13, 2011 #

Windows 8, HTML5, JavaScript and Silverlight

Preamble

Microsoft’s first introduction of upcoming Windows 8 spurred lots of discussions among developers. The most noticeable part of the demonstrations at D9 conference and Computex  show, as well as on YouTube, is, of course,  the new touch-centric UI.  So why is it controversial among  developers? Let’s take a look at Microsoft’s press release:

Today, we also talked a bit about how developers will build apps for the new system. Windows 8 apps use the power of HTML5, tapping into the native capabilities of Windows using standard JavaScript and HTML to deliver new kinds of experiences.

So there you got it. What we see here are HTML and JavaScript as a platform for the new Windows 8 UI. What do we not see here? WPF/Silverlight, .Net or any native platforms. No wonder that such message from Microsoft caused hot debates among developers. These two threads over on Silverlight’s official forum account for almost 10 million views (yes, you read it right, millions). This discussion over on Channel 9 generally follows the same direction: developers express their outrage at Microsoft’s pick of technology for the new user interface in Windows 8. I do not want to repeat all the reasons why our fellow developers are so upset about Microsoft’s choice, please, read the discussions at the links above.

I will be honest with you, when I first saw the Windows 8 preview, my first reaction was going to Google, sorry Bing, and searching for “Windows 8 preview html5 javascript silverlight”. I wanted to see community’s take on the announcements, and you already know what I got as a result – many Silverlight/.Net developers were wondering what was going on. Some amount of rage as well (which actually caused closing of one of the forum threads over on Silverlight’s official forums I mentioned above). Microsoft’s message was absolutely unexpected to many. What makes it even worse is that recently Microsoft has had a surprisingly steady track of sending mixed messages about the future of Silverlight. Let’s see what has happened so far.

 

Silverlight? What is Silverlight?

First, it was PDC 2010 conference, where Silverlight was noticeably absent in keynotes and sessions. And also comments from Bob Muglia (former President of the Server and Tools Division at Microsoft) about Silverlight that later required  follow-up blog post from him to assure that Silverlight is not dead. Later Microsoft even held the “Silverlight Firestarter 2010” event as damage control for Silverlight developers so they can rest assured that the future of Silverlight is bright.

But you know what happened next? Mix 11 and again Silverlight was far from being in the spotlight at the event. What is ironical in some way, is that several Microcofties used the Silverlight Firestarter event as a big reason why Silverlight did not get that much attention at Mix 11. See the irony? An event which was meant as damage control for the lack of attention to Silverlight at PDC was the reason for the lack on information at Mix 11. Speaking of learning from previous mistakes…

 

Windows 8 and Silverlight

So the Mix 11 was the second big wave of unrest at Silverlight community. Then comes Windows 8 preview. The new touch-centric UI was introduced. That was for consumers. For developers? This UI is built using HTML5/JavaScript. I do not believe regular consumers care what technology is behind the tile-intensive touch-friendly interface. The message about technologies used for it is clearly targeted at developers, nobody else would really care about it. And developers did notice it. Very loudly did. The most obvious reaction to this message is fear, uncertainty and doubt.

So what does Microsoft have to say about it? Let’s see. First, from Steven Sinofsky (the President of the Windows Division at Microsoft) at his Q&A session after the preview of Windows 8 at D9 conference:

Q: Where is Silverlight in all this?

A: There’s still a place for Silverlight, says Sinofsky. “The browser that we showed runs Silverlight and it will still run on the desktop.”

Are you surprised that this question was asked just a couple minutes after the demonstration of Windows 8 had been done? Me neither. But the answer speaks for itself, I do not think that I need to comment on it.

Next is Pete Brown’s (Microsoft Community Program Manager) comment on Silverlight’s forum:

As to everything else: You all saw a very small technology demo of Windows 8, and a brief press release. We're all being quiet right now because we can't comment on this. It's not because we don't care, aren't listening, have given up, or are agreeing or disagreeing with you on something. All I can say for now is to please wait until September. If we say more before then, that will be great, but there are no promises (and I'm not aware of any plans) to say more right now. I'm very sorry that there's nothing else to share at the moment. I know that answer is terrible, but it's all that we can say right now. Seriously.

Pete clearly admits that what Silverlight and .Net developers are hearing right now from Microsoft is not really what they want to hear. And honestly, I just do not understand why Microsoft is doing this. They could very simply avoid this. If Microsoft really has awesome news coming for Silverlight developers, then why, instead of building expectations and getting them excited about what is coming in the future for them, did Microsoft choose to upset them? Simply not talking about HTML5/JavaScript during the preview would not cause any unrest among developers. As simple as that. If you are going to talk about Windows 8 development platforms only at the BUILD event in September and not earlier (at least that’s what Microsofties are talking about), just apply the same for HTML5/JS and everybody would be happy. And talks like the Sinofsky’s answer do not help either.

 

Conclusion

I do not know what the future for Silverlight is. I do not know if it is considered as one of the important platforms inside Microsoft, or if they are slowly but surely letting it to sink into oblivion. I cannot talk about the future of Silverlight as I have no knowledge about it like anybody outside of Microsoft. What I know though, is that Microsoft is doing (and has been doing for awhile now) a very poor job communicating about Silverlight and, as a result, has irritated its developers on more than one occasion. Some might overreact or draw conclusions on anything but speculations, but it is Microsoft itself who is letting this happen.  Microsoft needs to stop doing this and be more open and straightforward with its developers.

Posted On Monday, June 13, 2011 12:40 AM | Comments (5)

Thursday, May 19, 2011 #

Channel 9 videos mass download tool

You probably have already visited Channel 9, and if you have not I would recommend to definitely check it out. There are literally thousands of videos about development using Microsoft technologies (and more).  You can watch the videos on the site using Silverlight player or you can use links on each video page for downloading. This usually works fine if you are interested in just one or a small number of videos, but it might become somewhat tedious if you want to download a bunch of them. I recently wanted to do the latter and this is how http://dayngo.com/channel9 was born.

Actually, it all started with this year’s MIX 11 event which I was unable to attend. I was quite interested in web-related sessions and saw that they started to pop up on the Channel 9 website. I was particularly interested in ASP.NET MVC and Silverlight topics. I realized that I will end up downloading quite a bit of videos and there is definitely an opportunity to automate the process. Since I am interested in Silverlight but do not have a chance to use it at work, I decided to use Silverlight for this little project. Also, since browsers and Silverlight (an out-of-browser implementation with elevated rights felt like an overkill in this case) have severe limitations when it comes to file system manipulations, I decided to use wget to do the actual downloading. Two nights later the initial implementation was done. As I saw that the tool has gained some popularity, I made some UI tweaks and called it done.

events, series, shows, blogs, post selection

Fast forward several weeks and  I realized that TechEd is coming, which means tons of videos of sessions I would like to watch. This time around, though, I had some time in advance before the event, so I decided to extend the MIX’11 tool so that it would allow not only to download one particular event, but become a mass download tool for the entire Channel 9 video content. I could definitely reuse some of the parsers from MIX11 tool, so I thought it is not going to take too much effort to refactor the code. And, of course, as it often happens with early estimates,  I was wrong. Long story short, because of the way Channel 9 organizes content, reusable code from MIX11 tool is like 5% of the code I ended up writing for the new tool.

videos selection

Nonetheless, the tool is up and running at http://dayngo.com/channel9. I extended the initial implementation so that now it can produce not only a batch file that utilizes wget, but also a PowerShell script. Those who decided to use wget (and it is my personal preference for this purpose), notice that it might be more convenient to put path to wget.exe into your system PATH variable, thus you do not have to put batch file next to wget executable.

The content of the tool is updated daily, around 4 AM CST. As I noticed during the development that Channel 9 keeps updating content for events well after the event ended (adding new sessions or uploading videos in other formats), I re-check and update event videos during those daily updates for 21 days since the event start date. Other content (shows, series, blogs) is consumed by the tool as it appears on the Channel 9 site and is not revisited afterwards.

Both scripts detect the already downloaded videos (by file name), so you can interrupt the download if you need to, just make sure to remove the last partially downloaded file (the one that has been downloaded when you interrupted).

I hope some of you will find this tool useful. Let me know if you have any questions about the tool, and any feedback is welcome.

Update 5/21/2011:

I have noticed that some events have more that 150 sessions on Channel 9 website, but my tool tops at 150. Turned out they use paging on the event’s page, so my tool was parsing only the first page. This is fixed now and for some events there is much larger number of sessions available. Series, shows and blogs did not have this problem.

 

Update 2/2/2012:

Even though this tool started as “exercise” while learning Silverlight, due to shift in my interest and all the things happening with Silverlight (also Microsoft is still keeping mum on Silverlight 6), I switched the tool from Silverlight to HTML+JavaScript.

Posted On Thursday, May 19, 2011 9:37 PM | Comments (12)

Thursday, September 30, 2010 #

Wake a PC on LAN using magic packet (F#)

Has it ever happened to you that you are sitting with your laptop and need to do something with a computer on your local network and it turns out that computer is in a sleep mode and you have to walk to it and move the mouse or press some key to wake it up and then come back to your laptop to do what you initially wanted to do with it? Indeed, if you have to walk to a computer rather than remotely access it than the benefit of having local network is already somewhat undermined. My particular situation is worsened by the fact that I usually work on my laptop in the living room on the first floor and from time to time I need an access (ideally remote access) to my desktop on the second floor on the opposite side of our house so it is not all that convenient, especially if I just want to do something really small and get it done quickly. For example, if I am ready to do some programming and realize that I forgot to check in some code while I was working on my desktop. And then the desktop is already in a sleep mode (I do care about power consumption) so the remote desktop connection is not an option. Or even worse if for whatever reason I need to access my desktop for just a minute from my work computer at the office. I believe you can think of some other examples too.

All this lead me to research tools which would allow me to wake up a computer remotely. Google immediately brought me this article in Wikipedia: Wake-on-LAN. Seems like this is exactly what I need. There are several limitations mentioned in the article but none of them is a blocker for my computers’ setup. Looking at the article it might seem that it is somewhat complex to implement in code, but turned out that there is only one small paragraph that really matters for implementing this solution in code: Magic Packet. Without further lyrics let’s dive into the code that allows us to wake up a computer on local network. Notice that the snippet is really small and simple and mostly consists of comments (the majority of which are copy/paste from the Magic Packet paragraph in the Wikipedia article).


// see http://en.wikipedia.org/wiki/Wake-on-LAN#Magic_Packet
module WakeOnLan
// The magic packet is a broadcast frame containing anywhere within its payload 6 bytes of 255— // all bits set to the on position—which has // the hexadecimal representation of: FF FF FF FF FF FF let header = [for x in 1..6 -> 0xFFuy] // , followed by sixteen repetitions of the target computer's 48-bit MAC address. let tail (mac: byte list) = [for x in 1..16 do yield! mac]
// the MAC address of the computer we are trying to wake up let mac = [0x00uy; 0x22uy; 0x1Duy; 0xCBuy; 0xE9uy; 0xA9uy] // and now form the magic packet let magicPacket = header @ (tail mac)
// it is about time to send our magic packet to the sleeping PC open System.Net open System.Net.Sockets let udp = new UdpClient() // the magic packet may be sent as a broadcast packet of any network- // and transport-layer protocol. // It is typically sent as a UDP datagram to port 0, 7 or 9 udp.Connect(IPAddress.Broadcast, 0(* could be 7 or 9 *)) udp.Send(List.toArray magicPacket, magicPacket.Length) |> ignore udp.Close()

Yes, it is really that simple. Of course this is just a snippet and I have hardcoded MAC address and so on but I can really just save this code as fsi script and run whenever I need or run it in Visual Studio or F# interactive. I will probably end up making it a WCF service and host it on my home server so that I can wake up my computers from any place that has an internet connection. And ASP.NET MVC client plus an app for my smartphone. As Windows Phone 7 recently came under my learning radar I may even end up with WP7 client for the server Smile Stay tuned!

Posted On Thursday, September 30, 2010 12:14 AM | Comments (2)

Tuesday, September 28, 2010 #

The first post

This is going to be my first blog post. I'm not going to post anything particularly meaningful this time, the intent is just to kick off blogging. Hopefully, I will be posting on a regular basis.

Lately I have been interested in WP7 development and as Microsoft is approaching the release date for their phones I am expecting Microsoft to be extremely  active with events, releasing documentation and other materials to get developers up to speed with the new platform (if the word “new” could be used here as it is Silverlight-powered environment…). Finally I came across a series of such events (click on the image to go to the event registration web site):

http://www.msdnevents.com/wp7devlaunch

Unfortunately none of those will be held in Kansas…

Posted On Tuesday, September 28, 2010 4:53 PM | Comments (6)