├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── drawable-hdpi
│ │ │ │ └── ic_stat_espressif.png
│ │ │ ├── drawable-mdpi
│ │ │ │ └── ic_stat_espressif.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── ic_stat_espressif.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_stat_espressif.png
│ │ │ ├── drawable-xxxhdpi
│ │ │ │ └── ic_stat_espressif.png
│ │ │ ├── values
│ │ │ │ ├── ic_launcher_background.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── menu
│ │ │ │ └── main_menu.xml
│ │ │ ├── xml
│ │ │ │ └── preferences.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── za
│ │ │ │ └── co
│ │ │ │ └── mitchwongho
│ │ │ │ └── example
│ │ │ │ └── esp32
│ │ │ │ └── alerts
│ │ │ │ ├── app
│ │ │ │ ├── MainApplication.kt
│ │ │ │ ├── OnBootReceiver.kt
│ │ │ │ ├── SettingsActivity.kt
│ │ │ │ ├── NotificationListener.kt
│ │ │ │ └── ForegroundService.kt
│ │ │ │ ├── ble
│ │ │ │ ├── LeManagerCallbacks.kt
│ │ │ │ └── LEManager.kt
│ │ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── za
│ │ │ └── co
│ │ │ └── mitchwongho
│ │ │ └── example
│ │ │ └── esp32
│ │ │ └── alerts
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── za
│ │ └── co
│ │ └── mitchwongho
│ │ └── example
│ │ └── esp32
│ │ └── alerts
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── caches
│ └── build_file_checksums.ser
├── encodings.xml
├── vcs.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── compiler.xml
├── modules.xml
├── runConfigurations.xml
├── codeStyles
│ └── Project.xml
├── misc.xml
└── assetWizardSettings.xml
├── README.md
├── gradle.properties
├── .gitignore
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | include ':ble'
3 | project(':ble').projectDir = file('../Android-BLE-Library/ble')
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_stat_espressif.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/drawable-hdpi/ic_stat_espressif.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_stat_espressif.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/drawable-mdpi/ic_stat_espressif.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_stat_espressif.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/drawable-xhdpi/ic_stat_espressif.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_stat_espressif.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/drawable-xxhdpi/ic_stat_espressif.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_stat_espressif.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/drawable-xxxhdpi/ic_stat_espressif.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchwongho/ESP-Alerts-for-Android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
175 | * This method is called from the main thread when the services has been discovered and 176 | * the device is supported (has required service). 177 | *
178 | * Remember to call {@link Request#enqueue()} for each request. 179 | *
180 | * A sample initialization should look like this: 181 | *
182 | * @Override
183 | * protected void initialize() {
184 | * requestMtu(MTU)
185 | * .with((device, mtu) -> {
186 | * ...
187 | * })
188 | * .enqueue();
189 | * setNotificationCallback(characteristic)
190 | * .with((device, data) -> {
191 | * ...
192 | * });
193 | * enableNotifications(characteristic)
194 | * .done(device -> {
195 | * ...
196 | * })
197 | * .fail((device, status) -> {
198 | * ...
199 | * })
200 | * .enqueue();
201 | * }
202 | *
203 | */
204 | override fun initialize() {
205 | Timber.i("Initialising...")
206 |
207 | enableNotifications(espDisplayTimeCharacteristic)
208 | .done(SuccessCallback {
209 | Timber.i("Successfully enabled DisplayMessageCharacteristic notifications")
210 | })
211 | .fail { device, status ->
212 | Timber.w("Failed to enable DisplayMessageCharacteristic notifications")
213 | }.enqueue()
214 | enableIndications(espDisplayMessageCharacteristic)
215 | .done(SuccessCallback {
216 | Timber.i("Successfully wrote message")
217 | })
218 | .fail(FailCallback { device, status ->
219 | Timber.w("Failed to write message to ${device.address} - status: ${status}")
220 | })
221 | .enqueue()
222 |
223 | // requestMtu(MTU).enqueue()
224 | setNotificationCallback(espDisplayTimeCharacteristic)
225 | .with(DataReceivedCallback { device, data ->
226 | Timber.i("Data received from ${device.address}")
227 | })
228 | enableNotifications(espDisplayTimeCharacteristic)
229 | .done(SuccessCallback {
230 | Timber.i("Successfully enabled DisplayTimeCharacteristic notifications")
231 | })
232 | .fail { device, status ->
233 | Timber.w("Failed to enable DisplayTimeCharacteristic notifications")
234 | }.enqueue()
235 | enableIndications(espDisplayTimeCharacteristic)
236 | .done(SuccessCallback {
237 | Timber.i("Successfully wrote Time & Battery status")
238 | })
239 | .fail(FailCallback { device, status ->
240 | Timber.w("Failed to write Time & Battery status to ${device.address} - status: ${status}")
241 | }).enqueue()
242 |
243 | val batteryLevelPercent = Companion.readBatteryLevel(context)
244 | writeTimeAndBatteryLevel(batteryLevelPercent, ForegroundService.formatter.format(Date()))
245 | }
246 |
247 | /**
248 | * This method should nullify all services and characteristics of the device.
249 | * It's called when the device is no longer connected, either due to user action
250 | * or a link loss.
251 | */
252 | override fun onDeviceDisconnected() {
253 | espDisplayMessageCharacteristic = null
254 | espDisplayTimeCharacteristic = null
255 | espDisplayOrientationCharacteristic = null
256 | }
257 | }
258 | }
--------------------------------------------------------------------------------
/app/src/main/java/za/co/mitchwongho/example/esp32/alerts/app/ForegroundService.kt:
--------------------------------------------------------------------------------
1 | package za.co.mitchwongho.example.esp32.alerts.app
2 |
3 | import android.annotation.TargetApi
4 | import android.app.*
5 | import android.bluetooth.BluetoothAdapter
6 | import android.bluetooth.BluetoothDevice
7 | import android.bluetooth.BluetoothManager
8 | import android.content.BroadcastReceiver
9 | import android.content.Context
10 | import android.content.Intent
11 | import android.content.IntentFilter
12 | import android.net.Uri
13 | import android.os.Build
14 | import android.os.IBinder
15 | import android.preference.PreferenceManager
16 | import android.support.v4.app.NotificationCompat
17 | import android.support.v4.content.LocalBroadcastManager
18 | import no.nordicsemi.android.ble.BleManager
19 | import timber.log.Timber
20 | import za.co.mitchwongho.example.esp32.alerts.BuildConfig
21 | import za.co.mitchwongho.example.esp32.alerts.MainActivity
22 | import za.co.mitchwongho.example.esp32.alerts.R
23 | import za.co.mitchwongho.example.esp32.alerts.ble.LEManager
24 | import za.co.mitchwongho.example.esp32.alerts.ble.LeManagerCallbacks
25 | import java.text.DateFormat
26 | import java.text.SimpleDateFormat
27 | import java.util.*
28 |
29 | /**
30 | *
31 | */
32 | class ForegroundService : Service() {
33 |
34 | companion object {
35 | val NOTIFICATION_DISPLAY_TIMEOUT = 2 * 60 * 1000 //2 minutes
36 | val SERVICE_ID = 9001
37 | val NOTIFICATION_CHANNEL = BuildConfig.APPLICATION_ID
38 | val VESPA_DEVICE_ADDRESS = "00:00:00:00:00:00"//""24:0A:C4:13:58:EA" // <--- YOUR ESP32 MAC address here
39 | val formatter = SimpleDateFormat.getTimeInstance(DateFormat.SHORT)
40 | }
41 |
42 | private var startId = 0;
43 | lateinit var bleManager: BleManager