Fetching the data when device is in range
This commit is contained in:
parent
64670f8cef
commit
88dc2bf33b
@ -27,7 +27,7 @@
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.BeaconDemo"
|
||||
android:theme="@style/Theme.AppCompat.Light"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".Activity.DetailActivity"
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.example.beacondemo.Activity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
@ -17,6 +19,7 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.beacondemo.BindView;
|
||||
@ -36,6 +39,7 @@ import com.minew.beaconplus.sdk.frames.HTFrame;
|
||||
import com.minew.beaconplus.sdk.frames.IBeaconFrame;
|
||||
import com.minew.beaconplus.sdk.frames.InfoFrame;
|
||||
import com.minew.beaconplus.sdk.frames.LightFrame;
|
||||
import com.minew.beaconplus.sdk.frames.LineBeaconFrame;
|
||||
import com.minew.beaconplus.sdk.frames.MinewFrame;
|
||||
import com.minew.beaconplus.sdk.frames.PIRFrame;
|
||||
import com.minew.beaconplus.sdk.frames.TamperProofFrame;
|
||||
@ -57,7 +61,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
private static final int REQUEST_ENABLE_BT = 3;
|
||||
private static final int PERMISSION_COARSE_LOCATION = 2;
|
||||
|
||||
@BindView(R.id.recycle)
|
||||
//@BindView(R.id.recycle)
|
||||
RecyclerView mRecycle;
|
||||
|
||||
private MTCentralManager mMtCentralManager;
|
||||
@ -71,6 +75,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
ArrayList<MinewFrame> advFrames;
|
||||
|
||||
TextView txt_name,txt_mac,txt_battery,txt_rssi,txt_device,txt_xaxis,txt_yaxis,txt_zaxis;
|
||||
String mac,name;
|
||||
int battery,rssi;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -130,93 +138,165 @@ public class MainActivity extends AppCompatActivity {
|
||||
mMtCentralManager.setMTCentralManagerListener(new MTCentralManagerListener() {
|
||||
@Override
|
||||
public void onScanedPeripheral(final List<MTPeripheral> peripherals) {
|
||||
Log.e("Peripherals : ", String.valueOf(peripherals.size()));
|
||||
for (MTPeripheral mtPeripheral : peripherals) {
|
||||
// get FrameHandler of a device.
|
||||
MTFrameHandler mtFrameHandler = mtPeripheral.mMTFrameHandler;
|
||||
String mac = mtFrameHandler.getMac(); //mac address of device
|
||||
String name = mtFrameHandler.getName(); // name of device
|
||||
int battery = mtFrameHandler.getBattery(); //battery
|
||||
int rssi = mtFrameHandler.getRssi(); //rssi
|
||||
mac = mtFrameHandler.getMac(); //mac address of device
|
||||
name = mtFrameHandler.getName(); // name of device
|
||||
battery = mtFrameHandler.getBattery(); //battery
|
||||
rssi = mtFrameHandler.getRssi(); //rssi
|
||||
txt_device.setText("Device in range. ");
|
||||
|
||||
|
||||
txt_mac.setText("Mac Address : "+mac);
|
||||
txt_name.setText("Device Name : "+name);
|
||||
txt_battery.setText("Battery Status : "+battery);
|
||||
txt_rssi.setText(" Rssi : "+rssi);
|
||||
|
||||
|
||||
// all data frames of device(such as:iBeacon,UID,URL...)
|
||||
advFrames = mtFrameHandler.getAdvFrames();
|
||||
/*for (MinewFrame minewFrame : advFrames) {
|
||||
Log.v("Device Log : ", advFrames.toString());
|
||||
for (MinewFrame minewFrame : advFrames) {
|
||||
FrameType frameType = minewFrame.getFrameType();
|
||||
switch (frameType) {
|
||||
case FrameiBeacon://iBeacon
|
||||
IBeaconFrame iBeaconFrame = (IBeaconFrame) minewFrame;
|
||||
Log.v("beaconplus", iBeaconFrame.getUuid() + iBeaconFrame.getMajor() + iBeaconFrame.getMinor());
|
||||
Log.v("beaconplus1", iBeaconFrame.getUuid() + iBeaconFrame.getMajor() + iBeaconFrame.getMinor());
|
||||
break;
|
||||
case FrameUID://uid
|
||||
UidFrame uidFrame = (UidFrame) minewFrame;
|
||||
Log.v("beaconplus", uidFrame.getNamespaceId() + uidFrame.getInstanceId());
|
||||
Log.v("beaconplus2", uidFrame.getNamespaceId() + uidFrame.getInstanceId());
|
||||
break;
|
||||
case FrameAccSensor:
|
||||
AccFrame accFrame = (AccFrame) minewFrame;//acc
|
||||
Log.v("beaconplus", String.valueOf(accFrame.getXAxis() + accFrame.getYAxis() + accFrame.getZAxis()));
|
||||
txt_xaxis.setText("X axis: " + accFrame.getXAxis());
|
||||
txt_yaxis.setText("Y axis: " + accFrame.getYAxis());
|
||||
txt_zaxis.setText("Z axis: " + accFrame.getZAxis());
|
||||
Log.v("beaconplus3", String.valueOf(accFrame.getXAxis() + " "+ accFrame.getYAxis() +" "+ accFrame.getZAxis()));
|
||||
break;
|
||||
case FrameHTSensor:
|
||||
HTFrame htFrame = (HTFrame) minewFrame;//ht
|
||||
Log.v("beaconplus", String.valueOf(htFrame.getTemperature() + htFrame.getHumidity()));
|
||||
Log.v("beaconplus4", String.valueOf(htFrame.getTemperature() + htFrame.getHumidity()));
|
||||
break;
|
||||
case FrameTLM:
|
||||
TlmFrame tlmFrame = (TlmFrame) minewFrame;//tlm
|
||||
Log.v("beaconplus", String.valueOf(tlmFrame.getTemperature() + tlmFrame.getBatteryVol() + tlmFrame.getSecCount() + tlmFrame.getAdvCount()));
|
||||
Log.v("beaconplus5", String.valueOf(tlmFrame.getTemperature() + tlmFrame.getBatteryVol() + tlmFrame.getSecCount() + tlmFrame.getAdvCount()));
|
||||
break;
|
||||
case FrameURL:
|
||||
UrlFrame urlFrame = (UrlFrame) minewFrame;//url
|
||||
Log.v("beaconplus", "Link:" + urlFrame.getUrlString() + "Rssi @ 0m:" + urlFrame.getTxPower());
|
||||
Log.v("beaconplus6", "Link:" + urlFrame.getUrlString() + "Rssi @ 0m:" + urlFrame.getTxPower());
|
||||
break;
|
||||
case FrameLightSensor:
|
||||
LightFrame lightFrame = (LightFrame) minewFrame;//light
|
||||
Log.v("beaconplus", "battery:" + lightFrame.getBattery() + "%" + lightFrame.getLuxValue());
|
||||
Log.v("beaconplus7", "battery:" + lightFrame.getBattery() + "%" + lightFrame.getLuxValue());
|
||||
break;
|
||||
case FrameForceSensor:
|
||||
ForceFrame forceFrame = ((ForceFrame) minewFrame);//force
|
||||
Log.v("beaconplus", "battery:" + forceFrame.getBattery() + "%" + "force:" + forceFrame.getForce() + "gram");
|
||||
Log.v("beaconplus8", "battery:" + forceFrame.getBattery() + "%" + "force:" + forceFrame.getForce() + "gram");
|
||||
break;
|
||||
case FramePIRSensor:
|
||||
PIRFrame pirFrame = ((PIRFrame) minewFrame);//pir
|
||||
Log.v("beaconplus", "battery:" + pirFrame.getBattery() + "%" + "PIR:", pirFrame.getValue());
|
||||
Log.v("beaconplus9", "battery:" + pirFrame.getBattery() + "%" + "PIR:"+ pirFrame.getPirData());
|
||||
break;
|
||||
case FrameTempSensor://temp
|
||||
TemperatureFrame temperatureFrame = (TemperatureFrame) minewFrame;
|
||||
Log.v("beaconplus", "battery:" + temperatureFrame.getBattery() + "%,temperature:" + String.format("%.2f", temperatureFrame.getValue()) + "°C");
|
||||
Log.v("beaconplus10", "battery:" + temperatureFrame.getBattery() + "%,temperature:" + String.format("%.2f", temperatureFrame.getValue()) + "°C");
|
||||
break;
|
||||
case FrameTVOCSensor://tvoc
|
||||
TvocFrame tvocFrame = (TvocFrame) minewFrame;
|
||||
Log.v("beaconplus", "battery:" + tvocFrame.getBattery() + ",TVOC:"+ tvocFrame.getValue() + "ppb," + "battery:" +tvocFrame.getBattery() + "mV");
|
||||
Log.v("beaconplus11", "battery:" + tvocFrame.getBattery() + ",TVOC:"+ tvocFrame.getValue() + "ppb," + "battery:" +tvocFrame.getBattery() + "mV");
|
||||
break;
|
||||
case FrameLineBeacon://FrameLineBeacon
|
||||
FrameLineBeacon lineBeacon = ((FrameLineBeacon) minewFrame);
|
||||
Log.v("beaconplus", "Hwid:" + lineBeacon.getHwid()
|
||||
+ ",Rssi@1m:", lineBeacon.getTxPower()
|
||||
+ ",authentication:"lineBeacon.getAuthentication()
|
||||
LineBeaconFrame lineBeacon = ((LineBeaconFrame) minewFrame);
|
||||
Log.v("beaconplus12", "Hwid:" + lineBeacon.getHwid()
|
||||
+ ",Rssi@1m:"+ lineBeacon.getTxPower()
|
||||
+ ",authentication:"+lineBeacon.getAuthentication()
|
||||
+ ",timesTamp:" + lineBeacon.getTimesTamp());
|
||||
break;
|
||||
case TamperProofFrame://TamperProofFrame
|
||||
case FrameTamperProof://TamperProofFrame
|
||||
TamperProofFrame tamperProofFrame = ((TamperProofFrame) minewFrame);//
|
||||
Log.v("beaconplus", "battery:" + tamperProofFrame.getBattery());
|
||||
Log.v("beaconplus13", "battery:" + tamperProofFrame.getBattery());
|
||||
break;
|
||||
case InfoFrame://InfoFrame
|
||||
case FrameDeviceInfo://InfoFrame
|
||||
InfoFrame infoFrame = ((InfoFrame) minewFrame);//
|
||||
Log.v("beaconplus", infoFrame.getMajor() + infoFrame.getMinor() + infoFrame.getBatteryVoltage());
|
||||
Log.v("beaconplus14", infoFrame.getMajor() + infoFrame.getMinor() + infoFrame.getBatteryVoltage());
|
||||
break;
|
||||
default:
|
||||
Log.v("Device range", "Device not found");
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
Log.e("Equals", "equals");
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
Log.e("Finalize", "finalize");
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
Log.e("HashCode", "hashCode");
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
Log.e("Clone", "clone");
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
Log.e("ToString", "toString");
|
||||
return super.toString();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
txt_battery=findViewById(R.id.txt_battery);
|
||||
txt_mac=findViewById(R.id.txt_mac);
|
||||
txt_name=findViewById(R.id.txt_name);
|
||||
txt_rssi=findViewById(R.id.txt_rssi);
|
||||
txt_device=findViewById(R.id.txt_device);
|
||||
txt_xaxis=findViewById(R.id.txt_xaxis);
|
||||
txt_yaxis=findViewById(R.id.txt_yaxis);
|
||||
txt_zaxis=findViewById(R.id.txt_zaxis);
|
||||
mRecycle.setLayoutManager(layoutManager);
|
||||
mAdapter = new RecycleAdapter();
|
||||
mRecycle.setAdapter(mAdapter);
|
||||
/*mRecycle.addItemDecoration(new RecycleViewDivider(this, LinearLayoutManager
|
||||
.HORIZONTAL));*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void initManager() {
|
||||
|
@ -1,19 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".Activity.MainActivity"
|
||||
android:backgroundTint="@color/white"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Name :"
|
||||
android:id="@+id/txt_name"
|
||||
android:layout_marginTop="20dp"
|
||||
>
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Macc :"
|
||||
android:id="@+id/txt_mac"
|
||||
android:layout_marginTop="20dp"
|
||||
>
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Battery :"
|
||||
android:id="@+id/txt_battery"
|
||||
android:layout_marginTop="20dp"
|
||||
>
|
||||
</TextView>
|
||||
|
||||
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_rssi"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="Rssi :"></TextView>
|
||||
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_xaxis"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="X axis :"></TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_yaxis"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="Y axis :"></TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_zaxis"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="Z axis :"></TextView>
|
||||
<TextView
|
||||
android:id="@+id/txt_device"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="Device range :"></TextView>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycle"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
@ -2,12 +2,12 @@
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.BeaconDemo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_500</item>
|
||||
<item name="colorPrimary">@color/purple_200</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||
<item name="colorOnPrimary">@color/white</item>
|
||||
<item name="colorOnPrimary">@color/black</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_700</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_200</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user