Beacon Scaning

revert-dabc3590
Waruna Samarsinghe 9 years ago
parent 32c4a34283
commit cd1cf2bf44

@ -1,3 +1,20 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.iot.android.sense.beacon;
import android.app.NotificationManager;

@ -0,0 +1,80 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.iot.android.sense.beacon;
import java.util.Date;
public class BeaconScanedData {
private int beaconMajor;// Major
private int beaconMinor;//Minor
private String beaconProximity;// Proximity
private int beaconUuid;// Uuid
private long timestamp;// Timestamp
BeaconScanedData(int beaconMajor, int beaconMinor,String beaconProximity,int beaconUuid) {
this.beaconMajor = beaconMajor;
this.beaconMinor = beaconMinor;
this.beaconProximity = beaconProximity;
this.beaconUuid = beaconUuid;
timestamp = new Date().getTime();
}
public int getBeaconMajor() {
return beaconMajor;
}
public void setBeaconMajor(int beaconMajor) {
this.beaconMajor = beaconMajor;
}
public int getBeaconMinor() {
return beaconMinor;
}
public void setBeaconMinor(int beaconMinor) {
this.beaconMinor = beaconMinor;
}
public String getBeaconProximity() {
return beaconProximity;
}
public void setBeaconProximity(String beaconProximity) {
this.beaconProximity = beaconProximity;
}
public int getBeaconUuid() {
return beaconUuid;
}
public void setBeaconUuid(int beaconUuid) {
this.beaconUuid = beaconUuid;
}
public long getTimeStamp() {
return timestamp;
}
public void setTimeStamp(long timeStamp) {
timestamp = timeStamp;
}
}

@ -8,7 +8,23 @@ import android.content.Context;
import android.content.Intent;
import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
public class BeaconServiceUtility {
private Context context;

@ -41,6 +41,10 @@ import android.widget.TextView;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.MonitorNotifier;
import org.altbeacon.beacon.Region;
import org.wso2.carbon.iot.android.sense.beacon.BeaconScanedData;
import org.wso2.carbon.iot.android.sense.util.SenseDataHolder;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
@ -56,6 +60,8 @@ public class MonitoringActivity extends Activity implements BeaconConsumer {
private BeaconServiceUtility beaconUtill = null;
private BeaconManager iBeaconManager = BeaconManager.getInstanceForApplication(this);
BeaconScanedData beaconData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -66,6 +72,15 @@ public class MonitoringActivity extends Activity implements BeaconConsumer {
list.setAdapter(adapter);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
iBeaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
for(Beacon beacon : beacons) {
Log.d(TAG, "UUID:" + beacon.getId1() + ", major:" + beacon.getId2() + ", minor:" + beacon.getId3() + ", Distance:" + beacon.getDistance() + ",RSSI" + beacon.getRssi() + ", TxPower" + beacon.getTxPower());
}
}
});
}
@Override
@ -85,16 +100,22 @@ public class MonitoringActivity extends Activity implements BeaconConsumer {
super.onStop();
}
@Override
public void onBeaconServiceConnect() {
iBeaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> iBeacons, Region region) {
for (Beacon beacon: iBeacons) {
Log.i(TAG, "This beacon has identifiers:"+beacon.getId1()+", "+beacon.getId2()+", "+beacon.getId3());
arrayL.clear();
arrayL.addAll((ArrayList<Beacon>) iBeacons);
// adapter.notifyDataSetChanged();
}
// arrayL.clear();
// arrayL.addAll((ArrayList<Beacon>) iBeacons);
// adapter.notifyDataSetChanged();
}
});
@ -163,21 +184,26 @@ public class MonitoringActivity extends Activity implements BeaconConsumer {
} else {
holder = new ViewHolder(convertView = inflater.inflate(R.layout.tupple_monitoring, null));
}
if (arrayL.get(position).getId1() != null)
holder.beacon_uuid.setText("UUID: " + arrayL.get(position).getServiceUuid());
holder.beacon_uuid.setText("UUID: " + arrayL.get(position).getId1().toString().toUpperCase());
holder.beacon_major.setText("Major: " + arrayL.get(position).getId1());
holder.beacon_major.setText("Major: " + arrayL.get(position).getId2());
holder.beacon_minor.setText(", Minor: " + arrayL.get(position).getId2());
holder.beacon_minor.setText(" Minor: " + arrayL.get(position).getId3());
holder.beacon_proximity.setText("Proximity: " + arrayL.get(position).getId3());
double proximity = arrayL.get(position).getDistance();
holder.beacon_proximity.setText("Proximity: " + (new BigDecimal(proximity).setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue()));
holder.beacon_rssi.setText(", Rssi: " + arrayL.get(position).getRssi());
holder.beacon_rssi.setText(" Rssi: " + arrayL.get(position).getRssi());
holder.beacon_txpower.setText(", TxPower: " + arrayL.get(position).getTxPower());
holder.beacon_txpower.setText(" TxPower: " + arrayL.get(position).getTxPower());
holder.beacon_range.setText("" + arrayL.get(position).getDistance());
beaconData = new BeaconScanedData(arrayL.get(position).getId2().toInt(), arrayL.get(position).getId3().toInt(),holder.beacon_uuid.toString(),arrayL.get(position).getRssi());
SenseDataHolder.getBeaconScanedDataHolder().add(beaconData);
} catch (Exception e) {
e.printStackTrace();
}
@ -194,6 +220,7 @@ public class MonitoringActivity extends Activity implements BeaconConsumer {
private TextView beacon_txpower;
private TextView beacon_range;
public ViewHolder(View view) {
beacon_uuid = (TextView) view.findViewById(R.id.BEACON_uuid);
beacon_major = (TextView) view.findViewById(R.id.BEACON_major);
@ -203,6 +230,7 @@ public class MonitoringActivity extends Activity implements BeaconConsumer {
beacon_txpower = (TextView) view.findViewById(R.id.BEACON_txpower);
beacon_range = (TextView) view.findViewById(R.id.BEACON_range);
view.setTag(this);
}
}

@ -24,6 +24,7 @@ import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.carbon.iot.android.sense.beacon.BeaconScanedData;
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.AndroidSenseMQTTHandler;
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.MQTTTransportHandler;
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.TransportHandlerException;
@ -148,6 +149,21 @@ public class DataPublisherService extends Service {
}
SenseDataHolder.resetSpeedDataHolder();
//retrieve speed data.
List<BeaconScanedData> beaconDataMap = SenseDataHolder.getBeaconScanedDataHolder();
if (!speedDataMap.isEmpty()) {
for (BeaconScanedData beaconData : beaconDataMap) {
Event event = new Event();
event.setBeaconMajor(beaconData.getBeaconMajor());
event.setBeaconMinor(beaconData.getBeaconMinor());
event.setBeaconProximity(beaconData.getBeaconProximity());
event.setBeaconUuid(beaconData.getBeaconUuid());
events.add(event);
}
}
SenseDataHolder.resetSpeedDataHolder();
//retrieve words
ProcessWords.cleanAndPushToWordMap();
List<WordData> wordDatMap = SenseDataHolder.getWordDataHolder();

@ -28,6 +28,12 @@ public class Event {
private static float speed;
private String turn;
public static final float SPEED_LIMIT = 60;
private int beaconMajor;
private int beaconMinor;
private int beaconUuid;
private String beaconProximity;
private int getBattery() {
return battery;
@ -178,6 +184,9 @@ public class Event {
return speed;
}
public void setTurns(String turn) {
this.type = "turn";
@ -192,6 +201,46 @@ public class Event {
return turn;
}
public void setBeaconMajor(int beaconMajor) {
this.type = "beaconMajor";
this.beaconMajor = beaconMajor;
}
public int getBeaconMajor() {
this.type = "beaconMajor";
return beaconMajor;
}
public void setBeaconMinor(int beaconMinor) {
this.type = "beaconMinor";
this.beaconMinor = beaconMinor;
}
public int getBeaconMinor() {
this.type = "beaconMinor";
return beaconMinor;
}
public void setBeaconUuid(int beaconUuid) {
this.type = "beaconUuid";
this.beaconUuid = beaconUuid;
}
public int getBeaconUuid() {
this.type = "beaconUuid";
return beaconUuid;
}
public void setBeaconProximity(String beaconProximity) {
this.type = "beaconProximity";
this.beaconProximity = beaconProximity;
}
public String getBeaconProximity() {
this.type = "beaconProximity";
return beaconProximity;
}
public JSONObject getEvent() throws JSONException {
JSONObject jsonEvent = new JSONObject();
JSONObject jsonMetaData = new JSONObject();
@ -218,6 +267,12 @@ public class Event {
jsonPayloadData.put("speed_limit", getSpeed());
//}
//Beacon
jsonPayloadData.put("beacon_major", getBeaconMajor());
jsonPayloadData.put("beacon_minor", getBeaconMinor());
jsonPayloadData.put("beacon_proximity", getBeaconProximity());
jsonPayloadData.put("beacon_uuid", getBeaconUuid());
//turn
jsonPayloadData.put("turn_way", getTurns());
//magnetic

@ -18,6 +18,7 @@ import android.content.Context;
import org.wso2.carbon.iot.android.sense.event.streams.Location.LocationDataReader;
import org.wso2.carbon.iot.android.sense.event.streams.Sensor.SensorDataReader;
import org.wso2.carbon.iot.android.sense.event.streams.Speed.SpeedDataReader;
import org.wso2.carbon.iot.android.sense.beacon.MonitoringActivity;
/**
* This class triggered by service to collect the sensor data.
@ -39,6 +40,7 @@ public class SenseDataCollector {
case SPEED:
dr = new SpeedDataReader(ctx);
break;
}
if (dr != null) {
Thread DataCollector = new Thread(dr);

@ -13,6 +13,7 @@
*/
package org.wso2.carbon.iot.android.sense.util;
import org.wso2.carbon.iot.android.sense.beacon.BeaconScanedData;
import org.wso2.carbon.iot.android.sense.event.streams.Location.LocationData;
import org.wso2.carbon.iot.android.sense.event.streams.Sensor.SensorData;
import org.wso2.carbon.iot.android.sense.event.streams.Speed.SpeedData;
@ -33,7 +34,7 @@ public class SenseDataHolder {
private static List<LocationData> locationDataHolder;
private static List<WordData> wordDataHolder;
private static List<SpeedData> speedDataHolder;
private static List<BeaconScanedData> beaconScanedDataHolder;
//LocationData gps;
@ -80,6 +81,13 @@ public class SenseDataHolder {
return speedDataHolder;
}
public static List<BeaconScanedData> getBeaconScanedDataHolder(){
if(beaconScanedDataHolder == null){
beaconScanedDataHolder = new CopyOnWriteArrayList<>();
}
return beaconScanedDataHolder;
}
public static void resetSensorDataHolder(){
sensorDataHolder = null;
}
@ -100,5 +108,9 @@ public class SenseDataHolder {
speedDataHolder = null;
}
public static void resetBeaconScanedDataHolder() {
beaconScanedDataHolder = null;
}
}

@ -2,8 +2,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dip"
tools:context=".RangingActivity" >
android:padding="5dip" >
<TextView
android:layout_width="fill_parent"

@ -31,25 +31,27 @@
android:layout_height="wrap_content" >
<android.support.design.widget.FloatingActionButton
android:id="@+id/addSensors"
android:id="@+id/beacon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_input_add"/>
android:src="@drawable/beacon"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/speech"
android:id="@+id/addSensors"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/mic"/>
android:src="@android:drawable/ic_input_add"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/beacon"
android:id="@+id/speech"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/beacon"/>
android:src="@drawable/mic"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/publish"

Loading…
Cancel
Save