Blog

Tutorial: Mobile App Local Deployment

Disclaimer: This tutorial is for simplified demonstration/educational purposes and not intended for production applications. We cannot be held responsible for any misuse, errors, or damages. Use at your own risk.

In this tutorial, we’ll discuss how to load a simple http2demo android application in developer mode. We will use an android phone, but analogous method exist for IOS devices. Internally, the demo performs network system calls that send an HTTP GET request to a server and prints the response on the demo’s screen. This is just a really simple example for pedagogical purposes, and we can build a much more complex product tailored to your needs. 

1. Turn on Developer Mode on your phone.  

    • To do this, go to Settings.
    • Click About Phone several times until the developer activation confirmation message pops up (if developer Options is not yet activated)
    • You should see a tab called Developer Options in Settings. Go into that tab and turn ON Developer Options.

2. Next, connect the phone to your computer via USB. Be careful to select a USB cable capable of charging AND data transfer; cheaper cables may support only charging. Select PTP on the phone (Picture Transfer Protocol).

3. Drag the mobile app APK file onto the phone. 

4. Find the application installer on the phone. You can do that by looking for Files->Installers. You’ll get some warning messages about a non-signed application when installing; but that’s alright for testing.

5. Next, run the application! In this case, the application name is http2demo.

6. Below, you’ll see some screens of this sample application, which is available as a free demo upon request here, with descriptions below. Of course, you can do this process automatically by building and deploying directly with Android Studio (but that requires getting your Gradle files in proper shape). Steps 1-2 are still necessary in this alternate option.

 

 

HTTP Demo Start Screen


Click on the screen to get hidden menu. Click on HTTP Get to connect to a sample server.


Received response from Server

Extra Learnings! – Gradle Files

Gradle files are used to build your Android code. Unfortunately, many demos online have non-working Gradle file configurations. For example, the “Compile” keyword is now deprecated and replaced with “implementation.” Below is a Gradle file we made. Important takeaways are to look at the SDK versions (targetSDKVersion, compileSDkVersion, and minSdkVersion). Android Studio will yell at you if your versions are not correct; however, there are many correct combinations. As a tip, try to keep compileSdkVersion and targetSdkVersion identical to avoid compile errors.

//Tested with Android 7.1.1
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.httpdemo2"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':httpcomm') //httpcomm is a module we developed
}

Tutorial: How to Use a Serial Interface To Blink an LED?

1. Overview

Disclaimer: This tutorial is for simplified demonstration/educational purposes and not intended for production applications. We cannot be held responsible for any misuse, errors, or damages. Use at your own risk.

One of the most common questions someone learning electronics may think about is how to get a computer to perform basic operations, such as controlling lights and other systems. A simplified version of this problem is learning how to get an LED blinking from your computer.

There are many ways to get the job done and common solutions typically require micro-controllers. However, is it possible to accomplish this without an understanding of micro-controllers and programming.

Let’s go into the basics of what a serial interface is. A serial interface is a way for the computer to communicate to other systems by sending and receiving a stream of 1’s and 0’s, which dictates what message is sent. For example, for a computer to send the letter ‘A’, it needs to send the ASCII representation (0x41), which is a way for letters to be translated into binary representations. In this case, 0x41 is a hexadecimal representation for ‘A’ and has an associated binary representation of 0b0100_0001. The least significant bit is sent first.

Order of bit transmission: [StartBit] [Least Significant Bit] …[Most Significant Bit] [Stop Bit(s)]

This could look like: [Start Bit] [01 00 00 01] [Stop Bit(s)]

A transmitted 1, a logical high, represents a negative voltage and a 0, a logical low, represents a positive voltage (due to the electrical/logical definition of Serial Interfaces).

2. Setting up Your computer

So, we need to get our computer hooked up. To do this, we need a USB to Serial Adapter.
a device that converts USB signals to a different form that will make it more convenient for us. I happened to use Office Depot’s Ativa, but any one you purchase should work (provided it is compliant to RS-232).

First, plug the USB to Serial to your laptop. We now need to figure out the name of our adapter. On Windows 10, we can open up Device manager to figure it out. Below, we see my device’s name is COM3, which we will need later. Yours may be different, so please check.

Next, we need to open PUTTY (or any terminal that can perform serial communication). Set the Serial Line to the device name and the speed to 75. Make sure to select the connection type of Serial. Note: if you do not select the correct (Baud Rate) speed of 75, the LED will blink very rapidly for your eyes and it will appear that it isn’t blinking, even though it is.

If you click open and you see the image below, you can proceed further. Otherwise, recheck your PUTTY settings above or go to the troubleshooting section at the end of the post.

3. Connect LED!

So now we need to get our hands dirty. Grab three wires and plug them into the adapter’s pins of 2,3, and 5. Pins 2 and 3 are the RECEIVE (Yellow below) and TRANSMIT (RED Wire below) of the computer’s serial interface, respectively. Pin 5 (Black below) is ground (GND). Next, hook up a resistor whose anode is connected to the Transmit Pin (3). Make sure to add a resistor in series with the LED, where the resistor is also connected to ground. Double check the connections to see if they are consistent. If you flip the LED, the blinking example will still work, but will invert. Also, if you short the Receive and Transmit pins of the serial interface, you will do a loop back test in which the computer will print out what it send. A good test indeed!

Here is a closer look at the serial interface.

Next fire up PUTTY based on the setup above and try typing on the keyboard. Every time you type, you should see a blink! And, you will see your character appear on your screen!

4. TroubleShooting Serial Driver Issue

If you couldn’t get the blinky demo working, it could be that the USB to Serial Adapter’s drivers aren’t set up properly. Here is a fix that worked for me. Open up Device Manager again. Go to your device, right click, and then click update driver.

Go for “Browse my computer” for driver software.

Click “Let me pick” below.

Select the appropriate driver and then click Next. If you have a CD, you can also click “Have Disk.” In my case, I just clicked Next.


Now give the demo another try and dig in to troubleshoot if other issues could be the culprit.

Please let us know your thoughts and how we can improve this! Thanks for reading!

We at Simplonics can deliver robust connectivity solutions tailored for your application.