Tag Archives: android

Using MQTT and Eclipse Paho in Android Things

A couple of days ago, Google announced that they were essentially rebranding Brillo to Android Things (I do love that name, by the way!), and finally opening it for a Developer Preview.

There are a few things I already like very much in Android Things:

  • It is already supported on Intel EdisonNXP Pico and Raspberry Pi 3, and there are ready to use filesystem images that you can just flash to get going with Android Things in just minutes.
  • The Rainbow HAT sensor kit that’s available for Raspberry Pi is very cool, and includes a 4-digit LED display, 7 RGB LEDs, a temperature and barometric sensor, a piezzo buzzer for basic PWM-based audio, and three capacitive touch buttons. Sparkfun has a kit that’s targeting the Edison, while Adafruit’s kit is general purpose and meant for breadboard enthusiasts.
Rainbow HAT for Raspberry Pi (Photo credit: Pimoroni)
  • Anyone who’s tried to manipulate low-level peripherals using Java will be pretty happy to see that Android Things’ Peripheral I/O APIs provide nice wrappers for GPIOsPWMI2CSPI and UART.
  • Implementing IoT sensor drivers taps into the existing sensor framework you may already be familiar with if you’ve already tried to access the gyroscope or light sensor of an Android device in your app, and the same SensorManager API you’re already used to can be used with your new devices (for which a driver may already exist, and if not adding a new one does not seem overly complex)
  • Finding good development tools for building IoT solutions is always a challenge. It’s great to be able to leverage the Android SDK tools and Android Studio for things like device emulation, debugging, etc.

I just received my Rainbow HAT today and thought I would use the opportunity to do a quick tutorial on how to use MQTT with Android Things, using Eclipse Paho. What’s more, I’ll also show you a cool feature in mqtt-spy that will allow us to easily display the live temperature on a chart.

I used the Weather Station example from Android Things as a starting point, as it is already including code to publish data to the cloud using Google Pub/Sub. My fork is available on Github, and as you can see the changes to the original example are very limited!

Check out the video, and let me know if you have any questions!

How to setup Eclipse for Android Wear development

Last week at Google I/O, the Android Wear platform was officially launched, together with two smart watches from LG and Samsung.

I wanted to play around with the new APIs for Wear devices for an upcoming blog post on how to use MQTT with you smart watch, but I had to do a few things to properly set up my environment, and I thought I’d share 🙂

I am assuming that if you read this blog post you have already a running, up-to-date, installation of the Android Development Tools.
Also, you should have installed, with the SDK manager, the Android 4.4W (API 20) SDK + Samples, as well as the Android Support Repository. And if you’ve done so already, it’s likely that you’ve been stuck not being able to compile an Android Wear project properly, for some classes seem to be missing…

Check out the following tips, and feel free to post a comment to report how it went for you!


The UI support library for Wear contains, among other things, a set of helpers to build UIs that work well on both square and round displays. In order to add this support library to your workspace, you must go find the file ./extras/google/m2repository/com/google/android/support/wearable/1.0.0/wearable-1.0.0.aar in your Android SDK folder. This is the support library in the AAR bundle format, that we need to convert in a project we can use in Eclipse.

  1. First, copy the .aar file to a location of your choice, change its extension to .zip, and unzip it
  2. In Eclipse, create a new project from this unzipped folder, using the File > New > Android Application Project wizard Capture d’écran 2014-07-04 à 10.10.59
  3. Once the project is created, there are two extra steps to perform to make it properly usable by your future Android Wear projects. First, is to move the classes.jar file in a “libs/” folder that you should create in the project. Second, is to edit the project preferences to make sure that the project is setup as a library project targeting Android API 20 (see screenshot below). Capture d’écran 2014-07-04 à 10.12.59

If you end up with something like this, you’re in a good shape! Capture d’écran 2014-07-05 à 12.14.55 You can now create you own Android Wear project, or import one of the samples that come with the SDK, and add the Wear support library as a dependency, as depicted below:
Capture d’écran 2014-07-05 à 12.45.19

WatchActivity is missing

Now you may notice that the “Blank Wear Activity” project template generates an Activity that extends WatchActivity, which is nowhere to be found in the SDK. Never mind this error, just extend a regular Activity instead and you should be just fine. See this StackOverflow answer.

Timeout when debugging over Bluetooth

ADB is an amazing tool for everything debug on Android platforms, and the ability to deploy apps on your watch and debug them over Bluetooth is really awesome. The setup of the debug link (which is actually done through your phone’s ADB connection) is well documented, but since the connection is rather slow you will need to update ADB connection timeout settings in your preferences.

Go to Preferences > Android > DDMS > ADB connection timeout (ms) and set a timeout of 30s (30000).
Capture d’écran 2014-07-05 à 13.00.57

Android Developer Challenge

Les 50 heureux gagnants (parmi 1788 !) de 25.000$ ont été annoncés il y a quelques jours.

Parmi eux, 46 ont accepté d’en dire publiquement un peu plus sur leur application, dans ces slides pleines de captures d’écrans bluffantes ! À voir absolument !