├── Android_Wifi
├── .gitignore
├── .idea
│ ├── gradle.xml
│ ├── inspectionProfiles
│ │ └── Project_Default.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ └── vcs.xml
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── tofaha
│ │ │ └── Android_wifi
│ │ │ └── ExampleInstrumentedTest.kt
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── tofaha
│ │ │ │ └── Android_wifi
│ │ │ │ ├── Pref.kt
│ │ │ │ ├── Util.kt
│ │ │ │ ├── app
│ │ │ │ ├── Constant.kt
│ │ │ │ ├── MyData.kt
│ │ │ │ └── TofahaApplication.kt
│ │ │ │ ├── connection
│ │ │ │ ├── CLoseConnection.kt
│ │ │ │ ├── OpenConnection.kt
│ │ │ │ └── SendMessages.kt
│ │ │ │ ├── dagger
│ │ │ │ ├── AppComponent.kt
│ │ │ │ ├── AppModule.kt
│ │ │ │ └── PreferenceModule.kt
│ │ │ │ └── ui
│ │ │ │ ├── AppSourceCode.kt
│ │ │ │ ├── FloatingMenuFragment.kt
│ │ │ │ ├── InfoActivity.kt
│ │ │ │ └── main
│ │ │ │ ├── MainActivity.kt
│ │ │ │ └── MainView.kt
│ │ └── res
│ │ │ ├── drawable-hdpi
│ │ │ ├── code_source_white.png
│ │ │ ├── ic_action_ip_logo.png
│ │ │ ├── port_white.png
│ │ │ ├── refresh_blue.png
│ │ │ ├── send_blue.png
│ │ │ └── share_white.png
│ │ │ ├── drawable-mdpi
│ │ │ ├── code_source_white.png
│ │ │ ├── ic_action_ip_logo.png
│ │ │ ├── port_white.png
│ │ │ ├── refresh_blue.png
│ │ │ ├── send_blue.png
│ │ │ └── share_white.png
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable-xhdpi
│ │ │ ├── code_source_white.png
│ │ │ ├── ic_action_ip_logo.png
│ │ │ ├── port_white.png
│ │ │ ├── refresh_blue.png
│ │ │ ├── send_blue.png
│ │ │ └── share_white.png
│ │ │ ├── drawable-xxhdpi
│ │ │ ├── code_source_white.png
│ │ │ ├── ic_action_ip_logo.png
│ │ │ ├── port_white.png
│ │ │ ├── refresh_blue.png
│ │ │ ├── send_blue.png
│ │ │ └── share_white.png
│ │ │ ├── drawable
│ │ │ ├── btn_accent_selector.xml
│ │ │ ├── btn_blue_menu_button_selector.xml
│ │ │ ├── btn_blue_menu_selector.xml
│ │ │ ├── btn_blue_selector.xml
│ │ │ ├── btn_transparent_selector.xml
│ │ │ ├── esp8266.jpg
│ │ │ ├── ic_filter.xml
│ │ │ └── ic_launcher_background.xml
│ │ │ ├── layout
│ │ │ ├── activity_app_source_code.xml
│ │ │ ├── activity_main.xml
│ │ │ ├── activity_main2.xml
│ │ │ ├── float_menu.xml
│ │ │ ├── ip_address_dialog.xml
│ │ │ └── port_number_dialog.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── tofaha
│ │ └── Android_wifi
│ │ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── Arduino_ESP8266
└── Arduino_ESP8266.ino
└── README.md
/Android_Wifi/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/Android_Wifi/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/Android_Wifi/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Android_Wifi/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Android_Wifi/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Android_Wifi/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Android_Wifi/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Android_Wifi/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Android_Wifi/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | apply plugin: 'me.tatarka.retrolambda'
8 | apply plugin: 'com.jakewharton.hugo'
9 |
10 |
11 | android {
12 | compileSdkVersion 26
13 | defaultConfig {
14 | applicationId "com.tofaha.Android_wifi"
15 | minSdkVersion 15
16 | targetSdkVersion 26
17 | versionCode 1
18 | versionName "1.0"
19 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
20 | }
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | }
28 |
29 | kapt {
30 | generateStubs = true
31 | }
32 |
33 |
34 | dependencies {
35 | implementation fileTree(dir: 'libs', include: ['*.jar'])
36 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
37 | implementation 'com.android.support:appcompat-v7:26.1.0'
38 | implementation 'com.android.support:cardview-v7:26.1.0'
39 | implementation 'com.android.support:design:26.1.0'
40 | implementation 'info.hoang8f:fbutton:1.0.5'
41 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
42 | testImplementation 'junit:junit:4.12'
43 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
44 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
45 | implementation 'com.jakewharton:butterknife:8.8.1'
46 | kapt 'com.jakewharton:butterknife-compiler:8.8.1'
47 |
48 | //fabulus filter
49 | implementation 'com.allattentionhere:fabulousfilter:0.0.4'
50 |
51 | // Anko
52 | implementation "org.jetbrains.anko:anko:0.10.3"
53 |
54 | // Butterknife
55 | implementation 'com.jakewharton:butterknife:8.8.1'
56 | kapt 'com.jakewharton:butterknife-compiler:8.8.1'
57 |
58 | //dagger
59 | kapt "com.google.dagger:dagger-compiler:2.9"
60 | implementation 'com.google.dagger:dagger:2.9'
61 | provided 'org.glassfish:javax.annotation:10.0-b28'
62 | }
63 |
--------------------------------------------------------------------------------
/Android_Wifi/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting input build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/androidTest/java/com/tofaha/Android_wifi/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi
2 |
3 | import android.support.test.InstrumentationRegistry
4 | import android.support.test.runner.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("com.tofaha.Android_wifi", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/Pref.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi
2 |
3 | import android.content.Context
4 | import android.content.SharedPreferences
5 |
6 | import com.tofaha.Android_wifi.app.Constant
7 |
8 |
9 | /**
10 | * Created by ayoub on 11/23/17.
11 | */
12 |
13 | class Pref(private val context: Context) {
14 | private val preferences: SharedPreferences
15 |
16 | var ipAddress: String?
17 | get() = this.preferences.getString(Constant.IP_ADDRESS, "non")
18 | set(ipAddress) = this.preferences.edit().putString(Constant.IP_ADDRESS, ipAddress).apply()
19 |
20 | var portNumber: Int
21 | get() = this.preferences.getInt(Constant.PORT_NUMBER, 0)
22 | set(portNumber) = this.preferences.edit().putInt(Constant.PORT_NUMBER, portNumber).apply()
23 |
24 | init {
25 | this.preferences = context.getSharedPreferences(context.packageName, 0)
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/Util.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi
2 |
3 | /**
4 | * Created by ayoub on 11/23/17.
5 | */
6 |
7 | object Util {
8 | private val ip4Regex = "^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}$"
9 |
10 | fun isValidIp(ip: String): Boolean {
11 | return ip.matches(ip4Regex.toRegex())
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/app/Constant.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.app
2 |
3 | /**
4 | * Created by ayoub on 11/23/17.
5 | */
6 |
7 | interface Constant {
8 | companion object {
9 |
10 | val IP_ADDRESS = "ip_address"
11 | val PORT_NUMBER = "port_number"
12 | val REPO_LINK = "https://github.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi"
13 |
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/app/MyData.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.app
2 |
3 | import com.tofaha.Android_wifi.ui.main.MainActivity
4 | import java.net.Socket
5 |
6 | /**
7 | * Created by ayoub on 11/26/17.
8 | */
9 |
10 | object MyData {
11 | lateinit var socket: Socket
12 | lateinit var mainActivity : MainActivity
13 | var THREAD_RUNNING = false
14 | }
15 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/app/TofahaApplication.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.app
2 |
3 | import android.app.Application
4 | import com.tofaha.Android_wifi.dagger.AppComponent
5 | import com.tofaha.Android_wifi.dagger.AppModule
6 | import com.tofaha.Android_wifi.dagger.DaggerAppComponent
7 |
8 | /**
9 | * Created by ayoub on 11/23/17.
10 | */
11 | class TofahaApplication : Application() {
12 |
13 | private var appComponent: AppComponent? = null
14 |
15 | override fun onCreate() {
16 | super.onCreate()
17 | appComponent = initDagger(this)
18 | }
19 |
20 | protected fun initDagger(application: TofahaApplication): AppComponent {
21 | return DaggerAppComponent.builder().appModule(AppModule(application)).build()
22 | }
23 |
24 | fun getAppComponent(): AppComponent? {
25 | return this.appComponent
26 | }
27 | }
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/connection/CLoseConnection.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.connection
2 |
3 | import android.os.AsyncTask
4 | import com.tofaha.Android_wifi.app.MyData
5 | import java.io.IOException
6 |
7 | /**
8 | * Created by ayoub on 11/26/17.
9 | */
10 |
11 | class CLoseConnection : AsyncTask(){
12 |
13 | override fun doInBackground(vararg params: Void?): Void? {
14 | try {
15 |
16 | MyData.socket?.close()
17 | System.out.println("connection closed")
18 |
19 | }catch (e: IOException) {
20 | e.printStackTrace()
21 | }
22 |
23 | return null
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/connection/OpenConnection.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.connection
2 |
3 | import android.os.AsyncTask
4 |
5 | import com.tofaha.Android_wifi.app.MyData
6 |
7 | import java.io.IOException
8 | import java.net.Socket
9 |
10 | /**
11 | * Created by ayoub on 11/26/17.
12 | */
13 |
14 | class OpenConnection(private val ipAddress: String, private val portNumber: Int) : AsyncTask() {
15 |
16 |
17 | override fun doInBackground(vararg voids: Void): Void? {
18 | try {
19 | MyData.socket = Socket(ipAddress, portNumber)
20 | System.out.println("connection opened")
21 |
22 | if (MyData.THREAD_RUNNING == false){
23 | MyData.mainActivity.receiveMessage()
24 | }
25 |
26 | } catch (e: IOException) {
27 | e.printStackTrace()
28 | }
29 |
30 | return null
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/connection/SendMessages.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.connection
2 |
3 | import android.os.AsyncTask
4 |
5 | import com.tofaha.Android_wifi.app.MyData
6 |
7 | import java.io.BufferedWriter
8 | import java.io.IOException
9 | import java.io.OutputStreamWriter
10 | import java.io.PrintWriter
11 | import java.net.Socket
12 |
13 | /**
14 | * Created by ayoub on 11/26/17.
15 | */
16 |
17 | class SendMessages(msg: String) : AsyncTask() {
18 |
19 | internal var msg = ""
20 |
21 | init {
22 | this.msg = msg
23 | }
24 |
25 | override fun doInBackground(vararg voids: Void): Void? {
26 | try {
27 |
28 | val out = PrintWriter(BufferedWriter(OutputStreamWriter(MyData.socket
29 | .getOutputStream())), true)
30 |
31 | out.println(msg)
32 | println("message send")
33 |
34 | } catch (e: IOException) {
35 | e.printStackTrace()
36 | }
37 |
38 | return null
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/dagger/AppComponent.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.dagger
2 |
3 | import com.tofaha.Android_wifi.ui.FloatingMenuFragment
4 | import com.tofaha.Android_wifi.ui.InfoActivity
5 | import com.tofaha.Android_wifi.ui.main.MainActivity
6 |
7 | import javax.inject.Singleton
8 |
9 | import dagger.Component
10 |
11 | @Singleton
12 | @Component(modules = arrayOf(AppModule::class , PreferenceModule :: class))
13 | interface AppComponent {
14 |
15 | fun inject(infoActivity: InfoActivity)
16 | fun inject(mainActivity: MainActivity)
17 | fun inject(target: FloatingMenuFragment)
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/dagger/AppModule.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.dagger
2 |
3 | import android.app.Application
4 | import android.content.Context
5 |
6 | import javax.inject.Singleton
7 |
8 | import dagger.Module
9 | import dagger.Provides
10 |
11 | @Module
12 | class AppModule(private val application: Application) {
13 |
14 | @Singleton
15 | @Provides
16 | fun provideContext(): Context {
17 | return this.application
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/dagger/PreferenceModule.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.dagger
2 |
3 | import android.content.Context
4 | import com.tofaha.Android_wifi.Pref
5 | import dagger.Module
6 | import dagger.Provides
7 | import javax.inject.Singleton
8 |
9 | /**
10 | * Created by ayoub on 11/23/17.
11 | */
12 | @Module
13 | class PreferenceModule {
14 |
15 | @Singleton
16 | @Provides
17 | internal fun providePref(context: Context): Pref {
18 | return Pref(context)
19 | }
20 |
21 | }
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/ui/AppSourceCode.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.ui
2 |
3 | import android.graphics.drawable.ColorDrawable
4 | import android.os.Build
5 | import android.support.annotation.RequiresApi
6 | import android.support.v7.app.AppCompatActivity
7 | import android.os.Bundle
8 |
9 | import com.tofaha.Android_wifi.R
10 | import kotlinx.android.synthetic.main.activity_app_source_code.*
11 | import android.content.Intent
12 | import android.net.Uri
13 | import com.tofaha.Android_wifi.app.Constant
14 |
15 |
16 | class AppSourceCode : AppCompatActivity() {
17 |
18 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
19 | override fun onCreate(savedInstanceState: Bundle?) {
20 | super.onCreate(savedInstanceState)
21 | setContentView(R.layout.activity_app_source_code)
22 |
23 | window.statusBarColor = resources.getColor(R.color.blue_menu_button)
24 | supportActionBar!!.setBackgroundDrawable(ColorDrawable(resources.getColor(R.color.blue_menu_button)))
25 |
26 | my_repo_link.setOnClickListener({
27 | val browser = Intent(Intent.ACTION_VIEW, Uri.parse(Constant.REPO_LINK))
28 | startActivity(browser)
29 | })
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/ui/FloatingMenuFragment.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.ui
2 |
3 | import android.app.AlertDialog
4 | import android.app.Dialog
5 | import android.content.Intent
6 | import android.view.View
7 | import android.widget.TextView
8 | import android.widget.Toast
9 |
10 | import com.allattentionhere.fabulousfilter.AAH_FabulousFragment
11 | import com.tofaha.Android_wifi.Pref
12 | import com.tofaha.Android_wifi.R
13 | import com.tofaha.Android_wifi.app.TofahaApplication
14 |
15 | import javax.inject.Inject
16 |
17 | import butterknife.BindView
18 | import butterknife.ButterKnife
19 | import butterknife.OnClick
20 | import com.tofaha.Android_wifi.Util
21 | import kotlinx.android.synthetic.main.ip_address_dialog.view.*
22 | import kotlinx.android.synthetic.main.port_number_dialog.view.*
23 |
24 | /**
25 | * Created by ayoub on 11/24/17.
26 | */
27 |
28 | class FloatingMenuFragment : AAH_FabulousFragment() {
29 |
30 | @BindView(R.id.content_menu)
31 | lateinit var contentMenu: View
32 |
33 | @BindView(R.id.close_menu)
34 | lateinit var closeMenu: View
35 |
36 | @BindView(R.id.menu_ip_address_text)
37 | lateinit var ipAddress: TextView
38 |
39 | @BindView(R.id.menu_port_number_text)
40 | lateinit var portNumber: TextView
41 |
42 | @Inject
43 | lateinit var pref: Pref
44 |
45 | override fun setupDialog(dialog: Dialog, style: Int) {
46 | val myView = View.inflate(context, R.layout.float_menu, null)
47 | (activity.application as TofahaApplication).getAppComponent()!!.inject(this)
48 | ButterKnife.bind(this, myView)
49 |
50 | updateInfo()
51 |
52 | setAnimationDuration(400) //optional; default 500ms
53 | setPeekHeight(400) // optional; default 400dp
54 | //setCallbacks((Callbacks) getActivity()); //optional; to get back result
55 | //setAnimationListener((AnimationListener) getActivity()); //optional; to get animation callbacks
56 | setViewgroupStatic(closeMenu) // optional; layout to stick at bottom on slide
57 | //setViewPager(vp_types); //optional; if you use viewpager that has scrollview
58 | setViewMain(contentMenu) //necessary; main bottomsheet view
59 | setMainContentView(myView) // necessary; call at end before super
60 | super.setupDialog(dialog, style) //call super at last
61 | }
62 |
63 | @OnClick(R.id.close_menu)
64 | fun close() {
65 | closeFilter(this)
66 | }
67 |
68 | @OnClick(R.id.menu_ip_address)
69 | fun ipAddress() {
70 | showIpDialog()
71 | }
72 |
73 | @OnClick(R.id.menu_port_number)
74 | fun portNumber() {
75 | showPortDialog()
76 | }
77 |
78 | @OnClick(R.id.menu_share)
79 | fun shareApp() {
80 | val sharingIntent = Intent(Intent.ACTION_SEND)
81 | sharingIntent.type = "text/plain"
82 | sharingIntent.putExtra(Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=com.tofaha.Android_wifi")
83 | startActivity(Intent.createChooser(sharingIntent, "Share with"))
84 | }
85 |
86 | @OnClick(R.id.menu_code_source)
87 | fun appCodeSource() {
88 | startActivity(Intent(context , AppSourceCode::class.java))
89 | }
90 |
91 | private fun showIpDialog() {
92 | val alertDialog = AlertDialog.Builder(context).create()
93 | val myView = layoutInflater.inflate(R.layout.ip_address_dialog, null)
94 | alertDialog.setView(myView)
95 | myView.ip_dialog.hint = pref.ipAddress
96 | myView.ip_dialog_change.setOnClickListener({
97 | if (Util.isValidIp(myView.ip_dialog.text.toString())){
98 | pref.ipAddress = myView.ip_dialog.text.toString()
99 | alertDialog.dismiss()
100 | updateInfo()
101 | }else
102 | Toast.makeText(context , "Enter Valid IP" , Toast.LENGTH_SHORT).show()
103 | })
104 | myView.ip_dialog_cancel.setOnClickListener({
105 | alertDialog.dismiss()
106 | })
107 | alertDialog.show()
108 | }
109 |
110 |
111 | private fun showPortDialog() {
112 | val alertDialog = AlertDialog.Builder(context).create()
113 | val myView = layoutInflater.inflate(R.layout.port_number_dialog, null)
114 | alertDialog.setView(myView)
115 | myView.port_dialog.hint = pref.portNumber.toString()
116 | myView.port_dialog_change.setOnClickListener({
117 | if (!myView.port_dialog.text.toString().equals("")){
118 | pref.portNumber = Integer.parseInt(myView.port_dialog.text.toString())
119 | alertDialog.dismiss()
120 | updateInfo()
121 | }else {
122 | Toast.makeText(context , "Enter port number" , Toast.LENGTH_SHORT).show()
123 | }
124 | })
125 | myView.port_dialog_cancel.setOnClickListener({
126 | alertDialog.dismiss()
127 | })
128 | alertDialog.show()
129 | }
130 |
131 | private fun updateInfo(){
132 | ipAddress.text = pref.ipAddress
133 | portNumber.text = pref.portNumber.toString()
134 | }
135 |
136 | companion object {
137 |
138 | fun newInstance(): FloatingMenuFragment {
139 | return FloatingMenuFragment()
140 | }
141 | }
142 |
143 |
144 | }
145 |
146 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/ui/InfoActivity.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.ui
2 |
3 | import android.content.Intent
4 | import android.graphics.drawable.ColorDrawable
5 | import android.os.Build
6 | import android.support.annotation.RequiresApi
7 | import android.support.v7.app.AppCompatActivity
8 | import android.os.Bundle
9 | import android.widget.EditText
10 | import android.widget.Toast
11 |
12 | import com.tofaha.Android_wifi.Pref
13 | import com.tofaha.Android_wifi.R
14 | import com.tofaha.Android_wifi.Util
15 | import com.tofaha.Android_wifi.app.TofahaApplication
16 |
17 | import javax.inject.Inject
18 |
19 | import butterknife.BindView
20 | import butterknife.ButterKnife
21 | import butterknife.OnClick
22 | import com.tofaha.Android_wifi.ui.main.MainActivity
23 |
24 | class InfoActivity : AppCompatActivity() {
25 |
26 | @BindView(R.id.ip_address)
27 | lateinit var ipAddress: EditText
28 |
29 | @BindView(R.id.port_number)
30 | lateinit var portNumber: EditText
31 |
32 | @Inject
33 | lateinit var pref: Pref
34 |
35 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
36 | override fun onCreate(savedInstanceState: Bundle?) {
37 | super.onCreate(savedInstanceState)
38 | setContentView(R.layout.activity_main2)
39 |
40 | (this.application as TofahaApplication).getAppComponent()!!.inject(this)
41 |
42 | ButterKnife.bind(this)
43 |
44 | supportActionBar!!.setBackgroundDrawable(ColorDrawable(resources.getColor(R.color.blue_menu)))
45 | window.statusBarColor = resources.getColor(R.color.blue_menu)
46 |
47 | if (Util.isValidIp(pref!!.ipAddress!!) && pref!!.portNumber != 0) {
48 | startMainActivity()
49 | }
50 | }
51 |
52 | @OnClick(R.id.login_next)
53 | fun next() {
54 |
55 | if (Util.isValidIp(ipAddress!!.text.toString())) {
56 | pref!!.ipAddress = ipAddress!!.text.toString()
57 | } else {
58 | Toast.makeText(this, "Enter valid IP address", Toast.LENGTH_SHORT).show()
59 | return
60 | }
61 |
62 | if (portNumber!!.text.toString() != "") {
63 | pref!!.portNumber = Integer.parseInt(portNumber!!.text.toString())
64 | } else {
65 | Toast.makeText(this, "Enter port number", Toast.LENGTH_SHORT).show()
66 | return
67 | }
68 |
69 | startMainActivity()
70 | }
71 |
72 | fun startMainActivity() {
73 | val intent = Intent(this@InfoActivity, MainActivity::class.java)
74 | intent.flags = (Intent.FLAG_ACTIVITY_CLEAR_TASK
75 | or Intent.FLAG_ACTIVITY_CLEAR_TOP
76 | or Intent.FLAG_ACTIVITY_NEW_TASK)
77 | startActivity(intent)
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/ui/main/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.ui.main
2 |
3 | import android.graphics.drawable.ColorDrawable
4 | import android.os.*
5 | import android.support.v7.app.AppCompatActivity
6 | import android.support.annotation.RequiresApi
7 | import android.widget.EditText
8 | import android.widget.TextView
9 | import butterknife.BindView
10 | import butterknife.ButterKnife
11 | import butterknife.OnClick
12 | import com.tofaha.Android_wifi.Pref
13 | import com.tofaha.Android_wifi.R
14 | import com.tofaha.Android_wifi.app.MyData
15 | import com.tofaha.Android_wifi.app.TofahaApplication
16 | import com.tofaha.Android_wifi.connection.CLoseConnection
17 | import com.tofaha.Android_wifi.connection.OpenConnection
18 | import com.tofaha.Android_wifi.connection.SendMessages
19 | import com.tofaha.Android_wifi.ui.FloatingMenuFragment
20 | import kotlinx.android.synthetic.main.activity_main.*
21 | import org.jetbrains.anko.doAsync
22 | import org.jetbrains.anko.uiThread
23 | import java.io.*
24 | import javax.inject.Inject
25 |
26 | class MainActivity : AppCompatActivity() , MainView {
27 |
28 |
29 | var input: BufferedReader? = null
30 |
31 | @Inject
32 | lateinit var pref: Pref
33 |
34 | @BindView(R.id.text_message)
35 | lateinit var msgText : EditText
36 |
37 | @BindView(R.id.server_response)
38 | lateinit var serverResponse : TextView
39 |
40 | @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
41 | override fun onCreate(savedInstanceState: Bundle?) {
42 | super.onCreate(savedInstanceState)
43 | setContentView(R.layout.activity_main)
44 |
45 | (this.application as TofahaApplication).getAppComponent()!!.inject(this)
46 |
47 | ButterKnife.bind(this)
48 |
49 | MyData.mainActivity = this
50 |
51 | supportActionBar!!.setBackgroundDrawable(ColorDrawable(resources.getColor(R.color.blue_menu)))
52 | window.statusBarColor = resources.getColor(R.color.blue_menu)
53 |
54 | this.fab.bringToFront()
55 | this.fab.parent.requestLayout()
56 |
57 | led1.setOnClickListener({
58 | var m : String
59 | if (led1.isChecked)
60 | m = "pin=11"
61 | else
62 | m = "pin=01"
63 | sendMessage(m)
64 | })
65 |
66 | led2.setOnClickListener({
67 | var m : String
68 | if (led2.isChecked)
69 | m = "pin=22"
70 | else
71 | m = "pin=02"
72 | sendMessage(m)
73 | })
74 |
75 | refresh_connection.setOnClickListener({
76 | openConnection()
77 | })
78 |
79 | }
80 |
81 |
82 | @OnClick(R.id.fab)
83 | operator fun next() {
84 | var dialogFrag = FloatingMenuFragment.newInstance()
85 | dialogFrag.setParentFab(fab)
86 | dialogFrag.show(getSupportFragmentManager(), dialogFrag.getTag())
87 | }
88 |
89 | @OnClick(R.id.send_message)
90 | fun sendButton(){
91 | sendMessage(msgText.text.toString())
92 | }
93 |
94 | override fun sendMessage(msg : String) {
95 | var sendMessages = SendMessages(msg)
96 | sendMessages!!.execute()
97 | }
98 |
99 | override fun openConnection() {
100 | var openConnection = OpenConnection(pref.ipAddress!!, pref.portNumber)
101 | openConnection!!.execute()
102 | }
103 |
104 | override fun receiveMessage() {
105 | doAsync {
106 |
107 | input = BufferedReader(InputStreamReader(MyData.socket.getInputStream()))
108 | var msgText = "waiting ...."
109 | MyData.THREAD_RUNNING = true
110 |
111 | while (true) {
112 |
113 | //println(input?.readLine())
114 | Thread.sleep(300)
115 | msgText = input?.readLine().toString()
116 |
117 | uiThread {
118 | serverResponse.text = msgText
119 | }
120 | }
121 | }
122 | }
123 |
124 | override fun closeConnection() {
125 | var closeConnection = CLoseConnection()
126 | closeConnection!!.execute()
127 | }
128 |
129 |
130 | override fun onResume() {
131 | super.onResume()
132 | openConnection()
133 | }
134 |
135 | override fun onPause() {
136 | super.onPause()
137 | closeConnection()
138 | }
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/java/com/tofaha/Android_wifi/ui/main/MainView.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi.ui.main
2 |
3 | /**
4 | * Created by ayoub on 11/30/17.
5 | */
6 | interface MainView {
7 | fun openConnection()
8 | fun closeConnection()
9 | fun sendMessage(msg : String)
10 | fun receiveMessage()
11 | }
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-hdpi/code_source_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-hdpi/code_source_white.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-hdpi/ic_action_ip_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-hdpi/ic_action_ip_logo.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-hdpi/port_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-hdpi/port_white.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-hdpi/refresh_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-hdpi/refresh_blue.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-hdpi/send_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-hdpi/send_blue.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-hdpi/share_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-hdpi/share_white.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-mdpi/code_source_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-mdpi/code_source_white.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-mdpi/ic_action_ip_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-mdpi/ic_action_ip_logo.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-mdpi/port_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-mdpi/port_white.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-mdpi/refresh_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-mdpi/refresh_blue.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-mdpi/send_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-mdpi/send_blue.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-mdpi/share_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-mdpi/share_white.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-xhdpi/code_source_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-xhdpi/code_source_white.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-xhdpi/ic_action_ip_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-xhdpi/ic_action_ip_logo.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-xhdpi/port_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-xhdpi/port_white.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-xhdpi/refresh_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-xhdpi/refresh_blue.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-xhdpi/send_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-xhdpi/send_blue.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-xhdpi/share_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-xhdpi/share_white.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-xxhdpi/code_source_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-xxhdpi/code_source_white.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-xxhdpi/ic_action_ip_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-xxhdpi/ic_action_ip_logo.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-xxhdpi/port_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-xxhdpi/port_white.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-xxhdpi/refresh_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-xxhdpi/refresh_blue.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-xxhdpi/send_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-xxhdpi/send_blue.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable-xxhdpi/share_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable-xxhdpi/share_white.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable/btn_accent_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable/btn_blue_menu_button_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable/btn_blue_menu_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable/btn_blue_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable/btn_transparent_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable/esp8266.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/drawable/esp8266.jpg
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable/ic_filter.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/layout/activity_app_source_code.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
19 |
20 |
30 |
31 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
19 |
20 |
30 |
31 |
38 |
39 |
48 |
49 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
69 |
70 |
76 |
77 |
85 |
86 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
110 |
111 |
116 |
117 |
125 |
126 |
132 |
133 |
142 |
143 |
152 |
153 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
176 |
177 |
178 |
181 |
182 |
187 |
188 |
197 |
198 |
204 |
205 |
213 |
214 |
215 |
216 |
217 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/layout/activity_main2.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
17 |
18 |
27 |
28 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
56 |
57 |
62 |
63 |
73 |
74 |
85 |
86 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/layout/float_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
20 |
24 |
25 |
34 |
35 |
39 |
40 |
50 |
51 |
62 |
63 |
64 |
65 |
74 |
75 |
79 |
80 |
90 |
91 |
102 |
103 |
104 |
105 |
114 |
115 |
119 |
120 |
130 |
131 |
132 |
133 |
143 |
144 |
148 |
149 |
159 |
160 |
161 |
162 |
163 |
164 |
171 |
172 |
180 |
181 |
182 |
183 |
184 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/layout/ip_address_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
19 |
20 |
31 |
32 |
37 |
38 |
47 |
48 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/layout/port_number_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
19 |
20 |
31 |
32 |
37 |
38 |
47 |
48 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #00ffffff
8 | #338dc6
9 | #326fc6
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Android Wifi
3 |
4 | the application code source and arduino program are both available in my github repository with a brief explanation about the communication between the two endpoint
5 |
6 | Navigate into the code source repository
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Android_Wifi/app/src/test/java/com/tofaha/Android_wifi/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.tofaha.Android_wifi
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Android_Wifi/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.1.51'
5 | repositories {
6 | google()
7 | mavenCentral()
8 | jcenter()
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.0.1'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13 | classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
14 | classpath 'me.tatarka:gradle-retrolambda:3.2.5'
15 |
16 | // NOTE: Do not place your application dependencies here; they belong
17 | // in the individual module build.gradle files
18 | }
19 | }
20 |
21 | allprojects {
22 | repositories {
23 | google()
24 | mavenCentral()
25 | jcenter()
26 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
27 | }
28 | }
29 |
30 | task clean(type: Delete) {
31 | delete rootProject.buildDir
32 | }
33 |
--------------------------------------------------------------------------------
/Android_Wifi/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified input this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run input incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/Android_Wifi/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayoubElhoucine/Connect-Android-to-Arduino-via-Wifi/e1817a94ca8068837fcdd2e266fdec908a933a79/Android_Wifi/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Android_Wifi/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Nov 22 20:51:03 CET 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/Android_Wifi/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" input
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable input your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found input your PATH.
82 |
83 | Please set the JAVA_HOME variable input your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears input the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir input $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg input "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i input
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/Android_Wifi/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found input your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable input your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable input your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/Android_Wifi/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/Arduino_ESP8266/Arduino_ESP8266.ino:
--------------------------------------------------------------------------------
1 | #include
2 | SoftwareSerial ESP8266(2,3);
3 |
4 | #define DEBUG true
5 |
6 | boolean FAIL_8266 = false;
7 | boolean headerSent = false;
8 | int connectionId = 0 ; // the connection id is O only if there is one client
9 |
10 | #define BUFFER_SIZE 128
11 | char buffer[BUFFER_SIZE];
12 |
13 | String ssid="\"SSID\""; // the network ssid
14 | String pass="\"ayoub1234\""; // the network password
15 |
16 | void setup() {
17 |
18 | Serial.begin(9600);
19 | ESP8266.begin(115200); // change this value to your wifi module (esp8266) baud rate
20 |
21 | do{
22 | ESP8266.println("AT");
23 | delay(1000);
24 | if(ESP8266.find((char*)"OK"))
25 | {
26 | Serial.println("Module is ready");
27 | delay(1000);
28 | clearESP8266SerialBuffer();
29 |
30 | //configure ESP as station
31 | sendESP8266Cmdln("AT+CWMODE=1",1000);
32 |
33 | //Join Wifi network
34 | sendESP8266Cmdln("AT+CWJAP="+ssid+","+pass,6500);
35 |
36 | //Get and display my IP
37 | sendESP8266Cmdln("AT+CIFSR", 1000);
38 |
39 | //Set multi connections
40 | sendESP8266Cmdln("AT+CIPMUX=1", 1000);
41 |
42 | //Setup web server on port 80
43 | sendESP8266Cmdln("AT+CIPSERVER=1,3333",1000);
44 |
45 | Serial.println("Server setup finish");
46 |
47 | FAIL_8266 = false;
48 |
49 | }
50 | else{
51 | Serial.println("Module have no response.");
52 | delay(500);
53 | FAIL_8266 = true;
54 | }
55 | }while(FAIL_8266);
56 |
57 | ESP8266.setTimeout(100);
58 |
59 | }
60 |
61 | void loop() {
62 |
63 | if(ESP8266.available()){
64 |
65 | String msg = ESP8266.readString();
66 | Serial.println("MSG: "+msg);
67 |
68 | // advance cursor to "pin=" and if you want this code to work you have to comment the two lines above
69 | if(ESP8266.find((char*)"pin=") || ESP8266.find((char*)"pio=") || ESP8266.find((char*)"phn=") || ESP8266.find((char*)"pin<")){
70 |
71 | int firstNumber = (ESP8266.read()-48); // get first number as integer
72 | int secondNumber = (ESP8266.read()-48); //get the second number as integer
73 |
74 | if (firstNumber == 1 || secondNumber == 1){
75 |
76 | Serial.println("MSG: the first led is ON");
77 |
78 | }else if(firstNumber == 2 || secondNumber == 2){
79 |
80 | Serial.println("MSG: the first led is ON");
81 |
82 | }else if(firstNumber == 0 && secondNumber == 1){
83 |
84 | Serial.println("MSG: the first led is ON");
85 |
86 | }else if(firstNumber == 0 && secondNumber == 2){
87 |
88 | Serial.println("MSG: the first led is ON");
89 |
90 | }
91 | }
92 |
93 | }
94 |
95 | if ( Serial.available() ){
96 | String s = Serial.readString();
97 | sendStringResponse(connectionId , s + "\r\n");
98 | }
99 | }
100 |
101 | void clearESP8266SerialBuffer()
102 | {
103 | Serial.println("= clearESP8266SerialBuffer() =");
104 | while (ESP8266.available() > 0) {
105 | char a = ESP8266.read();
106 | Serial.write(a);
107 | }
108 | Serial.println("==============================");
109 | }
110 |
111 |
112 |
113 | String sendData(String command, const int timeout, boolean debug)
114 | {
115 | String response = "";
116 |
117 | int dataSize = command.length();
118 | char data[dataSize];
119 | command.toCharArray(data,dataSize);
120 |
121 | ESP8266.write(data,dataSize); // send the read character to the ESP8266
122 |
123 | return response;
124 | }
125 |
126 | /*
127 | * Name: sendHTTPResponse
128 | * Description: Function that sends HTTP 200, HTML UTF-8 response
129 | */
130 | void sendHTTPResponse(int connectionId, String content)
131 | {
132 | // build HTTP response
133 | String httpResponse;
134 | String httpHeader;
135 | // HTTP Header
136 | httpHeader = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n";
137 | httpHeader += "Content-Length: ";
138 | httpHeader += content.length();
139 | httpHeader += "\r\n";
140 | httpHeader += "Connection: close\r\n";
141 | httpResponse = httpHeader + content + " r\n";
142 | sendCIPData(connectionId,httpResponse);
143 | }
144 |
145 | void sendStringResponse(int connectionId, String content)
146 | {
147 | sendCIPData(connectionId,content);
148 | }
149 |
150 | /*
151 | * Name: sendCIPDATA
152 | * Description: sends a CIPSEND=, command
153 | *
154 | */
155 | void sendCIPData(int connectionId, String data)
156 | {
157 | String cipSend = "AT+CIPSEND=";
158 | cipSend += 0;
159 | cipSend += ",";
160 | cipSend +=data.length();
161 | cipSend +="\r\n";
162 | sendCommand(cipSend,1000,DEBUG);
163 | sendData(data,100,DEBUG);
164 | }
165 |
166 | /*
167 | * Name: sendCommand
168 | * Description: Function used to send data to ESP8266.
169 | * Params: command - the data/command to send; timeout - the time to wait for a response; debug - print to Serial window?(true = yes, false = no)
170 | * Returns: The response from the ESP8266 (if there is a reponse)
171 | */
172 | String sendCommand(String command, const int timeout, boolean debug)
173 | {
174 | String response = "";
175 |
176 | ESP8266.print(command); // send the read character to the ESP8266
177 |
178 | long int time = millis();
179 |
180 | while( (time+timeout) > millis())
181 | {
182 | while(ESP8266.available())
183 | {
184 |
185 | // The esp has data so display its output to the serial window
186 | char c = ESP8266.read(); // read the next character.
187 | response+=c;
188 | }
189 | }
190 |
191 | if(debug)
192 | {
193 | Serial.print(response);
194 | }
195 |
196 | return response;
197 | }
198 |
199 | boolean waitOKfromESP8266(int timeout)
200 | {
201 | do{
202 | Serial.println("wait OK...");
203 | delay(1000);
204 | if(ESP8266.find((char*)"OK"))
205 | {
206 | return true;
207 | }
208 |
209 | }while((timeout--)>0);
210 | return false;
211 | }
212 |
213 |
214 | //Send command to ESP8266, assume OK, no error check
215 | //wait some time and display respond
216 | void sendESP8266Cmdln(String cmd, int waitTime)
217 | {
218 | ESP8266.println(cmd);
219 | delay(waitTime);
220 | clearESP8266SerialBuffer();
221 | }
222 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Android wifi is a demo aplication that shows you how to connect and send messages to Arduino via wifi communication , the demo android app is also provided in google play under the link https://play.google.com/store/apps/details?id=com.tofaha.Android_wifi .
2 | the communication system based on sever/client communication , in which android app act like client and the arduino program as server.
3 |
4 |
5 | # Android side (Kotlin) :
6 | in the android side the steps to communicate to arduino is very easy , the socket client is used for that , the socket client needs two parameters to find the tareget wifi module the first parameter is the wifi module IP address , and the seconde parameter is the port number , well the first thing you need to do is to open a socket connection , the server side (arduino with wifi module) has to be launched first and then the client (android device) will reach the server by the ip address and port number , you should be aware of where you instanciate the socket because it has to be instanciated in diffrent thread then the UI thread , if you do it in UI thread the app will crash , here sample how to open socket connection inside asyncTask:
7 |
8 | ## Open socket connection
9 |
10 | class OpenConnection(private val ipAddress: String, private val portNumber: Int) : AsyncTask() {
11 |
12 | override fun doInBackground(vararg voids: Void): Void? {
13 | try {
14 | MyData.socket = Socket(ipAddress, portNumber)
15 | System.out.println("connection opened")
16 |
17 | } catch (e: IOException) {
18 | e.printStackTrace()
19 | }
20 |
21 | return null
22 | }
23 | }
24 |
25 | ## Send messages
26 |
27 | and to send messages to server , you will need printWriter object to write in socket ibject that you already created and the socket will do the rest , here how you can do it :
28 |
29 | class SendMessages(msg: String) : AsyncTask() {
30 |
31 | internal var msg = ""
32 |
33 | init {
34 | this.msg = msg
35 | }
36 |
37 | override fun doInBackground(vararg voids: Void): Void? {
38 | try {
39 |
40 | val out = PrintWriter(BufferedWriter(OutputStreamWriter(MyData.socket
41 | .getOutputStream())), true)
42 |
43 | out.println(msg)
44 | println("message send")
45 |
46 | } catch (e: IOException) {
47 | e.printStackTrace()
48 | }
49 |
50 | return null
51 | }
52 | }
53 |
54 | ## Receive messages
55 |
56 | and to recieve messages from server , all you need to do is create an instance of bufferReader and pass the socket to it as parameter , and of course you need to do that inside loop with time out as optional , so whenever the server send message the socket object will receive it and bufferdReader will read the message from socket and you write it to the UI thread , here is the code (I used anko library in this code):
57 |
58 | doAsync {
59 |
60 | input = BufferedReader(InputStreamReader(MyData.socket.getInputStream()))
61 | var msgText = "waiting ...."
62 | MyData.THREAD_RUNNING = true
63 |
64 | while (true) {
65 |
66 | //println(input?.readLine())
67 | Thread.sleep(300)
68 | msgText = input?.readLine().toString()
69 |
70 | uiThread {
71 | serverResponse.text = msgText
72 | }
73 | }
74 | }
75 |
76 |
77 | to close the connection that what you do : socket.close() method :
78 |
79 | ## Close connection
80 |
81 | class CLoseConnection : AsyncTask(){
82 |
83 | override fun doInBackground(vararg params: Void?): Void? {
84 | try {
85 |
86 | MyData.socket?.close()
87 | System.out.println("connection closed")
88 |
89 | }catch (e: IOException) {
90 | e.printStackTrace()
91 | }
92 |
93 | return null
94 | }
95 |
96 | }
97 |
98 |
99 | # Server Side (Arduino with wifi module)
100 | in the server side I use arduino with wifi module(ESP8266) , well the first thing you need to consider is how to communicate arduino with the module , the communication will be done by the serial communication(Rx/Tx) , arduino board contains UART(Universal Asynchronious Receiver Transmmiter) , and the number of UART that arduino board contain is depend on the type of arduino like arduino uno has only one UART , so we are going to use the library of the serialSoftwar in arduino and by this library we can write and read to serial buffer (Rx/Tx) , after that we attach the Rx and Tx pin to Tx and Rx pin of the ESP8266 , this is how to communicate arduino with ESP8266 :
101 |
102 | ## Communicate arduino with esp module
103 |
104 | #include
105 | SoftwareSerial ESP8266(2,3); //(Rx/Tx) that means you have to attach pin 2 with esp Tx and pin 3 with esp Rx
106 |
107 | ## ESP configuration and setup with AT commands
108 |
109 | after the communication is established you now need to configure ESP as you need it to work , and that will be done by the ATcommand , in arduino IDE we will type the ATcommand and write it to the serialSoftware :
110 |
111 | void sendESP8266Cmdln(String cmd, int waitTime)
112 | {
113 | ESP8266.println(cmd);
114 | delay(waitTime);
115 | clearESP8266SerialBuffer();
116 | }
117 |
118 | void setup() {
119 |
120 | Serial.begin(9600);
121 | ESP8266.begin(115200); // change this value to your wifi module (esp8266) baud rate
122 |
123 | do{
124 | ESP8266.println("AT");
125 | delay(1000);
126 | if(ESP8266.find((char*)"OK"))
127 | {
128 | Serial.println("Module is ready");
129 | delay(1000);
130 | clearESP8266SerialBuffer();
131 |
132 | //configure ESP as station
133 | sendESP8266Cmdln("AT+CWMODE=1",1000);
134 |
135 | //Join Wifi network
136 | sendESP8266Cmdln("AT+CWJAP="+ssid+","+pass,6500);
137 |
138 | //Get and display my IP
139 | sendESP8266Cmdln("AT+CIFSR", 1000);
140 |
141 | //Set multi connections
142 | sendESP8266Cmdln("AT+CIPMUX=1", 1000);
143 |
144 | //Setup web server on port 80
145 | sendESP8266Cmdln("AT+CIPSERVER=1,3333",1000);
146 |
147 | Serial.println("Server setup finish");
148 |
149 | FAIL_8266 = false;
150 |
151 | }
152 | else{
153 | Serial.println("Module have no response.");
154 | delay(500);
155 | FAIL_8266 = true;
156 | }
157 | }while(FAIL_8266);
158 |
159 | ESP8266.setTimeout(100);
160 |
161 | }
162 |
163 | ## Receive messages from client
164 |
165 | after the configuration and setup of the ESP now you are ready to send and recieve data from client :
166 | to recieve data from client is very easy step , first you need to prepare the server and that will be done in the setup part , after that you write this code inside the loop method :
167 |
168 | void loop() {
169 |
170 | if(ESP8266.available()){
171 |
172 | String msg = ESP8266.readString();
173 | Serial.println("MSG: "+msg);
174 |
175 | }
176 | }
177 |
178 | ## Send messages to client
179 |
180 | to send data to client , well in this case to establish the client you need communication id , so if there are for exemple 5 client , so you need 5 communication id to send to each client , and in the case there is only one client you can use 0 as the value of the communication id :
181 |
182 |
183 | connectionId = 0 ;
184 | void sendStringResponse(int connectionId, String content)
185 | {
186 | sendCIPData(connectionId,content);
187 | }
188 |
189 | void loop() {
190 |
191 | if ( Serial.available() ){
192 | String s = Serial.readString();
193 | sendStringResponse(connectionId , s + "\r\n");
194 | }
195 | }
196 |
--------------------------------------------------------------------------------