What is the Internet of Things?

You’ve no doubt seen talk of the Internet of Things, or the Internet of Everything even, but you may still wonder what it is. Well, it isn’t a product or a feature you will buy, it has more in common with the “information age” or “industrial revolution” then “smart phone” or even the Internet itself.

It took me a while to warm up to the idea. At first I thought it was just marketing hype, but now I am really excited and see it as part of a huge trend that is going to really change life as we know it. In fact we’ve already seen a lot of the changes. The Internet of Things (IoT) isn’t something coming someday; it is something already here and is only going to get bigger.

Gartner's 2014 Hype Cycle of Emergine Technologies

Gartner says we are 5 to 10 years away from seeing the full productivity of IoT

 

The basic idea is that all sorts of “ordinary things” get connected to the Internet, but I believe that really misses the point. IoT is really the combination of four technologies: The cloud, computer miniaturization & commoditization, smart devices, and ubiquitous connectivity. I’d say ubiquity is a theme of IoT. These four technologies have been gaining steam individually, but as they come together we see massive changes.

Over the next few blog posts we can discuss each technology individually, and then we can discuss what they mean together. I’d love to hear your feedback along the way.

Did you know RAD Studio XE7 is great for building apps that connect with the Internet of Things? I’ll discuss that more in some of my future posts, but right now there are a lot of great special offers that make upgrading to XE7 a no brainer. I’d feel bad if you missed these special offers because you were waiting for me to get to the point. If you just download and activate the trial by Nov 21st you get a free copy of Nick’s book.

Developing on the Samsung Gear Live Smart Watch

Previously I created a blog post about using Delphi and RAD Studio XE7 to develop for the Moto 360. The new FireUI Multi Device Designer (MDD) makes is a breeze to design for the new smaller UI. I’ve since updated the FireUI Devices project on GitHub to cover the Samsung Gear Live & LG-G watches in addition to the Moto 360.

I thought I would walk through the steps for developing with the Samsung Gear Live. One advantage it has over the Moto 360 is that it has a physical USB cable connection, so you don’t need to deploy via BlueTooth. This makes for a much faster deploy cycles. With a USB cable though, you need to install the ADB USB Drivers.

  1. Put the device in USB Debugging Mode
    1. Hold the home / side button until the settings menu appears (couple seconds)
    2. Select About and tap Build Number until it notifies you that developer options are enabled.
    3. Swipe left to right to go back
    4. Select Developer Options and enable USB Debugging.
  2. You still need to have the watch paired with a phone via the Android Wear app since the confirmation dialog is displayed there.
  3. Run the SDK Manager / Android Tools and Make sure you have Android SDK Tools, Platform-tools and Build tools updated (this moves the ZipAlign.exe, so you need to tell the IDE where to find it.)
  4. Install the Samsung Android USB Driver for Windows
  5. Gear Live should appear as an Other Device in device manager once you connect it to windows via USB.
  6. Select Update Driver Software
  7. Browse my computer for Driver software
  8. Let me pick from a list of device drivers on my computer
  9. Then select ADB Interface
  10. Select SAMSUNG Android ADB Interface
  11. On your phone you will see a dialog “Allow Wear Debugging” Check “Always allow .. . ” and then select OK.

Gear Live - Device Manager Driver Update

 

Once you have done all of that, it will show up in your IDE as a target, and when you load the FireUI custom device for it, then you will have a great design surface for it too.

GearLive in XE7 IDE

 

And you are ready to build your Gear Live app with Delphi XE7.

Delphi XE7 on the Samsung Gear Live

I’m sure I’ll have more coverage on Android Wear in the coming months too.

Voice Enable Your Android Apps

During CodeRage 9 I revisited adding voice support to Android apps. There are some updates from my previous skill sprint coverage on the topic and my original post on launching Google Glass apps via Voice.

You can download the Samples and Components on GitHub. It covers voice recognition, text to speech and launching apps on Google glass with your voice. The examples also cover Android Wear.

Voice Launching Google Glass Apps

  • Add a Voice Trigger XML file:
  • Modify the Android Manifest Template:
    • Add an Intent Filter
      • <action android:name=”com.google.android.glass.action.VOICE_TRIGGER”/>
  • Add Meta Data for Filter
    • <meta-data android:name=”com.google.android.glass.VoiceTrigger”
             android:resource=”@xml/my_voice_trigger” />

Custom Glass Voice Trigger

  • Change XML to from Command to Keyword.
  • Use arbitrary text for voice trigger.
  • Use the Development permission:
    • <uses-permission
      android:name=”com.google.android.glass.permission.DEVELOPMENT”/>
    • Added to android manifest template
  • Not allowed for app store distribution
    • Usable for in-house or ad-hoc use

Additional Prompts on Google Glass

  • Collect additional Voice recognition input when app is launched.
    • Add an Input Prompt to the Voice Trigger XML
      • <?xml version=”1.0″ encoding=”UTF-8″?>
      • <trigger command=”TAKE_A_NOTE”>
      •     <input prompt=”What shall I say?” />
      • </trigger>
  • In FormCreate get speech guesses from Intent Extras
    • SharedActivity.getIntent.getExtras. getStringArrayList(TJRecognizerIntent.JavaClass.EXTRA_RESULTS);

Voice Recognition on AndroidAndroid/Google - Speak Now

  • Prompts user for voice input
  • Returns up to 5 “guesses”
  • Works offline too
    • (only returns 1 guess)
  • Reusable component for download.
  • Requires RECORD_AUDIO & INTERNET permissions.
  • Sends audio to Google’s servers.
  • Uses context to select words.
  • Pronounce punctuation (period, comma, etc.)
  • Works on Android phones & tablets
  • Works on Google Glass
  • Works on Android Wear
  • Doesn’t work on iOS (no exposed API)

Using TSpeechRecognition Component

  • Properties
    • Language: en-US
    • Prompt: Speak now
    • AlwaysGuesses: True
  • Methods
    • Listen
    • ListenFor
  • Events
    • OnRecognition
    • OnRecognitionEx
    • OnCommand

Text-To-Speech on Android

  • Converts Text to spoken word.
  • Reusable component based on Jeff Overcash’s translation.
  • Code shows example of handling Java Listener events.
  • Works on Android phones & tablets
  • Works on Google Glass
  • Doesn’t work on Android Wear (no speaker)
  • iOS Support is possible . . . . (needs implementation)

Using TAndroidTTS Component (component name may change)

  • Just one procedure: Speak

A Note About iOS

  • iOS does not expose voice recognition API
    • (Need to use 3rd party)
  • iOS 7 supports Text to Speech API
    • AVSpeechSynthesizer
    • Just haven’t implemented in component yet

Google Glass Voice Trigger Sample

The replay video will be available here later.

Download the XE7 Trial today and check out the special offers.

Fire UI and the Multi-Device Designer

During CodeRage 9 I had a session on Fire UI and the Multi-Device Designer. You can also check out my previous post on creating a custom FireUI view for the Moto 360.

Fire UI is made up of three parts:

  1. Behavior Services – Runtime & design time platform design information
  2. Multi-Device Designer – Unified project – Tweak UI for platforms
  3. TMultiView Component – Adaptive layout

Behavior Services at Design Time

  • Examples:
    • TTabControl.TabPosition
      • Bottom on iOS, top otherwise
    • Font.Size & Font.Family
    • Many controls have Size.PlatformDefault = True
    • TMultiView mode

Behavior Services at Runtime

  • TBehaviorServices class in FMX.BehaviorManager.pas
  • IDeviceBehavior defines
    • GetDeviceClass: TDeviceInfo.TDeviceClass;
    • GetOSPlatform: TOSPlatform; // Windows, OSX, iOS, Android
    • GetDisplayMetrics: TDeviceDisplayMetrics;
  • IFontBehavior defines
    • GetDefaultFontFamily & GetDefaultFontSize

OS Specific example

 var
  DeviceBehavior: IDeviceBehavior;
begin
  if TBehaviorServices.Current.SupportsBehaviorService(?
    IDeviceBehavior, DeviceBehavior, Self) and
    (DeviceBehavior.GetOSPlatform = TOSPlatform.iOS) then
    // behavior specific to iOS
end;

Display metrics example

var
  DisplayMetrics: TDeviceDisplayMetrics;
begin                        // self is a form in this case
  DisplayMetrics := DeviceBehavior.GetDisplayMetrics(Self);
  if DisplayMetrics.AspectRatio > x then
    // AspectRatio specific behavior
end;
type
TDeviceDisplayMetrics = record
    PhysicalScreenSize: TSize;
    LogicalScreenSize: TSize;
    AspectRatio: Single;
    PixelsPerInch: Integer;
    ScreenScale: Single;
    FontScale: Single;
end;

More Information

Check back later and I’ll have the video replay available too.

Download the XE7 Trial today and check out the special offers.

Meet Me in São Paulo, Brazil at the Embarcadero Conference

Last year was my first visit to the Embarcadero Conference in São Paulo, Brazil and I loved it. So I am going back again this year. As an added treat I’m be joining Marco Canto, the Delphi product manager. We both speak together on Delphi Present and Future, then Marco does The Fun Side of Delphi and later I’ll cover Internet of Things, Bluetooth and AppTethering when I will also show some Delphi powered Brain-Computer Interface demos and a lucky volunteer will fly a quadricopter with their thoughts.

The Embarcadero Conference in Brazil is huge with a lot of great sessions. I always consider it a treat when I get to see Marco’s Fun Side of Delphi presentation. I wonder if he will show off the Elf & Wizard classes that are new in XE7?

New XE7 Android Features Skill Sprint

XE7 is full of new features everywhere, but there are some really nice ones specific to Android. Here is a replay of my Skill Sprint session on New Android Features.

The new Android specific features in XE7 include:

There are lots of other new features that are not specific to Android, but that will still help make your apps amazing for Android, iOS, Windows and OS X.

Hello Moto 360 from Delphi XE7

Moto 360I really like my Moto 360 watch. It looks fabulous, and does great as an extension of my Android phone, but of course the most important question is how to make an app for it. Turns out it just works with RAD Studio X7, Delphi or C++. Thanks to the new FireUI Multi-Device designer I can actually create a custom view in the UI to make designing the perfect user interface a breeze. Here are some of the details of what I discovered along the way, followed by a download of my sample and the custom view.

The bottom line is it just works, which really isn’t a surprise. Most new Android devices use ARMv7 and the NEON instruction set. (NEON is kind of like the MMX standard on the Intel platform. At first not everyone used those instructions, but once they caught on, everyone did.) So it is no surprise that the Moto 360 does too. Unlike some of the other watches, the Moto 360 does not have a micro USB port. So you have to use ADB over BlueTooth. This requires a few extra steps to setup, and is really slow to deploy over. So slow I canceled the first two deployments because I thought I set something up wrong.

First of all, the Moto 360 display is not perfectly round. It has a flat area on the bottom. If you look closely you can see the light sensor there. Not sure if that was why it wasn’t round, or if there was another design reason. In any case, the screen resolution is 320 x 290 pixels at 213 Pixels Per Inch. This means at design time you have a usable area of 240 x 218 pixels. This is the information we need to create a custom view. Just put the following code in a package.

  TDeviceinfo.AddDevice(TDeviceinfo.TDeviceClass.Tablet, ViewName,
    // The Moto360 is 320x290 phyiscal and 240x218 logical with 213 PPI
    TSize.Create(320, 290), TSize.Create(240, 218),
    TOSVersion.TPlatform.pfAndroid, 213,
    True); // Exclusive

The Device class enumeration actually has a Watch class, but looking in the code that detects the class at runtime and it doesn’t know how to detect a watch yet. So it defaults to Tablet. It makes sense if you think about the fact that XE7 was released before the Moto 360. I imagine an update will address this.

The requirement to get the custom view to show up in the IDE is you need to update the XML file found at %AppData%\Roaming\Embarcadero\BDS\15.0\MobileDevices.xml to reference the new view. Inside the MobileDevices element, add the following:

  <MobileDevice>
    <Displayname>Moto360</Displayname>
    <Name>Moto360</Name>
    <DevicePlatform>3</DevicePlatform>
    <FormFactor>2</FormFactor>
    <Portrait Enabled="True" Width="240" Height="218" Top="102" Left="29" StatusbarHeight="0" StatusBarPos="0" Artwork="C:\Users\jim\Documents\Embarcadero\Studio\Projects\HelloMoto360\Moto360.png" />
    <UpsideDown Enabled="False" Width="240" Height="218" Top="0" Left="0" StatusbarHeight="0" StatusBarPos="0" Artwork="" />
    <LandscapeLeft Enabled="False" Width="240" Height="218" Top="0" Left="0" StatusbarHeight="0" StatusBarPos="0" Artwork="" />
    <LandscapeRight Enabled="False" Width="240" Height="218" Top="0" Left="0" StatusbarHeight="0" StatusBarPos="0" Artwork="" />
  </MobileDevice>

You’ll need to update the path to that Artwork to point to the correct location of the PNG on your system. Or you can just leave it blank. Here is what it all looks like when setup in the IDE.

Hello Moto 360 in the XE7 IDE

You’ll notice a red circle on the design surface. I added this to see where the corners are (since the display is round). At runtime you can just barely see the red if you hold the watch right. In production I’d hide this at runtime. I placed the TCircle at -1, -1 and set the size to 242 x 242. This way the circle follows the bezel and not the display area of the screen. I suppose if I bumped it out another pixel it would disappear completely at runtime.

To get the Moto 360 to show up as a target device you first need to enable Bluetooth debugging.

  1. Hold the side button in until Settings appears
  2. Swipe down to About and tap it.
  3. Tap on build number until it tells you that you are a developer.
  4. Swipe back to settings and then tap on Developer options.
  5. Tap on ADB Debugging until it says Enabled.
  6. Tap on Debug over Bluetooth until it says Enabled.
  7. On your paired phone, go into Android Wear settings (gears in the upper right)
  8. Enable Debugging over Bluetooth.
    1. It should show
      • Host: disconnected
      • Target: connected
    2. Target is the watch, Host is your computer.

Then you connect your phone that is connected to the Moto 360 via USB and run the following commands (assuming ADB is on your system path) to connect via Bluetooth. I made a batch file.

[dos]
@echo off
REM optional cleaning up
adb disconnect localhost:4444
adb -d forward –remove-all
REM this is the connection
adb -d forward tcp:4444 localabstract:/adb-hub
adb -d connect localhost:4444
REM these lines are to see if it worked
echo Here is the forwarded ports . . . .
adb forward –list
echo.
echo Wait a second for it to connect . . . .
pause
adb devices
[/dos]

The ADB Devices list should show something like

List of devices attached 
123456abcd device 
localhost:4444 device

Now the Android Wear app on your phone should show

  • Host: connected
  • Target: connected

Be sure that your Moto 360 app uses the unit that defines the Moto 360 device (from your package). This way your app can select it at runtime. If you do all that, you’ll see something similar to this with it running on the Moto 360:

Hello Moto 360 from Delphi XE7

My camera had a hard time focusing on it, but rest assured it looks fabulous! I tried C++ too, and no surprises, it works as well. More experimenting to do, but it is nice to know I have a tool that will take me everywhere I want to go.

If you don’t have a Moto 360, you can setup an Android emulator (AVD) instead. I did that before mine showed up. You need to download the Android 4.4W (API20) SDK Platform and ARM System image.

Android Wear SDK Download

Then create an AVD with the new Emulator.

Android Wear AVD Settings

It actually gives you the rectangle screen with a round bezel. Also it is 320 x 320 (so completely round) and 240 PPI. This means the view I created (since it was exclusive) won’t work on the emulator. You’ll need to create a new custom view for the emulator, but I’ll leave that up to to.

you can download all of my code for the custom view, Bluetooth ADB batch file, and sample apps from Github. (Update: Added a view for Galaxy Gear Live & LG-G) BTW, XE7 adds local Git support, which is another great new feature. Download the trial and check it out.

The FireUI: Multi-Device Designer in RAD Studio XE7

Here is the video replay, slides and resources from my Developer Skill Sprint on the new Multi-Device Designer in RAD Studio XE7. This is one part of the new FireUI, the evolution of FireMonkey.

The Multi-Device Designer is a new feature in Appmethod, RAD Studio, Delphi and C++Builder XE7 that makes it easy to maximize the reuse of your visually designed forms across devices, while also getting the most flexibility and customization as possible.

Design your UI once for Windows, OS X, iOS and Android, then customize it for different screen sizes: iPad, iPhone, Tablet, Google Glass, Surface Pro, etc.

You can view the slides on Google Docs.

Check out the Guided Tour on the Welcome Page and the following DocWiki pages:

Check out the other skill sprints too. . .

What About Blackberry?

One of the most common questions we get when we talk about new features in Delphi, C++Builder and RAD Studio is “What about Blackberry?” which is almost as common as similar questions about Windows Phone or Linux. iOS and especially Android rule the smartphone OS market, but Blackberry still has a place on most charts (unlike Symbian and some others).

IDC: Smartphone OS Market Share 2013, 2012, and 2011 ChartWell, now RAD Studio XE6, Delphi, C++Builder and Appmethod support 96.8% of the shipping platforms thanks to the latest update to Blackberry 10 (10.2.1 or later), it now supports running Native Android APK apps without needing to port. I tested on a Z10 developer device, but it should work on Q10, Q5, Z30, or others. To be clear, Blackberry still runs their own OS, but that OS is able to run Native Android Apps.

Our IDE doesn’t recognize the Blackberry device, again because it is not running Android. But once you build your APK you can transfer it to the Blackberry device using whatever method is most convenient for you. I used Dropbox. Once you have the APK on the Blackberry you simply need to install it.

I built a few samples, including one that takes a picture, and they all more or less worked as expected. When the ShareSheet came up, the usual suspects like Facebook and Twitter were not there, but I didn’t have those set up yet on my test device, so that is to be expected.

You can take things a step further and repackage and sign your app to distribute through the Blackberry store, but that isn’t necessary. You can deploy your APK directly to the Blackberry, or distribute it through the Amazon App Store. Crackberry has a guide on installing APKs too, with a little more detail.

The Blackberry Developer site has useful pages:

How to Get Answers to Your Questions

I love helping people out with technical challenges. I don’t always have as much time as I would like to dive into the details of their code though. Occasionally I get requests for help that are completely unactionable on my part. A while back Eric S. Raymond wrote a great guide for How to Ask Questions the Smart Way. If you haven’t read it I recommend it. I’ll summarize some of my tips here, which may or may not agree with his write-up. Hopefully these will be useful as you ask for help elsewhere. These are the steps I use when I ask others for help, or post on Stack Overflow.

One note, this isn’t intended to be taken as a complaint or rant. Just some useful tips to expedite the process of asking for help.

  1. What are you trying to do? – Just saying “This doesn’t work” is not enough information. Let me know what you are trying to accomplish. Also, if you can tell me some context and why, then I might be able to suggest an alternative method to accomplish the objective – you may be trying to do something the hard way. A while back a friend of mine asked me of the DOS Interrupt to reverse the scroll direction of text. I didn’t know, so he spent a few more hours researching it. When he was done he showed me the assembly routine he wrote to delete a line of text and then move the text bellow it up to take it’s place. Once I knew what he was trying to accomplish I could tell him there was already a routine in the CRT unit that did exactly that.
  2. What have you tried? – What debugging steps have you taken? Did you set a breakpoint? Did you try it on a different device? Did you consult the documentation? Did you consult the platform APIs? Did you reboot the device? Did you read what the error message said and try adjusting your code appropriately? Depending on what you are doing, there are different troubleshooting steps you should be taking. If you can tell me what you have done, and what the results were then that saves me from asking you if you “tried turning it off and back on again?” I’ve forgotten that simple step many times, and it is amazing how often it fixes the problems. If you haven’t tried anything else yet, do that first.
    We've tried nothing and we're all out of ideas
  3. Include a link to related documentation – Believe it or not, I don’t have every API memorized. To save me from doing some Googling, include some links to the pages you consulted in your troubleshooting. If you don’t have any links, then either you need to do some searching, or you need to let me know there is no documentation for what you are working on. Also, this may explain better what you are trying to do, and where you are getting your information. If you are reading an outdated document then that may be the problem, but if I don’t know where you are getting your information then I probably won’t know to suggest that. Also, by showing me the resources you’ve already tried then I won’t waste your time by sending you those links.
  4. Let Me Google That For YouTry searching Google, Stack Overflow, Forums, etc. first – Occasionally it is nice to get the question that I can answer just by pasting it into Google and replying with the first link. Makes me look smarter than I really am, but after a while it gets old. Often times I’ve found that after I search for something and don’t find any results, I’ll compose my question to a real person differently than my original search terms. I then take that question and paste it back into Google and the answer appears.
  5. Be Specific and Relevant – For example if you are having some issues calling the Facebook API from a FireMonkey mobile application, it is useful to know you are only seeing the issue from your rooted Android tablet, using XE5, running the beta of Android “L”. On the other hand, I probably don’t need to know the color of your device’s case or your Facebook password.
  6. Don’t send source unless asked – Please don’t paste in your entire project source code, including forms, etc. unless I ask you to. Often times it just results in an unwieldy long email message or blog comment that I need to scroll through to find the pertinent information. Sometimes it is useful to send source though, and I generally recommend trying to recreate the issue in a sample program before asking for help, just as a troubleshooting step. That isn’t always possible though, so explain why in your email too. Now when asking on other forums, etc. observe the tradition there. If you are submitting a bug report then a test case is a good place to start.
  7. Avoid Personal Attacks – I used to work with a guy that whenever dealing with someone else’s code, software, library, tool, etc. would say “If I wrote code like that I’d lose my job.” One time I pointed out it was his code. He didn’t learn. It is never necessary to insult someone, even if you believe you’ve found a bug. I’d wager that any programmer who has not written any bugs has not written enough code. Even if you are not attacking me, I don’t like working with people who feel it necessary to belittle others.
  8. Stack OverflowDo some leg work yourself – This one is kind of hard to explain, but on sites like Stack Overflow they call them “homework questions.” Sometimes someone ask a question that sounds like it was part of their homework. The corollary is if you are asking a question like “What happens if I try to reference an object after I free it?” Or even more complex questions, but where the answer is obtained by simply doing what you ask and observing the outcome. I might know the answer off the top of my head, but often times I would need to do the same level of work you would to test it. Now if you are curious if “X works on Y” where you don’t have access to Y, then let me know in your question. Likewise if you did test something, and are getting inconsistent results and what a better understanding, explain that as well.
  9. Explain it to a Teddy Bear – The Teddy Bear PTeddy Bearrinciple is where you try to explain the problem out-loud to a Teddy Bear, as if you are trying to get an answer. It is amazing how often just going through the process you will answer your own question, or maybe realize your question doesn’t make any sense. If you don’t have a Teddy Bear you can use your dog, child, spouse, statue of Blaise Pascal, picture of Niklaus Wirth, shrine to Charles Babbage, etc. You can take it to the next step by imagining what answers, questions or challenges might be offered to your question. It is OK to have a full on conversation with an inanimate object.

Personally I’ve found that frequently when I prepare a proper question I find the answer before I need to ask it. Especially if I try to create a test case. That won’t always be the case though, and that is fine.

What tips do you have for getting better answers? What do you do before asking for help?