My Bluetooth Summer, not so BLE(h)

Hi there,

This last summer I developed Bluetooth Low Energy (BLE) interfaces for a couple of embedded boards and an Android app companion to operate the boards.

BLE Serial Console is currently in Beta and is available in Google Play.

Special thanks to Federico Biagioli who made the app’s Icon!

screenshot_20170202-170429
BLE Serial Console discovered all HM10 Services!

The app can discover all the GATT Services available in a BLE device. It was tested with an HM-10 module (in a breakout board) and Intel Edison’s HM11 integrated BLE module. BLE uses a protocol called Generic Attributes Profile (GATT), that exposes hierarchical data on any BLE device.

Once you enter the right GATT Characteristic, if it has Read/Write permissions you can exchange data with the module from the app to whatever device is connected to the BLE Module. Additionally, if the GATT Characteristic has the Notify permissions, you can subscribe to the device, and receive any updates made to that GATT Characteristic from the other side of the line. Subscribing will enable you to have bidirectional communication with the module.

HM10’s breakout board works with 3.3V with voltage and logic converters and exposes TX/RX pins that you can connect very easily to any Arduino based board having UART protocol. In my case I connected the RX/TX pins to the RS232 RX/TX pins in the CIAA board. HM10’s default GATT Characteristic contains a 20 bytes long registry with Read/Write/Notify permissions.

Service UUID: 0000ffe0-0000-1000-8000-00805f9b34fb
Characteristic UUID: 0000ffe1-0000-1000-8000-00805f9b34fb

0-eus-d2-72d06ae14d9237e9a9a5f176123d903b
EDU-CIAA-NXP & HM-10 BLE Module in Action

I wrote some node.js code for Intel Edison’s board. To enable BLE in this board you have to login and run 3 commands:

rfkill unblock bluetooth
killall bluetoothd
hciconfig hci0 up

After this, you can flash your javascript code to the board, connect & subscribe to the BLE device and operate seamlessly like any other Serial Communication app.

Last but not least, I wrote some plain twenty first century C code to interface with an embedded board called CIAA (Computadora Industrial Abierta Argentina). I connected an HM-10 BLE module to the board and configured the interface between a PC terminal, the board itself and the BLE module in Master Mode.

Advertisements

Bubblr updates for Android 7

Hello true believers!

I recently updated Bubblr’s Free and Full version, so you can enjoy using it with your Android Nougats!

Also, some of the updates include:

  • Auto dismiss buttons when clicking on them
  • Updated all the app-compat packages to 25.2.0
  • Bigger Icons 56 dp when not using FABs

Check them out!

Free Version:
https://play.google.com/store/apps/details?id=org.pampanet.mobile.bubblr.free

Full Version (only 2 bucks!):
https://play.google.com/store/apps/details?id=org.pampanet.mobile.bubblr.full

My Kotlin adventures: 5th Generation Language Awesomeness

Kotlin is a new programming language developed by the guys at JetBrains. Since it’s version 0.9 I’ve been testing the syntax and features and I must say that it’s amazing.

I developed a couple of Android apps which are now released in Google Play. Made 100% with Kotlin.

Bubblr is an application meant for the guy that wants a really fast shortcut to his everyday apps. it wants to be a very lightweight app launcher based on FABs (Floating Action Buttons). It is intended to be really simple to use and very lightweight (approximately 8 MB).The launcher adapts to the screen drawing an Arc of buttons that you can add, remove (swiping) and even sort by doing drag & drop with the buttons. Buttons are customizable, having the ability of being bubbles or icons within colored FABs (colors also customizable). The free edition has an Ad Banner at the bottom, safe and not intrusive. The Full edition doesn’t have Ads.

Augmented Fence (AFence) is an augmented reality fence, which uses Google Maps to display points stored in a sorted list, drawing a polygonal figure, and determining whether the user is inside or outside of the figure described by the polygon, and it allows you to activate alarms when the user is near the limits of the fenced area. The full edition doesn’t have any limitations.

To be able to develop these apps I used Android Studio with Kotlin’s plugin. The development was really faster y smooth than with other languages for Android, plus all the advantages that come from Functional Programming Languages, making your development experience more motivating and relaxing.

How many of you enjoy the term “tail recursion”? It’s like going into a traditional cafeteria and ask for a “mochaccino”, even though the tail recursion has been here since the days of Lisp and Haskell.

How about “pattern-matching” and “functional thread-safety”? These are some of the advantages of using a Functional Programming Language.

I think the world is going to make a leap of paradigm eventually, and staying in Java can be tough when that change happens. Java might be able to turn into COBOL… yuk!

It’s definitely the time to start giving 5th Generation Languages a chance, a try, and an APP.

Cheers!

Academic Android Certification

I finished Coursera’s Mobile Cloud Computing with Android Specialization. It’s been a really wonderful experience to get through all the courses and the final capstone.

The Specialization starts with a first approach to all the basic features in Android’s API and from there, the course gets you through all the advanced features -Location Services, Security mechanisms for Intents, Sensors…- with the use of some optimized algorithms curated by the professors to help us learn the best practices for the these vast platform.

It also covers concurrency and design patterns used in multiple areas, not just Android, like ThreadPools and Queues for managing multiple parallel threads and synchronization, the Half Sync-Half Async pattern -used also in BSD Unix-, or Dependency Injection pattern -widely used in web application development- using Spring Framework. With concurrency, there’s a part in one of the courses that covers Networking, using Netty framework -one of the best frameworks in my opinion- for starting a Java web server without using the standard Servlet specs.

Finally, it covers the BackEnd too, with exercises using Spring 4’s framework. This last one has topics like HTTPS, OAuth2, RESTful Web Services -using RetroFit library- and best practices for using WebViews, helping us understand the whole picture when building Cloud Services for Android Applications.

The Capstone project was truly challenging, covering design documentation for Mobile + Cloud projects and deployments using enterprise PaaS products like OpenShift. It kept the focus on today’s industries needs and trending topics for mobile and cloud applications.

Overall, a great Specialization to do, recommendable to everyone willing to start in the Mobile development world and earn a lot of knowledge, with flexible times, and in the timespan of a year.

Special thanks to the professors from Universities of Maryland and Vanderbilt for this great specialization.

My Guice Integration Adventures: Building a Server from scratch with Netty

Intro & Motivation

I came to this also by the Android MOOC offered by Coursera last year, and I found this framework really useful for building event-driven application servers.

In previous posts I talked about Node.js and it’s ease of use when developing web applications. Node.js is also event-driven and it counts with a lot of features and today it counts with very wide community. It has been a great experience to work with Node.js.

Netty Rulez Too

Netty Logo

Back in the Java world, Netty tries to achieve Rapid development of maintainable high performance protocol servers & clients, so I wanted to give it a try with my favorite DI framework. The server was drastically more lightweight and feature specific, but I didn’t have Servlet support. This is going to be a next step for sure if you want to fully migrate your webapp from your previous Java Application Server.

I made a very simple Java project with Guice and Netty, a Non-Blocking Event-Driven Server with Dependency Injection integrated.

Project and Code

The example application is in my github repo: guice-netty-bootstrap

My Guice Integration Adventures: Building Servlet 3.x RESTful Web Applications

Intro & Motivation

Following the line with my previous post about Jersey + Guice integration, I wanted to get deeper on the Servlet 3.x specs and the new Asynchronous features in Java.

This was one of the limitations I found in my previous approach. The lack of asynchronous request processing within my Web Application.

RESTful Java with JAX-RS 2.0 Book

My Investigation led me to RESTEasy Framework. I found this framework to be very handy and very updated with Java specs on JAX-RS, JSR-330, and Asynchronous Servlets.

I also bought the book RESTful Java with JAX-RS 2.0 (2nd Edition), which offered a very complete insight about this library and it’s capabilities. It’s also written by Bill Burke, who according to O’Reilly Media “is a Fellow at the JBoss division of Red Hat Inc. A long time JBoss contributor and architect, his current project is RESTEasy, RESTful Web Services for Java”. Big Kudos to Bill Burke for this great book and RESTEasy framework!

Third Approach: Apache  Shiro + RESTEasy + Servlet 3 + Guice

This integration was tricky because I had to ditch the so comfortable guice-servlet package. But RESTEasy provides a fancy way to integrate with Guice through their GuiceResteasyBootstrapServletContextListener. Also to complete the whole Servlet/Filter 3 implementation, I used the Filter30Dispatcher.

This third approach also has Apache Shiro integrated, which I explain in detail in other post, to build a fully Secured Web Application.

JBoss RESTEasy Logo

The ContextListener is the way of RESTEasy to inject Guice’s Injector into the Web Application Context. it has a methods to enumerate all the Modules (Guice AbstractModule’s implementations) needed for the WebApp and a method to operate with configurations just after the Injector is created.

Noteworthy about JAX-RS API

There are several ways to bootstrap your beans/POJOS in your Web Application. The way JAX-RS proposes to expose its Resource Classes is by its Application class. This class defines the Singleton classes and Prototype classes that will have the RESTful annotations for exposing Resources. It is a good practice to have all the RESTful Endpoints in a dedicated package like “.rest” or “.endpoint”, just like with the Jersey framework and their “packages” parameter, so in my case, migrating a Jersey Resource to a RESTEasy one was a very light task if not a massive file copy&paste among projects.

Code Template

The github project shiro-guice-async-webapp has the sample webapp. It has the following frameworks integrated:

Again, this project can be turned into a Maven Archetype, with the mvn command.

Next Adventure:

Integrate Google Guice with Netty!

My Guice Integration Adventures: Building Secure RESTful Web Application with Apache Shiro

Intro & Motivation

From my previous post, I created an Maven Archetype to bootstrap a Java Web Application. My next step was to make the Web App Secure somehow, and by recommendation I came into Apache Shiro.

RBAC and Security Management

Apache Shiro has a new way of thinking security, with its Resource Based Access Control  (RBAC, not to be mistaken with Role Based Access Control). Basically, instead of giving access to Roles, you give set access to Resources, in this case RESTful endpoints. This can be applied to all JAX-RS Resources.

Second Approach: Guice + Apache Shiro + Jersey

The way to integrate Shiro into a web application is via the web filters to attach the Security Context into the main context. But I also needed to configure Guice, so it can load the Security Manager and Shiro Realms as Singletons at bootstrap.

I also used Shiro’s AOP Module to support Annotations like @RequiresPermission, but in the long run I stuck with the default way for requesting Permissions.

My overall experience with Shiro was very successful, and I found the Permission approach very intuitive. It’s very customizable also, having the chance to modify the behavior of Sessions (or go totally Sesion-less), Permission levels and Realms to save Users, Roles and Permissions according to your existing data structure.

Finally this framework also counts with a Cryptography package, to manage your passwords in multiple formats (MD5, SHA1, SHA-256, et al.) and to encrypt any kind of data to be shared.

Code Template Project

My github example is in shiro-guice-jersey-bootstrap project. This integrates the following frameworks and libraries:

  • Servlet 2.5
  • Jersey 1.18.1
  • Guice 3.0
  • Apache Shiro 1.2.3
  • guice-persist 3.0
  • gson 2.2.4
  • joda-time 2.4
  • JUnit 4.10

I also made a Maven Archetype from this template in secure-rest-webapp-archetype project.

Conclusions

This kind of projects are very demanded nowadays because of the SaaS and MBaaS architectures, and like I said in previous post, having Jersey makes your RESTful tier compliant with JAX-RS, Guice and Dependency Injection compliant with JSR-330 and the so long standardized Servlet 2.5 spec compliant with any Java Enterprise Application Servers. This makes the app more portable in terms of code sharing/reviewing and more focused on the BackEnd business logic, allowing a more agile workflow for distributed teams.

Next Adventure

My next adventure will involve RESTEasy and Servlet 3.x spec! Stay tuned!

Cheers!