From: rtrimana Date: Tue, 26 Sep 2017 19:45:58 +0000 (-0700) Subject: Adding database information insertion features in the phone app X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;ds=sidebyside;h=00922a5779ecade450c3cabc756f850dbe528095;p=iot2.git Adding database information insertion features in the phone app --- diff --git a/others/lede-gui/.gradle/3.3/taskArtifacts/fileHashes.bin b/others/lede-gui/.gradle/3.3/taskArtifacts/fileHashes.bin index 8a9ea4e..466d723 100644 Binary files a/others/lede-gui/.gradle/3.3/taskArtifacts/fileHashes.bin and b/others/lede-gui/.gradle/3.3/taskArtifacts/fileHashes.bin differ diff --git a/others/lede-gui/.gradle/3.3/taskArtifacts/fileSnapshots.bin b/others/lede-gui/.gradle/3.3/taskArtifacts/fileSnapshots.bin index 5832079..1d63b58 100644 Binary files a/others/lede-gui/.gradle/3.3/taskArtifacts/fileSnapshots.bin and b/others/lede-gui/.gradle/3.3/taskArtifacts/fileSnapshots.bin differ diff --git a/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.bin b/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.bin index 399927f..97f0849 100644 Binary files a/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.bin and b/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.bin differ diff --git a/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.lock b/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.lock index a153485..b6450aa 100644 Binary files a/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.lock and b/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.lock differ diff --git a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin index c182c8b..ecaaa6c 100644 Binary files a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin and b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin differ diff --git a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock index 627cc8a..f864e15 100644 Binary files a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock and b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock differ diff --git a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin index e08f809..fb93f2d 100644 Binary files a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin and b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin differ diff --git a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock index 067e9e4..bba075a 100644 Binary files a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock and b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock differ diff --git a/others/lede-gui/.idea/libraries/iotinstaller.xml b/others/lede-gui/.idea/libraries/iotinstaller.xml deleted file mode 100644 index 80ad498..0000000 --- a/others/lede-gui/.idea/libraries/iotinstaller.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/workspace.xml b/others/lede-gui/.idea/workspace.xml index 9323b6a..be99b55 100644 --- a/others/lede-gui/.idea/workspace.xml +++ b/others/lede-gui/.idea/workspace.xml @@ -6,6 +6,7 @@ + @@ -46,12 +47,16 @@ - + - - - + + + + + + + @@ -59,19 +64,26 @@ - - - + + + + + + - - + + - - - + + + + + + + @@ -79,8 +91,35 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -93,6 +132,8 @@ @@ -873,7 +914,7 @@ @@ -1135,32 +1176,48 @@ - @@ -1224,6 +1281,124 @@ + @@ -1259,12 +1435,20 @@ - - + + + + + + + + + + @@ -1851,23 +2035,25 @@ - - + + - + - - + + + - + - - + + + @@ -1881,10 +2067,11 @@ - - + + - - - - - - - + + + + + + + - - - - - - - + + + - + + + + + - + + + - - - + + - + - - - + + - + - - - + + - - - - - - - - - + + + + + + + + - - - + - - + + + - + + + + + + + + + - - - - - + + + + + - + - + - - + + - - - - - + - - + + + - - - - + + + + + + + + - - - + + + + + + + + - - - + + + + + + + + - - - - + - - + + + - - - + - - + + + - + - - + + + + + + - + - + + + + + - + - - + + + - - + + + + + + + + + + + + - + - - - - - - + + + + + + - + + + + + + + + + + + + - - + + + - + + + + + + + + + - - + + + - + + + + + + + + + + + - - + + @@ -2113,66 +2363,105 @@ + + + + + + + + + - + - - - + + + + + + + - - + + + + + + + + + + - + - - - + + + + + + + - - + + + + + + + + + + + - + - - + + + + + - + - - + + - + - - - + + + + + - + - - + + diff --git a/others/lede-gui/build.gradle b/others/lede-gui/build.gradle index f74784d..b9dd0d4 100644 --- a/others/lede-gui/build.gradle +++ b/others/lede-gui/build.gradle @@ -45,5 +45,6 @@ dependencies { compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.android.support:design:26.0.0-alpha1' + compile 'com.android.support:support-v4:26.+' testCompile 'junit:junit:4.12' } diff --git a/others/lede-gui/lede-gui.iml b/others/lede-gui/lede-gui.iml index b56780f..74baa3e 100644 --- a/others/lede-gui/lede-gui.iml +++ b/others/lede-gui/lede-gui.iml @@ -62,13 +62,6 @@ - - - - - - - @@ -76,9 +69,17 @@ + + + + + + + + @@ -90,6 +91,7 @@ + @@ -125,7 +127,6 @@ - diff --git a/others/lede-gui/libs/iotinstaller.jar b/others/lede-gui/libs/iotinstaller.jar deleted file mode 100644 index 1acf7be..0000000 Binary files a/others/lede-gui/libs/iotinstaller.jar and /dev/null differ diff --git a/others/lede-gui/src/main/AndroidManifest.xml b/others/lede-gui/src/main/AndroidManifest.xml index c8e7e6f..57ca44d 100644 --- a/others/lede-gui/src/main/AndroidManifest.xml +++ b/others/lede-gui/src/main/AndroidManifest.xml @@ -23,7 +23,16 @@ - + + + + \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/add_comm.config b/others/lede-gui/src/main/assets/add_comm.config new file mode 100644 index 0000000..0a8a2ac --- /dev/null +++ b/others/lede-gui/src/main/assets/add_comm.config @@ -0,0 +1,3 @@ +CM4 AmcrestCameraCM4 +LB4 LifxLightBulbLB4 +WRITE \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/add_device.config b/others/lede-gui/src/main/assets/add_device.config new file mode 100644 index 0000000..4ecf673 --- /dev/null +++ b/others/lede-gui/src/main/assets/add_device.config @@ -0,0 +1,15 @@ +IoTMain +ID CM4 +TYPE Camera +TYPESPECIFIC AmcrestCamera +END + +Table 2 +USERNAME VARCHAR 20 +PASSWORD VARCHAR 20 +END + +Data +admin +55779CatSoundz35 +END \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/add_device_address.config b/others/lede-gui/src/main/assets/add_device_address.config new file mode 100644 index 0000000..9867d01 --- /dev/null +++ b/others/lede-gui/src/main/assets/add_device_address.config @@ -0,0 +1,8 @@ +ID=CM4 +ADDRESSFOR=AmcrestCameraAdd +DEVICEADDRESS=ab:cd:ef:12:34:56 +PORTNUMBER=888 +PROTOCOL=udp +SOURCEWILDCARD=false +DESTWILDCARD=false +END \ No newline at end of file diff --git a/others/lede-gui/src/main/java/com/example/lede2/AddDeviceActivity.java b/others/lede-gui/src/main/java/com/example/lede2/AddDeviceActivity.java new file mode 100644 index 0000000..fc4a075 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/AddDeviceActivity.java @@ -0,0 +1,102 @@ +package com.example.lede2; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.*; + + +public class AddDeviceActivity extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener { + + Button doneButton; + TextView databaseInfo; + TextView databaseAddressInfo; + private SSH_MySQL ssh;//Connection object between Android & Host + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_add_device); + + doneButton = (Button) findViewById(R.id.doneButton); + databaseInfo = (EditText)findViewById(R.id.textInfo); + databaseAddressInfo = (EditText)findViewById(R.id.textInfoAddress); + + doneButton.setOnClickListener(this); + databaseInfo.setOnFocusChangeListener(this); + databaseAddressInfo.setOnFocusChangeListener(this); + ssh = new SSH_MySQL(); + // Set config text from file for device + try { + InputStream is = getAssets().open(MainActivity.DEF_ADD_DEVICE_FILE); + int size = is.available(); + byte[] buffer = new byte[size]; + is.read(buffer); + is.close(); + String text = new String(buffer); + databaseInfo.setGravity(Gravity.LEFT); + databaseInfo.setText(text); + Log.d("LOADINGFILE", "Add device info file is already loaded!"); + } catch (IOException ex) { + Log.d("LOADINGFILE", "Add device info file is NOT loaded!"); + ex.printStackTrace(); + } + // Set config text from file for device address + try { + InputStream is = getAssets().open(MainActivity.DEF_ADD_DEVICE_ADDRESS_FILE); + int size = is.available(); + byte[] buffer = new byte[size]; + is.read(buffer); + is.close(); + String text = new String(buffer); + databaseAddressInfo.setGravity(Gravity.LEFT); + databaseAddressInfo.setText(text); + Log.d("LOADINGFILE", "Add device address info file is already loaded!"); + } catch (IOException ex) { + Log.d("LOADINGFILE", "Add device address info file is NOT loaded!"); + ex.printStackTrace(); + } + + } + + @Override + public void onClick(View v) { + if(v == doneButton){ + // 1) Create a new file and insert the configuration + // 2) Run iotinstaller code for device installation + // 3) Remove the existing config file + // 4) Repeat 1, 2, and 3 for device address + ssh.execute("echo \"" + databaseInfo.getText().toString() + "\" >> " + + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + MainActivity.DEF_INSTALL_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + // repeat process for device address + "echo \"" + databaseAddressInfo.getText().toString() + "\" >> " + + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + MainActivity.DEF_INSTALL_ADDRESS_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE); + finish(); + } + } + + @Override + public void onFocusChange(View view, boolean hasFocus) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (hasFocus) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } else { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/AddRelationActivity.java b/others/lede-gui/src/main/java/com/example/lede2/AddRelationActivity.java new file mode 100644 index 0000000..da54025 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/AddRelationActivity.java @@ -0,0 +1,75 @@ +package com.example.lede2; + +import android.content.Context; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +import java.io.IOException; +import java.io.InputStream; + +public class AddRelationActivity extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener { + + Button doneButton; + TextView databaseInfo; + private SSH_MySQL ssh;//Connection object between Android & Host + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_add_relation); + + doneButton = (Button) findViewById(R.id.doneButton); + databaseInfo = (EditText)findViewById(R.id.textInfoComm); + + doneButton.setOnClickListener(this); + databaseInfo.setOnFocusChangeListener(this); + ssh = new SSH_MySQL(); + // Set config text from file for device + try { + InputStream is = getAssets().open(MainActivity.DEF_ADD_DEVICE_COMM_FILE); + int size = is.available(); + byte[] buffer = new byte[size]; + is.read(buffer); + is.close(); + String text = new String(buffer); + databaseInfo.setGravity(Gravity.LEFT); + databaseInfo.setText(text); + Log.d("LOADINGFILE", "Add comm info file is already loaded!"); + } catch (IOException ex) { + Log.d("LOADINGFILE", "Add comm info file is NOT loaded!"); + ex.printStackTrace(); + } + } + + @Override + public void onClick(View v) { + if(v == doneButton){ + // 1) Create a new file and insert the configuration + // 2) Run iotinstaller code for communication/relation installation + // 3) Remove the existing config file + ssh.execute("echo \"" + databaseInfo.getText().toString() + "\" >> " + + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + MainActivity.DEF_INSTALL_RELATION_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE); + finish(); + } + } + + @Override + public void onFocusChange(View view, boolean hasFocus) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (hasFocus) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } else { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } + +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/ConfigActivity.java b/others/lede-gui/src/main/java/com/example/lede2/ConfigActivity.java index de16fa9..5f20a69 100644 --- a/others/lede-gui/src/main/java/com/example/lede2/ConfigActivity.java +++ b/others/lede-gui/src/main/java/com/example/lede2/ConfigActivity.java @@ -22,14 +22,16 @@ public class ConfigActivity extends AppCompatActivity implements View.OnClickLis public static String RPWD = MainActivity.DEF_RPWD; public static String ROUTERIP = MainActivity.DEF_ROUTERIP; public static String ROUTERUSER = MainActivity.DEF_ROUTERUSER; - + public static String MYSQLHOSTUSER = MainActivity.DEF_MYSQLHOSTUSER; + public static String MYSQLHOSTIP = MainActivity.DEF_MYSQLHOSTIP; + public static String MYSQLHOSTPASSWORD = MainActivity.DEF_MYSQLHOSTPASSWORD; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_config); - ssid = (EditText) findViewById(R.id.ssid); + ssid = (EditText) findViewById(R.id.device_subtype); pwd = (EditText) findViewById(R.id.pwd); ip = (EditText) findViewById(R.id.ip); user = (EditText) findViewById(R.id.user); diff --git a/others/lede-gui/src/main/java/com/example/lede2/DeleteDeviceActivity.java b/others/lede-gui/src/main/java/com/example/lede2/DeleteDeviceActivity.java new file mode 100644 index 0000000..3036805 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/DeleteDeviceActivity.java @@ -0,0 +1,85 @@ +package com.example.lede2; + +import android.content.Context; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +public class DeleteDeviceActivity extends AppCompatActivity implements View.OnClickListener, View.OnFocusChangeListener { + + Button deleteButton; + Button doneButton; + EditText device_id; + EditText device_type; + EditText device_subtype; + EditText device_address_subtype; + TextView status; + private SSH_MySQL ssh;//Connection object between Android & Host + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_delete_device); + + deleteButton = (Button) findViewById(R.id.delete); + doneButton = (Button) findViewById(R.id.done); + device_id = (EditText)findViewById(R.id.device_id); + device_type = (EditText)findViewById(R.id.device_type); + device_subtype = (EditText)findViewById(R.id.device_subtype); + device_address_subtype = (EditText)findViewById(R.id.device_address_subtype); + status = (TextView)findViewById(R.id.textStatus); + + deleteButton.setOnClickListener(this); + doneButton.setOnClickListener(this); + device_id.setOnFocusChangeListener(this); + device_type.setOnFocusChangeListener(this); + device_subtype.setOnFocusChangeListener(this); + device_address_subtype.setOnFocusChangeListener(this); + ssh = new SSH_MySQL(); + } + + @Override + public void onClick(View v) { + if(v == deleteButton){ + // Remove the entry based on ID, type, and subtype + ssh.execute(MainActivity.DEF_DELETE_CMD + " " + + device_id.getText().toString() + " " + + device_type.getText().toString() + " " + + device_subtype.getText().toString() + ";" + + // Also remove the device address + MainActivity.DEF_DELETE_ADDRESS_CMD + " " + + device_id.getText().toString() + " " + + device_address_subtype.getText().toString() + ); + device_id.setText(""); + device_type.setText(""); + device_subtype.setText(""); + device_address_subtype.setText(""); + status.setText("Successfully deleted " + device_id.getText()); + /*try { + Thread.sleep(2000); + } catch (Exception ex) { + ex.printStackTrace(); + } + status.setText("");*/ + } + if(v == doneButton){ + finish(); + } + + } + + @Override + public void onFocusChange(View view, boolean hasFocus) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (hasFocus) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } else { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/EnrollDeviceActivity.java b/others/lede-gui/src/main/java/com/example/lede2/EnrollDeviceActivity.java index 926870a..be1d04a 100644 --- a/others/lede-gui/src/main/java/com/example/lede2/EnrollDeviceActivity.java +++ b/others/lede-gui/src/main/java/com/example/lede2/EnrollDeviceActivity.java @@ -100,19 +100,23 @@ public class EnrollDeviceActivity extends AppCompatActivity implements View.OnCl ssh = new SSH(); // execute shell script (script's function -> Save contents(Mac,Ip,Key,Name) on hostapd-psk) - ssh.execute("-co " + networkPass + " " + deviceName +" "+ ConfigActivity.RPWD);//review!!!!!! + ssh.execute("-co " + networkPass + " " + deviceName + " " + ConfigActivity.RPWD);//review!!!!!! try {//To execute asyntask in ssh object, we have to sleep main thread Thread.sleep(1000); } catch (Exception e) { Log.d("SLEEP EXCEPTION", "SLEEP EXCEPTION occurs in onClick method of EnrollDeviceActivity"); } finish();//Go back to the Main Activity - } else { //if name of wifi is not LEDE2 -> go to wifi configuration screen to change wifi type + } else { //if name of wifi is not LEDE -> go to wifi configuration screen to change wifi type Toast t = Toast.makeText(this, R.string.try_again, Toast.LENGTH_SHORT); t.show(); startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); } } + // Call activity that adds device - not doing this flow because we haven't found + // a way to change password without restarting WiFi + //startActivity(new Intent(this, AddDeviceActivity.class)); + //finish(); } else if (v == wifi) { startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); } diff --git a/others/lede-gui/src/main/java/com/example/lede2/ListActivity.java b/others/lede-gui/src/main/java/com/example/lede2/ListActivity.java index 60bc1f8..5de1fd2 100644 --- a/others/lede-gui/src/main/java/com/example/lede2/ListActivity.java +++ b/others/lede-gui/src/main/java/com/example/lede2/ListActivity.java @@ -1,24 +1,33 @@ package com.example.lede2; +import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.util.SparseBooleanArray; import android.view.View; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.EditText; import android.widget.ListView; +import android.widget.TextView; +import android.widget.Toast; import java.util.List; public class ListActivity extends AppCompatActivity implements View.OnClickListener { Button delete;//delete button in UI - Button selectAll;//select button in UI + Button deviceInfo;//select button in UI ListView listview;//listview in UI SSH ssh;//Connection object between Android & Router List tmp;//data structure which has IoT device information already registered on LEDE2 ArrayAdapter adapter;//adapter between tmp and listview + String device_info; + protected String deviceIp; + TextView ip; + TextView mac; @Override protected void onCreate(Bundle savedInstanceState) { @@ -33,14 +42,20 @@ public class ListActivity extends AppCompatActivity implements View.OnClickListe } delete = (Button) findViewById(R.id.delete); - selectAll = (Button) findViewById(R.id.selectAll); + deviceInfo = (Button) findViewById(R.id.deviceInfo); listview = (ListView) findViewById(R.id.listView1); + ip = (TextView) findViewById(R.id.txt_ip); + mac = (TextView) findViewById(R.id.txt_mac); adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, tmp);//register tmp array to adapter delete.setOnClickListener(this); - selectAll.setOnClickListener(this); + deviceInfo.setOnClickListener(this); listview.setAdapter(adapter); + listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { + public void onItemClick(AdapterView parent, View view, int position, long id) { + device_info = listview.getItemAtPosition(position).toString(); + }}); } @Override @@ -58,6 +73,7 @@ public class ListActivity extends AppCompatActivity implements View.OnClickListe command += rmName + " ";//complete command //remove this information on the listview tmp.remove(i); + //deviceIp = checkedItems. } } try { @@ -68,20 +84,24 @@ public class ListActivity extends AppCompatActivity implements View.OnClickListe } catch (Exception e) { Log.d("SLEEP EXCEPTION", "SLEEP EXCEPTION occurs in onClick method of ListActivity"); } - //update adapter.notifyDataSetChanged(); - //delete checked mark in listview listview.clearChoices(); - } else if (v == selectAll) { + } else if (v == deviceInfo) { + String[] devInfo = device_info.split("\\s+"); + ip.setText(devInfo[1]); + mac.setText(devInfo[2]); + Toast t = Toast.makeText(this, device_info, Toast.LENGTH_SHORT); + t.show(); + /*} else if (v == selectAll) { int count; count = adapter.getCount(); for (int i = 0; i < count; i++) { listview.setItemChecked(i, true); - } + }*/ } } } diff --git a/others/lede-gui/src/main/java/com/example/lede2/MainActivity.java b/others/lede-gui/src/main/java/com/example/lede2/MainActivity.java index d4ee5ea..7374bf1 100644 --- a/others/lede-gui/src/main/java/com/example/lede2/MainActivity.java +++ b/others/lede-gui/src/main/java/com/example/lede2/MainActivity.java @@ -13,22 +13,36 @@ import android.widget.Button; import android.widget.TextView; import android.widget.Toast; -import iotinstaller.IoTInstaller; - public class MainActivity extends AppCompatActivity implements View.OnClickListener { Button registerButton; Button listButton; + Button insertDBButton; + Button deleteDBButton; Button configButton; + Button relationButton; TextView ssid; protected static Context context; protected static String DEF_RSSID; protected static String DEF_RPWD; protected static String DEF_ROUTERIP; protected static String DEF_ROUTERUSER; + protected static String DEF_MYSQLHOSTUSER; + protected static String DEF_MYSQLHOSTIP; + protected static String DEF_MYSQLHOSTPASSWORD; protected static String DEF_CHANGE_DEFAULT_SCRIPT; protected static String DEF_CONNECT_DEVICE_SCRIPT; protected static String DEF_REGISTER_DEVICE_SCRIPT; + protected static String DEF_ADD_DEVICE_FILE; + protected static String DEF_ADD_DEVICE_ADDRESS_FILE; + protected static String DEF_ADD_DEVICE_COMM_FILE; + protected static String DEF_ADD_DEVICE_TO_MYSQL; + protected static String DEF_MYSQL_CONFIG_FILE; + protected static String DEF_INSTALL_CMD; + protected static String DEF_DELETE_CMD; + protected static String DEF_INSTALL_ADDRESS_CMD; + protected static String DEF_DELETE_ADDRESS_CMD; + protected static String DEF_INSTALL_RELATION_CMD; @Override protected void onCreate(Bundle savedInstanceState) { @@ -37,12 +51,18 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe registerButton = (Button) findViewById(R.id.register); listButton = (Button) findViewById(R.id.list); + insertDBButton = (Button) findViewById(R.id.insert_db); + deleteDBButton = (Button) findViewById(R.id.delete_db); configButton = (Button) findViewById(R.id.config); - ssid = (TextView)findViewById(R.id.ssid); + relationButton = (Button) findViewById(R.id.add_comm); + ssid = (TextView)findViewById(R.id.device_subtype); registerButton.setOnClickListener(this); listButton.setOnClickListener(this); + insertDBButton.setOnClickListener(this); + deleteDBButton.setOnClickListener(this); configButton.setOnClickListener(this); + relationButton.setOnClickListener(this); context = getApplicationContext(); DEF_RSSID = context.getResources().getString(R.string.default_rssid); @@ -52,6 +72,19 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe DEF_CHANGE_DEFAULT_SCRIPT = context.getResources().getString(R.string.change_default_script); DEF_CONNECT_DEVICE_SCRIPT = context.getResources().getString(R.string.connect_device_script); DEF_REGISTER_DEVICE_SCRIPT = context.getResources().getString(R.string.register_device_script); + DEF_ADD_DEVICE_FILE = context.getResources().getString(R.string.add_device_file); + DEF_ADD_DEVICE_ADDRESS_FILE = context.getResources().getString(R.string.add_device_address_file); + DEF_ADD_DEVICE_COMM_FILE = context.getResources().getString(R.string.add_device_comm_file); + DEF_MYSQLHOSTUSER = context.getResources().getString(R.string.mysql_hostuser); + DEF_MYSQLHOSTIP = context.getResources().getString(R.string.mysql_hostip); + DEF_MYSQLHOSTPASSWORD = context.getResources().getString(R.string.mysql_hostpassword); + DEF_ADD_DEVICE_TO_MYSQL = context.getResources().getString(R.string.add_device_to_mysql); + DEF_MYSQL_CONFIG_FILE = context.getResources().getString(R.string.mysql_config_file); + DEF_INSTALL_CMD = context.getResources().getString(R.string.install_cmd); + DEF_DELETE_CMD = context.getResources().getString(R.string.delete_cmd); + DEF_INSTALL_ADDRESS_CMD = context.getResources().getString(R.string.install_address_cmd); + DEF_DELETE_ADDRESS_CMD = context.getResources().getString(R.string.delete_address_cmd); + DEF_INSTALL_RELATION_CMD = context.getResources().getString(R.string.add_comm_cmd); ssid.setText(DEF_RSSID); } @@ -72,13 +105,21 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe if (v == registerButton) { Log.d("CLICKING", "Clicking on register!"); startActivity(new Intent(this, EnrollDeviceActivity.class)); + //startActivity(new Intent(this, AddDeviceActivity.class)); } else if (v == listButton) { + Log.d("CLICKING", "Clicking on list activity!"); startActivity(new Intent(this, ListActivity.class)); + } else if (v == insertDBButton) { + Log.d("CLICKING", "Clicking on add device!"); + startActivity(new Intent(this, AddDeviceActivity.class)); + } else if (v == deleteDBButton) { + Log.d("CLICKING", "Clicking on delete device!"); + startActivity(new Intent(this, DeleteDeviceActivity.class)); + } else if (v == relationButton) { + Log.d("CLICKING", "Clicking on add communication!"); + startActivity(new Intent(this, AddRelationActivity.class)); } } - //IoTInstaller ioTInstaller = new IoTInstaller(); - //ioTInstaller.helpMessages(); - } boolean isNetworkAvailable() {//check whether wifi connection is or not diff --git a/others/lede-gui/src/main/java/com/example/lede2/MySQLInterface.config b/others/lede-gui/src/main/java/com/example/lede2/MySQLInterface.config deleted file mode 100644 index b809e59..0000000 --- a/others/lede-gui/src/main/java/com/example/lede2/MySQLInterface.config +++ /dev/null @@ -1,7 +0,0 @@ -# MySQLInterface configuration - -#HOST=128.195.204.105 -HOST=localhost -DATABASE=IoTMain -USERNAME=root -PASSWORD=1234 \ No newline at end of file diff --git a/others/lede-gui/src/main/java/com/example/lede2/SSH.java b/others/lede-gui/src/main/java/com/example/lede2/SSH.java index 203ba79..9438053 100644 --- a/others/lede-gui/src/main/java/com/example/lede2/SSH.java +++ b/others/lede-gui/src/main/java/com/example/lede2/SSH.java @@ -34,13 +34,13 @@ import java.util.List; public class SSH extends AsyncTask> { // variables used for connection - Session session; - Channel channel; - ChannelExec ce; + private Session session; + private Channel channel; + private ChannelExec ce; // in this project, we supposed we use fixed host, username, password - String host; - String username; - String password; + private String host; + private String username; + private String password; // host, username, password initialize @Override @@ -57,8 +57,7 @@ public class SSH extends AsyncTask> { https://stackoverflow.com/questions/25789245/how-to-get-jsch-shell-command-output-in-string */ - - // open the conenction using username, password, and hostname + // open the connection using username, password, and hostname public boolean open() throws JSchException { JSch jSch = new JSch(); @@ -148,9 +147,9 @@ public class SSH extends AsyncTask> { cmd = MainActivity.DEF_CHANGE_DEFAULT_SCRIPT + " " + params[0]; } else if(params[0].substring(0,3).equals("-co")) { // ./connect_device.sh -co cmd = MainActivity.DEF_CONNECT_DEVICE_SCRIPT + " " + params[0]; - } else if(params[0].substring(0,3).equals("-dn")) { // ./register_device.sh -dn + } else if(params[0].substring(0,3).equals("-dn")) { // ./register_device.sh -dn cmd = MainActivity.DEF_REGISTER_DEVICE_SCRIPT + " " + params[0]; - } else if(params[0].substring(0,3).equals("-ln")) { // ./register_device.sh -ln + } else if(params[0].substring(0,3).equals("-ln")) { // ./register_device.sh -ln // below block is a little different from others cause it needs to get output from the router try { // try open the connection diff --git a/others/lede-gui/src/main/java/com/example/lede2/SSH_MySQL.java b/others/lede-gui/src/main/java/com/example/lede2/SSH_MySQL.java new file mode 100644 index 0000000..7702fcb --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/SSH_MySQL.java @@ -0,0 +1,174 @@ +package com.example.lede2; + +/** + * Created by rtrimana on 9/25/17. + */ + +import android.os.AsyncTask; +import android.util.Log; + +import com.jcraft.jsch.Channel; +import com.jcraft.jsch.ChannelExec; +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.Session; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import android.content.Context; +import android.util.Log; +import android.os.AsyncTask; + +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.Session; +import com.jcraft.jsch.ChannelExec; +import com.jcraft.jsch.Channel; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.String; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +// AsyncTask input : command line +// AysncTask output : output from a command +public class SSH_MySQL extends AsyncTask> { + + // variables used for connection + private Session session; + private Channel channel; + private ChannelExec ce; + // in this project, we supposed we use fixed host, username, password + private String host; + private String username; + private String password; + + // host, username, password initialize + @Override + protected void onPreExecute() { + super.onPreExecute(); + + host = ConfigActivity.MYSQLHOSTIP; + username = ConfigActivity.MYSQLHOSTUSER; + password = ConfigActivity.MYSQLHOSTPASSWORD; + } + + /* + The functions below are mainly from : + https://stackoverflow.com/questions/25789245/how-to-get-jsch-shell-command-output-in-string + */ + + // open the connection using username, password, and hostname + public boolean open() throws JSchException { + + JSch jSch = new JSch(); + + session = jSch.getSession(username, host, 22); + java.util.Properties config = new java.util.Properties(); + config.put("StrictHostKeyChecking", "no"); // not recommended + session.setPassword(password); + session.setConfig(config); + + + Log.d("SSH CONNECT OPEN", "Connecting SSH to " + host + " - Please wait for few seconds... "); + session.connect(); + if (session.isConnected()) { + Log.d("SSH CONNECT", "router connected!"); + return true; + } else { + Log.d("SSH NOT CONNECT", "router NOT connected!"); + return false; + } + } + + // send a command + public void runCommand(String command) throws JSchException, IOException { + + if (!session.isConnected()) + throw new RuntimeException("Not connected to an open session. Call open() first!"); + + channel = session.openChannel("exec"); + ce = (ChannelExec) channel; + ce.setCommand(command); + ce.connect(); + Log.d("SSH RUN COMMAND", command); + } + + // get output from a command + private List getChannelOutput(Channel channel) throws IOException { + + byte[] buffer = new byte[1024]; + List output_lines = new ArrayList(); + try { + InputStream in = channel.getInputStream(); + String line = new String(); + while (true) { + while (in.available() > 0) { + int i = in.read(buffer, 0, 1024); + if (i < 0) { + break; + } + line = new String(buffer, 0, i); + // add the read line to the return value list. + output_lines = new ArrayList(Arrays.asList(line.split("\\n"))); + } + + if(line.contains("logout")) { + break; + } + if (channel.isClosed()) { + break; + } + try { + Thread.sleep(1000); + } catch (Exception ee){} + } + } catch(Exception e) { + Log.d("SSH READOUTPUT ERROR", "Error while reading channel output: "+ e); + } + + return output_lines; + } + + + /* + usage : execute commands through SSH for database MySQL + */ + @Override + protected List doInBackground(String... params) { + + String cmd; + // Get into the path and create the config file + cmd = "cd " + MainActivity.DEF_ADD_DEVICE_TO_MYSQL + ";"; + cmd = cmd + params[0]; + + // now the command is set, so send it. + try { + // try open the connection + if (!open()) { + Log.d("SSH CONNECTION CLOSE", "open failed."); + return null; + } + runCommand(cmd); + ce.setCommand(cmd); + ce.connect(); + } catch (Exception e) { + } // done + + channel.disconnect(); + return null; + } + + /* + @Override + protected onPostExecute(Void param) { + Log.d("POST", "in post execute"); + } + */ +} diff --git a/others/lede-gui/src/main/res/layout/activity_add_device.xml b/others/lede-gui/src/main/res/layout/activity_add_device.xml new file mode 100644 index 0000000..836322a --- /dev/null +++ b/others/lede-gui/src/main/res/layout/activity_add_device.xml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + +