Instructional Material: Deploying Code over WiFi

If you are using OnBot, you can skip this lesson as you already know how to do this. AS users, read on!

As you have no doubt learned, deploying code with a USB cable is time consuming and puts a lot of wear on the controller device USB connectors. When you are developing actual robot code, you will be doing this a lot. There is a better way.

You can deploy your code over a WiFi network instead of using a cable. This is much quicker and puts no wear on the controller device.

Here are the instructions on how to do it using a cell phone over WiFi Direct. Instructions for the Control Hub are below.

We will use the Android Debug Bridge (adb) app running on the phone and configure it to provide communication between the phone and your PC over WiFi. Normally, you would open the terminal window (bottom of the AS screen) and issue commands to ADB to get this running. We will create three AS External Tools to make the process easier.

Android Studio allows for the creation of External Tools, which will appear in the main window’s Tools / ExternalTools menu. These tools can do just about anything, and they can easily be used to run adb commands on the click of a button.

In Android Studio, open the main settings panel:

  • On Mac OS, click “Android Studio”, then “Preferences…” (or simply press the hotkey “⌘,”).
  • On Windows, click “File”, then “Settings…”.

In the settings panel:

  1. Expand the “Tools” item
  2. Click “External Tools” to open the External Tools list. The list is normally empty.
  3. For each of the following tools below, click the [+] button, and fill in the provided fields (leaving all others unchanged). Once each tool screen is filled-in, click “OK” to save. (Note: The “Program” field is the same, so the value can be cut and pasted to avoid re-typing.)
  4. Once all tools have been added, click the main settings panel’s “OK” button to save.

“Enable ADB over TCP/IP”

Field Value
Name: Enable ADB over TCP/IP
Program: $ModuleSdkPath$\platform-tools\adb.exe
Parameters: tcpip 5555

“Connect to ADB over WiFi Direct”

Field Value
Name: Connect to ADB over WiFi Direct
Program: $ModuleSdkPath$\platform-tools\adb.exe
Parameters: connect 192.168.49.1:5555

“Disconnect ADB”

Field Value
Name: Disconnect ADB
Program: $ModuleSdkPath$\platform-tools\adb.exe
Parameters: disconnect

With this done, you attach the phone to the PC with the USB cable. When the PC has recognized the phone, run the Enable ADB over TCP/IP external tool (Tools pull down menu->External Tools). When the command file has completed, disconnect the USB cable. You need to do this step with the USB cable each time you reboot the phone. Note: when running these external tool commands, you must have a Java source file in your project open and selected for editing (cursor in that file) when you execute the external tool.

On the controller app go to the settings menu and select Program & Manage. On the next screen you will see the name of the network created by the phone, something like DIRECT-xy-1234-RC. On your development PC, connect to that network name and use the network pass code displayed on the phone. Select to Automatically Connect so the PC will remember the pass code on future connections. The name of the WiFi Direct network should not change unless you change the name of the controller phone. Now run the Connect to ADB over WiFi Direct external tool in AS. This connects your PC to the phone over WiFi Direct. The connection will remain until you disconnect from the phone's network.

Now, when you compile in AS, the networked controller phone will be available as a deployment target. Compiled code will be sent to the phone over the network connection. 

Note: while connected to the phone's WiFi, your connection to the internet will not be available. You will need to switch networks when you need Internet access. If you do wish switch to another connection, run the Disconnect ADB tool before switching. When you switch back to the phone WiFi network, you will need to run the Connect to ADB over WiFi Direct tool again to reestablish the connection between AS and the phone. Also, a reminder that the first time you connect to the RC phone from any PC, you will be prompted on the phone to accept the PC's RSA Security Key before the first connection will be completed.

Note: If you do not disconnect adb before switching to away from the phone network, when you switch back to the phone network, and try to compile, in the window where you select the phone for deployment, it may be marked as [OFFLINE] and won't allow deployment. When this happens run the Disconnect ABD tool then run the Connect to ADB tool again and that should fix it.

Note: you can add the three external tools to the tool bar above the editing area. This left to you to figure out how, but to get started, right click on the tool bar.


Here are the instructions on how to do it using a Control Hub over WiFi.

We will use the Android Debug Bridge (adb) app which automatically runs on the hub to provide communication between the hub and your PC over WiFi. Normally, you would open the terminal window (bottom of the AS screen) and issue commands to ADB to get this running. We will create two AS External Tools to make the process easier.

Android Studio allows for the creation of External Tools, which will appear in the main window’s Tools / ExternalTools menu. These tools can do just about anything, and they can easily be used to run adb commands on the click of a button.

In Android Studio, open the main settings panel:

  • On Mac OS, click “Android Studio”, then “Preferences…” (or simply press the hotkey “⌘,”).
  • On Windows, click “File”, then “Settings…”.

In the settings panel:

  1. Expand the “Tools” item
  2. Click “External Tools” to open the External Tools list. The list is normally empty.
  3. For each of the following tools below, click the [+] button, and fill in the provided fields (leaving all others unchanged). Once each tool screen is filled-in, click “OK” to save. (Note: The “Program” field is the same, so the value can be cut and pasted to avoid re-typing.)
  4. Once all tools have been added, click the main settings panel’s “OK” button to save.

“Connect to ADB over WiFi”

Field Value
Name: Connect to ADB over WiFi 
Program: $ModuleSdkPath$\platform-tools\adb.exe
Parameters: connect 192.168.43.1:5555

“Disconnect ADB”

Field Value
Name: Disconnect ADB
Program: $ModuleSdkPath$\platform-tools\adb.exe
Parameters: disconnect

With this done, connect your PC to the Control Hub over WiFi. When the PC has connected to the hub, run the Connect to ADB over WiFi external tool (Tools pull down menu->External Tools). When the command file has completed you are ready to use AS. The connection will remain until you disconnect from the hub's network. Note: when running these external tool commands, you must have a java source file in your project open with the cursor in that file when you execute the external tool.

Now, when you compile in AS, the networked Control Hub will be available as a deployment target. Compiled code will be sent to the hub over the network connection. 

Note: while connected to the hub WiFi, your connection to the internet will not be available. You will need to switch networks when you need Internet access. If you do wish switch to another connection, run the Disconnect ADB tool before switching. When you switch back to the hub WiFi network, you will need to run the Connect to ADB over WiFi tool again to reestablish the connection between AS and the hub.

Note: If you do not disconnect adb before switching to away from the hub network, when you switch back to the hub network, and try to compile, in the window where you select the hub for deployment, it may be marked as [OFFLINE] and won't allow deployment. When this happens you will need to power the hub off and back on and reconnect.

Note: you can add the two external tools to the tool bar above the editing area. This left to you to figure out how, but to get started, right click on the tool bar.

 

Material Type: 
Lecture/Presentation
Education Level: 
Middle School
High School
Focus Subject: 
Computing / Computer Science
Robotics Software
HW Platform: 
Tetrix
SW Platform: 
Java
Interactivity Style: 
Mixed
Audience: 
Learner