mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Merge branch 'master' of github.com:wso2/carbon-device-mgt-plugins
This commit is contained in:
commit
e05906fed5
@ -9,6 +9,7 @@ android {
|
||||
targetSdkVersion 22
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
@ -28,13 +29,22 @@ android {
|
||||
packagingOptions {
|
||||
exclude 'META-INF/NOTICE'
|
||||
exclude 'META-INF/LICENSE'
|
||||
exclude 'META-INF/DEPENDENCIES'
|
||||
exclude 'META-INF/NOTICE'
|
||||
exclude 'META-INF/LICENSE'
|
||||
exclude 'META-INF/LICENSE.txt'
|
||||
exclude 'META-INF/NOTICE.txt'
|
||||
}
|
||||
productFlavors {
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
targetCompatibility JavaVersion.VERSION_1_7
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
compile 'com.android.support:appcompat-v7:22.2.1'
|
||||
compile 'com.android.support:design:22.2.1'
|
||||
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2'
|
||||
@ -42,5 +52,6 @@ dependencies {
|
||||
compile 'commons-codec:commons-codec:1.4'
|
||||
compile 'com.netflix.feign:feign-jaxrs:8.16.0'
|
||||
compile 'com.netflix.feign:feign-jackson:8.16.0'
|
||||
compile 'org.altbeacon:android-beacon-library:2.8.1'
|
||||
|
||||
}
|
||||
|
||||
@ -13,6 +13,10 @@
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-sdk android:minSdkVersion="19" />
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/wso2logo"
|
||||
@ -68,6 +72,12 @@
|
||||
android:label="Speech Recongnizer"
|
||||
android:theme="@style/AppTheme.NoActionBar" >
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="org.wso2.carbon.iot.android.sense.beacon.MonitoringActivity"
|
||||
android:label="Beacon Monitor"
|
||||
android:theme="@style/AppTheme.NoActionBar" >
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
|
||||
|
||||
import org.altbeacon.beacon.BeaconConsumer;
|
||||
import org.altbeacon.beacon.BeaconManager;
|
||||
import org.altbeacon.beacon.MonitorNotifier;
|
||||
import org.altbeacon.beacon.Region;
|
||||
|
||||
public class BeaconDetactorService extends Service implements BeaconConsumer {
|
||||
|
||||
private BeaconManager iBeaconManager = BeaconManager.getInstanceForApplication(this);
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent arg0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
iBeaconManager.bind(this);
|
||||
|
||||
final Handler handler = new Handler();
|
||||
final Runnable runnable = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
stopSelf();
|
||||
}
|
||||
};
|
||||
handler.postDelayed(runnable, 10000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
iBeaconManager.unbind(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeaconServiceConnect() {
|
||||
iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
|
||||
@Override
|
||||
public void didEnterRegion(Region region) {
|
||||
Log.e("BeaconDetactorService", "didEnterRegion");
|
||||
generateNotification(BeaconDetactorService.this, region.getUniqueId()
|
||||
+ ": just saw this iBeacon for the first time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didExitRegion(Region region) {
|
||||
Log.e("BeaconDetactorService", "didExitRegion");
|
||||
generateNotification(BeaconDetactorService.this, region.getUniqueId() + ": is no longer visible");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didDetermineStateForRegion(int state, Region region) {
|
||||
Log.e("BeaconDetactorService", "didDetermineStateForRegion:" + state);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
try {
|
||||
iBeaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Issues a notification to inform the user that server has sent a message.
|
||||
*/
|
||||
private static void generateNotification(Context context, String message) {
|
||||
|
||||
Intent launchIntent = new Intent(context, MonitoringActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
||||
((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(
|
||||
0,
|
||||
new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis())
|
||||
.setSmallIcon(R.drawable.beacon).setTicker(message)
|
||||
.setContentTitle(context.getString(R.string.app_name)).setContentText(message)
|
||||
.setContentIntent(PendingIntent.getActivity(context, 0, launchIntent, 0)).setAutoCancel(true)
|
||||
.build());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package org.wso2.carbon.iot.android.sense.beacon;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
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;
|
||||
private PendingIntent pintent;
|
||||
private AlarmManager alarm;
|
||||
private Intent iService;
|
||||
|
||||
public BeaconServiceUtility(Context context) {
|
||||
super();
|
||||
this.context = context;
|
||||
iService = new Intent(context, BeaconDetactorService.class);
|
||||
alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
pintent = PendingIntent.getService(context, 0, iService, 0);
|
||||
}
|
||||
|
||||
public void onStart(BeaconManager iBeaconManager, BeaconConsumer consumer) {
|
||||
|
||||
stopBackgroundScan();
|
||||
iBeaconManager.bind(consumer);
|
||||
|
||||
}
|
||||
|
||||
public void onStop(BeaconManager iBeaconManager, BeaconConsumer consumer) {
|
||||
|
||||
iBeaconManager.unbind(consumer);
|
||||
startBackgroundScan();
|
||||
|
||||
}
|
||||
|
||||
private void stopBackgroundScan() {
|
||||
|
||||
alarm.cancel(pintent);
|
||||
context.stopService(iService);
|
||||
}
|
||||
|
||||
private void startBackgroundScan() {
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.SECOND, 2);
|
||||
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 360000, pintent); // 6*60 * 1000
|
||||
context.startService(iService);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,252 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed 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.Manifest;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.BaseAdapter;
|
||||
import org.altbeacon.beacon.BeaconConsumer;
|
||||
import org.altbeacon.beacon.BeaconManager;
|
||||
import org.altbeacon.beacon.Beacon;
|
||||
import org.altbeacon.beacon.RangeNotifier;
|
||||
import android.widget.ListView;
|
||||
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 java.util.logging.Handler;
|
||||
import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
|
||||
|
||||
public class MonitoringActivity extends Activity implements BeaconConsumer {
|
||||
protected static final String TAG = MonitoringActivity.class.getName();
|
||||
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 1;
|
||||
private ListView list = null;
|
||||
private BeaconAdapter adapter;
|
||||
private ArrayList<Beacon> arrayL = new ArrayList<>();
|
||||
private LayoutInflater inflater;
|
||||
|
||||
private BeaconServiceUtility beaconUtill = null;
|
||||
private BeaconManager iBeaconManager = BeaconManager.getInstanceForApplication(this);
|
||||
|
||||
BeaconScanedData beaconData;
|
||||
|
||||
@Override
|
||||
public void onBeaconServiceConnect() {
|
||||
|
||||
iBeaconManager.setBackgroundMode(true);
|
||||
|
||||
|
||||
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(iBeacons);
|
||||
//adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
|
||||
@Override
|
||||
public void didEnterRegion(Region region) {
|
||||
Log.e("BeaconDetactorService", "didEnterRegion");
|
||||
// logStatus("I just saw an iBeacon for the first time!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didExitRegion(Region region) {
|
||||
Log.e("BeaconDetactorService", "didExitRegion");
|
||||
// logStatus("I no longer see an iBeacon");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didDetermineStateForRegion(int state, Region region) {
|
||||
Log.e("BeaconDetactorService", "didDetermineStateForRegion");
|
||||
// logStatus("I have just switched from seeing/not seeing iBeacons: " + state);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
try {
|
||||
iBeaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
iBeaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_monitor);
|
||||
beaconUtill = new BeaconServiceUtility(this);
|
||||
list = (ListView) findViewById(R.id.list);
|
||||
adapter = new BeaconAdapter();
|
||||
list.setAdapter(adapter);
|
||||
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
//iBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
|
||||
iBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
|
||||
|
||||
iBeaconManager.bind(this);
|
||||
|
||||
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());
|
||||
}
|
||||
arrayL.clear();
|
||||
arrayL.addAll(beacons);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
beaconUtill.onStart(iBeaconManager, this);
|
||||
beaconUtill = new BeaconServiceUtility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
beaconUtill.onStop(iBeaconManager, this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
||||
private class BeaconAdapter extends BaseAdapter {
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (arrayL != null && arrayL.size() > 0)
|
||||
return arrayL.size();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Beacon getItem(int arg0) {
|
||||
return arrayL.get(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int arg0) {
|
||||
return arg0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
try {
|
||||
ViewHolder holder;
|
||||
|
||||
if (convertView != null) {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
} else {
|
||||
holder = new ViewHolder(convertView = inflater.inflate(R.layout.tupple_monitoring, null));
|
||||
}
|
||||
holder.beacon_uuid.setText("UUID: " + arrayL.get(position).getId1().toString().toUpperCase());
|
||||
|
||||
holder.beacon_major.setText("Major: " + arrayL.get(position).getId2());
|
||||
|
||||
holder.beacon_minor.setText(" Minor: " + 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_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();
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private class ViewHolder {
|
||||
private TextView beacon_uuid;
|
||||
private TextView beacon_major;
|
||||
private TextView beacon_minor;
|
||||
private TextView beacon_proximity;
|
||||
private TextView beacon_rssi;
|
||||
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);
|
||||
beacon_minor = (TextView) view.findViewById(R.id.BEACON_minor);
|
||||
beacon_proximity = (TextView) view.findViewById(R.id.BEACON_proximity);
|
||||
beacon_rssi = (TextView) view.findViewById(R.id.BEACON_rssi);
|
||||
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;
|
||||
@ -140,8 +141,24 @@ public class DataPublisherService extends Service {
|
||||
for (SpeedData speedData : speedDataMap) {
|
||||
Event event = new Event();
|
||||
event.setTimestamp(speedData.getTimeStamp());
|
||||
event.setSpeed(speedData.getSpeed());
|
||||
event.setTurns(speedData.getTurns());
|
||||
event.setSpeed(speedData.getSpeed());
|
||||
|
||||
events.add(event);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -174,9 +180,7 @@ public class Event {
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
|
||||
this.type = "speed";
|
||||
|
||||
return speed;
|
||||
}
|
||||
|
||||
@ -194,6 +198,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();
|
||||
@ -209,18 +253,23 @@ public class Event {
|
||||
double gpsEvents[] = getGps();
|
||||
jsonPayloadData.put("gps_lat", gpsEvents[0]);
|
||||
jsonPayloadData.put("gps_long", gpsEvents[1]);
|
||||
//acceleromter
|
||||
//accelerometer
|
||||
float events[] = getAccelerometer();
|
||||
jsonPayloadData.put("accelerometer_x", events[0]);
|
||||
jsonPayloadData.put("accelerometer_y", events[1]);
|
||||
jsonPayloadData.put("accelerometer_z", events[2]);
|
||||
|
||||
//speed
|
||||
|
||||
//if (getSpeed()>SPEED_LIMIT) {
|
||||
jsonPayloadData.put("speed_limit", getSpeed());
|
||||
//}
|
||||
|
||||
//Beacon Data
|
||||
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
|
||||
|
||||
@ -40,7 +40,6 @@ public class LocationDataReader extends DataReader implements LocationListener {
|
||||
|
||||
static final Double EARTH_RADIUS = 6371.00;
|
||||
|
||||
|
||||
// flag for GPS status
|
||||
private boolean isGPSEnabled = false;
|
||||
|
||||
@ -176,8 +175,6 @@ public class LocationDataReader extends DataReader implements LocationListener {
|
||||
|
||||
time=c.get(Calendar.HOUR);
|
||||
|
||||
|
||||
|
||||
locationManager.removeUpdates(LocationDataReader.this);
|
||||
//String Speed = "Device Speed: " +location.getSpeed();
|
||||
latitude=location.getLongitude();
|
||||
@ -185,7 +182,6 @@ public class LocationDataReader extends DataReader implements LocationListener {
|
||||
|
||||
double distance =CalculationByDistance(latitude, longitude, lat_old, lon_old)/1000;
|
||||
|
||||
|
||||
speed = (float)distance/(float)time;
|
||||
Toast.makeText(mContext, longitude+"\n"+latitude+"\nDistance is: "
|
||||
+distance+"\nSpeed is: "+speed , Toast.LENGTH_SHORT).show();
|
||||
@ -219,7 +215,6 @@ public class LocationDataReader extends DataReader implements LocationListener {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(TAG, "running -Location");
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -35,7 +35,8 @@ import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import org.wso2.carbon.iot.android.sense.RegisterActivity;
|
||||
import org.wso2.carbon.iot.android.sense.data.publisher.DataPublisherReceiver;
|
||||
import org.wso2.carbon.iot.android.sense.data.publisher.DataPublisherService;
|
||||
@ -48,11 +49,13 @@ import org.wso2.carbon.iot.android.sense.realtimeviewer.sensorlisting.SupportedS
|
||||
import org.wso2.carbon.iot.android.sense.realtimeviewer.view.adaptor.SensorViewAdaptor;
|
||||
import org.wso2.carbon.iot.android.sense.realtimeviewer.view.sensor.selector.SelectSensorDialog;
|
||||
import org.wso2.carbon.iot.android.sense.speech.detector.WordRecognitionActivity;
|
||||
import org.wso2.carbon.iot.android.sense.util.LocalRegistry;
|
||||
import org.wso2.carbon.iot.android.sense.beacon.MonitoringActivity;
|
||||
|
||||
import org.wso2.carbon.iot.android.sense.util.LocalRegistry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.altbeacon.beacon.BeaconManager;
|
||||
|
||||
import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
|
||||
|
||||
@ -73,6 +76,8 @@ public class ActivitySelectSensor extends AppCompatActivity
|
||||
private RealTimeSensorReader sensorReader = null;
|
||||
private RealTimeSensorChangeReceiver realTimeSensorChangeReceiver = new RealTimeSensorChangeReceiver();
|
||||
private SupportedSensors supportedSensors = SupportedSensors.getInstance();
|
||||
protected static final String TAG = ActivitySelectSensor.class.getName();
|
||||
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 1;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -85,6 +90,7 @@ public class ActivitySelectSensor extends AppCompatActivity
|
||||
sessionIdText.setCursorVisible(false);
|
||||
|
||||
listView = (ListView) findViewById(R.id.senseListContainer);
|
||||
verifyBluetooth();
|
||||
|
||||
registerReceiver(realTimeSensorChangeReceiver, new IntentFilter("sensorDataMap"));
|
||||
|
||||
@ -136,6 +142,18 @@ public class ActivitySelectSensor extends AppCompatActivity
|
||||
}
|
||||
});
|
||||
|
||||
FloatingActionButton fbtnBeaconMonitor = (FloatingActionButton) findViewById(R.id.beacon);
|
||||
fbtnBeaconMonitor.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(getApplicationContext(), MonitoringActivity.class);
|
||||
startActivity(intent);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
sharedPreferences = getSharedPreferences(SupportedSensors.SELECTED_SENSORS, 0);
|
||||
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
@ -293,4 +311,44 @@ public class ActivitySelectSensor extends AppCompatActivity
|
||||
public void unregisterReceivers() {
|
||||
unregisterReceiver(realTimeSensorChangeReceiver);
|
||||
}
|
||||
|
||||
private void verifyBluetooth() {
|
||||
|
||||
try {
|
||||
if (!BeaconManager.getInstanceForApplication(this).checkAvailability()) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Bluetooth not enabled");
|
||||
builder.setMessage("Please enable bluetooth in settings and restart this application.");
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
finish();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
});
|
||||
builder.show();
|
||||
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Bluetooth LE not available");
|
||||
builder.setMessage("Sorry, this device does not support Bluetooth LE.");
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
finish();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
});
|
||||
builder.show();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.siddhi.dto;
|
||||
|
||||
public class BLE {
|
||||
int id;
|
||||
long timeStamp;
|
||||
String location;
|
||||
|
||||
public BLE(int id, String location){
|
||||
this.id = id;
|
||||
this.location = location;
|
||||
timeStamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getTimeStamp() {
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
public void setTimeStamp(long timeStamp) {
|
||||
this.timeStamp = timeStamp;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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.siddhi.eventprocessor.core;
|
||||
|
||||
import org.wso2.carbon.iot.android.sense.siddhi.dto.BLE;
|
||||
import org.wso2.carbon.iot.android.sense.siddhi.eventprocessor.wrapper.SidhdhiWrapper;
|
||||
import org.wso2.siddhi.core.SiddhiManager;
|
||||
import org.wso2.siddhi.core.event.Event;
|
||||
import org.wso2.siddhi.core.stream.input.InputHandler;
|
||||
import org.wso2.siddhi.core.ExecutionPlanRuntime;
|
||||
import org.wso2.siddhi.core.stream.output.StreamCallback;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
|
||||
public class SidhdhiQueryExecutor implements Runnable {
|
||||
|
||||
protected String query = null;
|
||||
private static SiddhiManager siddhiManager = new SiddhiManager();
|
||||
private static final int INTERVAL = 3000;
|
||||
|
||||
public volatile Thread sidhdiThread;
|
||||
private ReadWriteLock rwlock = new ReentrantReadWriteLock();
|
||||
|
||||
//TODO have another array initialized so that a list of callbacks can be stored, String[] callbackList
|
||||
public SidhdhiQueryExecutor(String query){
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public void run(){
|
||||
//TODO the array of callbacks needs to be passed to invoke
|
||||
//TODO what is retruned should be a map of callbacks and outputs
|
||||
ExecutionPlan executionPlan = new ExecutionPlan().invoke();
|
||||
|
||||
Thread thisThread = Thread.currentThread();
|
||||
|
||||
while (sidhdiThread == thisThread) {
|
||||
InputHandler inputHandler = executionPlan.getInputHandler();
|
||||
|
||||
//Sending events to Siddhi
|
||||
try {
|
||||
List<BLE> bleReadings = read();
|
||||
for(BLE ble : bleReadings){
|
||||
System.out.println("Publishing data...");
|
||||
inputHandler.send(new Object[]{ble.getId(), ble.getTimeStamp(), ble.getLocation()});
|
||||
}
|
||||
|
||||
thisThread.sleep(INTERVAL);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<BLE> read()
|
||||
{
|
||||
List<BLE> bleData;
|
||||
rwlock.readLock().lock();
|
||||
try {
|
||||
//TODO Reading BLE VALUES
|
||||
bleData = SidhdhiWrapper.getBleData();
|
||||
} finally {
|
||||
rwlock.readLock().unlock();
|
||||
}
|
||||
return bleData;
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
sidhdiThread = null;
|
||||
}
|
||||
|
||||
public void start(){
|
||||
sidhdiThread = new Thread(this);
|
||||
sidhdiThread.start();
|
||||
}
|
||||
|
||||
private class ExecutionPlan {
|
||||
|
||||
private InputHandler inputHandler;
|
||||
|
||||
public InputHandler getInputHandler() {
|
||||
return inputHandler;
|
||||
}
|
||||
|
||||
//TODO should expect an array of callbacks
|
||||
public ExecutionPlan invoke() {
|
||||
|
||||
//Generating runtime
|
||||
ExecutionPlanRuntime runtime = siddhiManager.createExecutionPlanRuntime(query);
|
||||
|
||||
|
||||
|
||||
//TODO logic needs to be revised so that array of callbacks are processed
|
||||
runtime.addCallback("dataOut", new StreamCallback() {
|
||||
@Override
|
||||
public void receive(Event[] events) {
|
||||
System.out.println("Location Match event initiated.");
|
||||
if (events.length > 0) {
|
||||
//TODO Configure Event here!
|
||||
System.out.println("Firing location match event...");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//Retrieving InputHandler to push events into Siddhi
|
||||
inputHandler = runtime.getInputHandler("dataIn");
|
||||
|
||||
//Starting event processing
|
||||
runtime.start();
|
||||
System.out.println("Execution Plan Started!");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.siddhi.eventprocessor.wrapper;
|
||||
|
||||
import org.wso2.carbon.iot.android.sense.siddhi.dto.BLE;
|
||||
import org.wso2.carbon.iot.android.sense.siddhi.eventprocessor.core.SidhdhiQueryExecutor;
|
||||
import org.wso2.carbon.iot.android.sense.siddhi.reader.BLEReader;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class SidhdhiWrapper {
|
||||
|
||||
private static List<BLE> bleData;
|
||||
|
||||
public static List<BLE> getBleData() {
|
||||
return bleData;
|
||||
}
|
||||
|
||||
public static void setBleData(List<BLE> bleData) {
|
||||
SidhdhiWrapper.bleData = bleData;
|
||||
}
|
||||
|
||||
public static void main(String args[]){
|
||||
String query = "@Import('iot.sample.input:1.0.0')\n" +
|
||||
"define stream dataIn (id int, timestamp long, location string);\n" +
|
||||
"\n" +
|
||||
"@Export('iot.sample.output:1.0.0')\n" +
|
||||
"define stream dataOut (action string, timestamp long);\n" +
|
||||
"\n" +
|
||||
"from every e1=dataIn[location=='loc_1'] -> e2=dataIn[location=='loc_2'] -> e3=dataIn[location=='loc_3']\n" +
|
||||
"select 'x' as action, e3.timestamp\n" +
|
||||
"insert into dataOut;";
|
||||
|
||||
BLEReader blEReader = new BLEReader();
|
||||
blEReader.start();
|
||||
|
||||
SidhdhiQueryExecutor queryExecutor = new SidhdhiQueryExecutor(query);
|
||||
queryExecutor.start();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.siddhi.reader;
|
||||
|
||||
import org.wso2.carbon.iot.android.sense.siddhi.dto.BLE;
|
||||
import org.wso2.carbon.iot.android.sense.siddhi.eventprocessor.wrapper.SidhdhiWrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
public class BLEReader implements Runnable{
|
||||
|
||||
private ReadWriteLock rwlock = new ReentrantReadWriteLock();
|
||||
List<BLE> bleData = new ArrayList<BLE>();
|
||||
public volatile Thread bleReader;
|
||||
private static final int INTERVAL = 2000;
|
||||
|
||||
public void run(){
|
||||
Thread thisThread = Thread.currentThread();
|
||||
while (bleReader == thisThread) {
|
||||
write();
|
||||
try {
|
||||
thisThread.sleep(INTERVAL);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
bleReader = null;
|
||||
}
|
||||
|
||||
public void start(){
|
||||
bleReader = new Thread(this);
|
||||
bleReader.start();
|
||||
}
|
||||
|
||||
public void write()
|
||||
{
|
||||
rwlock.writeLock().lock();
|
||||
try {
|
||||
bleData.add(new BLE(123, "loc_1"));
|
||||
bleData.add(new BLE(123, "loc_2"));
|
||||
bleData.add(new BLE(123, "loc_3"));
|
||||
SidhdhiWrapper.setBleData(bleData);
|
||||
} finally {
|
||||
rwlock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,7 +51,7 @@ public class SenseClient {
|
||||
String responseStatus = response.get("status");
|
||||
RegisterInfo registerInfo = new RegisterInfo();
|
||||
if (responseStatus.trim().contains(SenseConstants.Request.REQUEST_SUCCESSFUL)) {
|
||||
registerInfo.setMsg("Login Succesful");
|
||||
registerInfo.setMsg("Login Successful");
|
||||
registerInfo.setIsRegistered(true);
|
||||
return registerInfo;
|
||||
} else {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="false">
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="#fa09ad"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="#c20586"/>
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
@ -0,0 +1,21 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="5dip" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="Scanning..." />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:divider="@android:color/darker_gray"
|
||||
android:dividerHeight="1dip" />
|
||||
|
||||
</RelativeLayout>
|
||||
@ -6,7 +6,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context="org.wso2.carbon.iot.android.sense.realtimeviewer.ActivitySelectSensor">
|
||||
tools:context="org.wso2.carbon.iot.android.sense.realtimeviewer.ActivitySelectSensor"
|
||||
android:touchscreenBlocksFocus="false">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -24,30 +25,42 @@
|
||||
|
||||
<include layout="@layout/content_activity_select_sensor"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/publish"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:adjustViewBounds="false"
|
||||
android:src="@drawable/pushtoserver"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_gravity="bottom|center"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/speech"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/mic"/>
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/beacon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/beacon"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/addSensors"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|start"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@android:drawable/ic_input_add"/>
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/addSensors"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@android:drawable/ic_input_add"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/speech"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/mic"/>
|
||||
|
||||
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/publish"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:adjustViewBounds="false"
|
||||
android:src="@drawable/pushtoserver"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:background="@drawable/round_button"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginStart="20dp"/>
|
||||
|
||||
|
||||
<Button
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:background="@drawable/round_button"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:gravity="center" />
|
||||
|
||||
<Button
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:background="@drawable/round_button"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:gravity="center" />
|
||||
|
||||
<Button
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:background="@drawable/round_button"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:gravity="center" />
|
||||
|
||||
</LinearLayout>
|
||||
@ -0,0 +1,80 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/white"
|
||||
android:paddingBottom="10dip"
|
||||
android:paddingTop="10dip" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/BEACON_uuid"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:gravity="left|top" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/BEACON_major"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@+id/BEACON_uuid"
|
||||
android:layout_marginTop="5dp"
|
||||
android:gravity="left|top" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/BEACON_minor"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/BEACON_uuid"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_toRightOf="@+id/BEACON_major"
|
||||
android:gravity="left|top" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/BEACON_proximity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@+id/BEACON_major"
|
||||
android:layout_marginTop="5dp"
|
||||
android:gravity="left|top" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/BEACON_rssi"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/BEACON_major"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_toRightOf="@+id/BEACON_proximity"
|
||||
android:gravity="left|top" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/BEACON_txpower"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/BEACON_major"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_toRightOf="@+id/BEACON_rssi"
|
||||
android:gravity="left|top" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/BEACON_range"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/BEACON_proximity"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginTop="5dp"
|
||||
android:gravity="left|top" >
|
||||
</TextView>
|
||||
|
||||
</RelativeLayout>
|
||||
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/webView1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
/>
|
||||
@ -5,5 +5,5 @@
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="nav_header_vertical_spacing">16dp</dimen>
|
||||
<dimen name="nav_header_height">160dp</dimen>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
<dimen name="fab_margin">40dp</dimen>
|
||||
</resources>
|
||||
|
||||
@ -51,4 +51,70 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>wso2-nexus</id>
|
||||
<name>WSO2 internal Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
<checksumPolicy>ignore</checksumPolicy>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>wso2.releases</id>
|
||||
<name>WSO2 internal Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
<checksumPolicy>ignore</checksumPolicy>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!--Dependency on Sidhdhi - required for PolicyMgt-->
|
||||
<dependency>
|
||||
<groupId>org.wso2.siddhi</groupId>
|
||||
<artifactId>siddhi-query-compiler</artifactId>
|
||||
<version>${sidhdhi.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.siddhi</groupId>
|
||||
<artifactId>siddhi-query-api</artifactId>
|
||||
<version>${sidhdhi.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.siddhi</groupId>
|
||||
<artifactId>siddhi-core</artifactId>
|
||||
<version>${sidhdhi.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${apache-httpclient.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<!-- Java Version Compatibility -->
|
||||
<wso2.maven.compiler.source>1.7</wso2.maven.compiler.source>
|
||||
<wso2.maven.compiler.target>1.7</wso2.maven.compiler.target>
|
||||
<!--Apache HTTP Components-->
|
||||
<apache-httpclient.version>4.5</apache-httpclient.version>
|
||||
<!-- Sidhdhi Version -->
|
||||
<sidhdhi.version>3.0.5</sidhdhi.version>
|
||||
<gson.version>2.3.1</gson.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@ -21,7 +21,7 @@
|
||||
<mapping customMapping="disable" type="text"/>
|
||||
<to eventAdapterType="email">
|
||||
<property name="email.subject">Email Alerts Speed</property>
|
||||
<property name="email.address"></property>
|
||||
<property name="email.address">pacificcontrolsapps@gmail.com</property>
|
||||
<property name="email.type">text/html</property>
|
||||
</to>
|
||||
</eventPublisher>
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
<mapping customMapping="disable" type="text"/>
|
||||
<to eventAdapterType="email">
|
||||
<property name="email.subject">Email Alerts Turn</property>
|
||||
<property name="email.address"></property>
|
||||
<property name="email.address">pacificcontrolsapps@gmail.com</property>
|
||||
<property name="email.type">text/html</property>
|
||||
</to>
|
||||
</eventPublisher>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user