Add publishMeasurementAutoServer()
This commit is contained in:
5
.idea/gradle.xml
generated
5
.idea/gradle.xml
generated
@@ -4,16 +4,15 @@
|
|||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<option name="testRunner" value="GRADLE" />
|
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleJvm" value="jbr-17" />
|
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
<option value="$PROJECT_DIR$/app" />
|
<option value="$PROJECT_DIR$/app" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
|
<option name="resolveExternalAnnotations" value="false" />
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@@ -1,3 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||||
|
|||||||
2
.idea/vcs.xml
generated
2
.idea/vcs.xml
generated
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -9,7 +9,7 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.logitech.vc.kirbytest"
|
applicationId "com.logitech.vc.kirbytest"
|
||||||
minSdk 29
|
minSdk 27
|
||||||
targetSdk 32
|
targetSdk 32
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.SensorTestingApp"
|
android:theme="@style/Theme.SensorTestingApp"
|
||||||
|
android:usesCleartextTraffic="true"
|
||||||
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ class DeviceListAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val inflater = popup.menuInflater
|
val inflater = popup.menuInflater
|
||||||
popup.setForceShowIcon(true)
|
// popup.setForceShowIcon(true)
|
||||||
inflater.inflate(R.menu.device_menu, popup.menu)
|
inflater.inflate(R.menu.device_menu, popup.menu)
|
||||||
popup.show()
|
popup.show()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,7 +150,8 @@ class KirbyDevice(
|
|||||||
payload = Payload(measurement.toString())
|
payload = Payload(measurement.toString())
|
||||||
Log.i("BleListener", "Char received: $payload")
|
Log.i("BleListener", "Char received: $payload")
|
||||||
val base64Payload = Base64.getEncoder().encodeToString(characteristic.value)
|
val base64Payload = Base64.getEncoder().encodeToString(characteristic.value)
|
||||||
publishMeasurement(base64Payload)
|
// publishMeasurement(base64Payload)
|
||||||
|
publishMeasurementAutoServer(measurement)
|
||||||
|
|
||||||
loggerDb.writeLog(measurement)
|
loggerDb.writeLog(measurement)
|
||||||
}
|
}
|
||||||
@@ -194,6 +195,46 @@ class KirbyDevice(
|
|||||||
queue.add(request)
|
queue.add(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun publishMeasurementAutoServer(measurement: DecoderIaq.Measurement) {
|
||||||
|
val accessKey = BuildConfig.API_KEY
|
||||||
|
val url = BuildConfig.API_BASE_URL
|
||||||
|
|
||||||
|
if(url.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val eui = "0000${bleDevice.address.replace(":", "")}"
|
||||||
|
|
||||||
|
val postData = JSONObject()
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Log.i("POST", "Transmitting for $eui: $payload")
|
||||||
|
postData.put("accessKey", "${accessKey}_fromAndroid")
|
||||||
|
postData.put("eui", eui)
|
||||||
|
postData.put("deviceId", measurement.deviceId)
|
||||||
|
postData.put("msgType", measurement.msgType)
|
||||||
|
postData.put("co2", measurement.co2)
|
||||||
|
postData.put("voc", measurement.voc)
|
||||||
|
postData.put("humidity", measurement.humidity)
|
||||||
|
postData.put("temperature", measurement.temperature)
|
||||||
|
postData.put("pressure", measurement.pressure)
|
||||||
|
postData.put("occupancy", measurement.occupancy)
|
||||||
|
postData.put("pm25", measurement.pm25)
|
||||||
|
postData.put("pm10", measurement.pm10)
|
||||||
|
} catch (e: JSONException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
|
||||||
|
val request = JsonObjectRequest(
|
||||||
|
Request.Method.POST, url, postData,
|
||||||
|
{ response ->
|
||||||
|
Log.i("sendDataResponse", "Response is: $response")
|
||||||
|
}
|
||||||
|
) { error -> error.printStackTrace() }
|
||||||
|
|
||||||
|
queue.add(request)
|
||||||
|
}
|
||||||
|
|
||||||
private val measurements = ArrayList<Payload>()
|
private val measurements = ArrayList<Payload>()
|
||||||
private val maxMeasurements = 20
|
private val maxMeasurements = 20
|
||||||
|
|
||||||
|
|||||||
7
app/src/main/res/xml/network_security_config.xml
Normal file
7
app/src/main/res/xml/network_security_config.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<network-security-config>
|
||||||
|
<base-config cleartextTrafficPermitted="true" />
|
||||||
|
<domain-config cleartextTrafficPermitted="true">
|
||||||
|
<domain includeSubdomains="true">192.168.1.154:5000</domain>
|
||||||
|
</domain-config>
|
||||||
|
</network-security-config>
|
||||||
Reference in New Issue
Block a user