| xqd
@@ -4,7 +4,6 @@ import android.Manifest;
|
|
|
import android.app.ActivityManager;
|
|
|
import android.app.AlarmManager;
|
|
|
import android.app.Application;
|
|
|
-
|
|
|
import android.app.PendingIntent;
|
|
|
import android.bluetooth.BluetoothAdapter;
|
|
|
import android.bluetooth.BluetoothDevice;
|
| xqd
@@ -35,6 +34,7 @@ import android.os.BatteryManager;
|
|
|
import android.os.Build;
|
|
|
import android.os.Handler;
|
|
|
import android.os.ParcelUuid;
|
|
|
+import android.provider.Settings;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.annotation.RequiresApi;
|
|
|
import android.support.v4.app.ActivityCompat;
|
| xqd
@@ -100,7 +100,10 @@ import top.maybesix.xhlibrary.serialport.ComPortData;
|
|
|
import top.maybesix.xhlibrary.serialport.SerialPortHelper;
|
|
|
import top.maybesix.xhlibrary.util.HexStringUtils;
|
|
|
|
|
|
+import com.siwei.recyclebox.entity.MapLocationInfo;
|
|
|
+import com.siwei.recyclebox.service.MyService;
|
|
|
import com.siwei.recyclebox.utils.DemoOne;
|
|
|
+import com.siwei.recyclebox.utils.LocationUtils;
|
|
|
import com.siwei.recyclebox.utils.SilentInstall;
|
|
|
import com.siwei.recyclebox.utils.unZipFileDemo;
|
|
|
import com.zhy.http.okhttp.OkHttpUtils;
|
| xqd
@@ -116,11 +119,37 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
private TimerTask task1;
|
|
|
private TimerTask task2;
|
|
|
private TimerTask task3;
|
|
|
+ private LocationUtils mLocationUtils;
|
|
|
+ /** 定位信息 */
|
|
|
+ private MapLocationInfo mMapLocationInfo;
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
|
public void onCreate(){
|
|
|
super.onCreate();
|
|
|
-// Intent service = new Intent(getApplication(), MyService.class);
|
|
|
-// getApplication().startService(service);//打开服务,把程序写在服务里不容易被系统kill
|
|
|
+ Intent service = new Intent(getApplication(), MyService.class);
|
|
|
+ getApplication().startService(service);//打开服务,把程序写在服务里不容易被系统kill
|
|
|
+ mLocationUtils = LocationUtils.getInstance();
|
|
|
+ Log.i(TAG,"定位--------------------");
|
|
|
+ mLocationUtils.startLocationInfo();
|
|
|
+ mLocationUtils.onCreate(new LocationUtils.LocationListener() {
|
|
|
+ @Override
|
|
|
+ public void locationSuccess(MapLocationInfo mapLocationInfo, String message) {
|
|
|
+ mMapLocationInfo = mapLocationInfo;
|
|
|
+ Log.i("定位: ","" + message);
|
|
|
+ Log.i(TAG,"定位ok");
|
|
|
+ Log.i(TAG,mMapLocationInfo.toString());
|
|
|
+ Log.i(TAG,"纬度"+mMapLocationInfo.getLatitude()+"经度"+mMapLocationInfo.getLongitude());
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void locationFail(String message) {
|
|
|
+ Log.i("定位: ","" + message);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mLocationUtils.stopLocationClient();
|
|
|
+ }
|
|
|
+ },5000);
|
|
|
|
|
|
MainViewModel.context = getApplication();
|
|
|
SPUtils.getInstance().put("RunningState",0);//设备运行状态
|
| xqd
@@ -143,6 +172,9 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public ObservableField<String> textIMEI = new ObservableField<>();//imei显示
|
|
|
public ObservableField<String> textqueryCurrentData = new ObservableField<>();//电流过大查询显示
|
|
|
|
|
|
+// public void startLocation(){
|
|
|
+// mLocationUtils.startLocationInfo();
|
|
|
+// }
|
|
|
/*
|
|
|
* 按钮模拟指令
|
|
|
* */
|
| xqd
@@ -244,36 +276,50 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
SerialPortUtil.getInstance().getOtherDevice().closeLight3();
|
|
|
}
|
|
|
a++;
|
|
|
+// publishRepeat();
|
|
|
}
|
|
|
};
|
|
|
public View.OnClickListener btnClickOpenLight2 = new View.OnClickListener() {
|
|
|
//打开关闭灯2按钮
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
-// if(a%2==0){
|
|
|
-// SerialPortUtil.getInstance().getOtherDevice().openLight2();
|
|
|
-// }
|
|
|
-// else {
|
|
|
-// SerialPortUtil.getInstance().getOtherDevice().closeLight2();
|
|
|
-// }
|
|
|
-// a++;
|
|
|
- int hour=readTime();
|
|
|
- Log.i("当前时间hour是:",hour+"dian");
|
|
|
+ if(a%2==0){
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().openLight2();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().closeLight2();
|
|
|
+ }
|
|
|
+ a++;
|
|
|
}
|
|
|
};
|
|
|
public View.OnClickListener btnClickOpenLight1 = new View.OnClickListener() {
|
|
|
//打开关闭灯1按钮
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
- /* if(a%2==0){
|
|
|
+ if(a%2==0){
|
|
|
SerialPortUtil.getInstance().getOtherDevice().openLight1();
|
|
|
}
|
|
|
else {
|
|
|
SerialPortUtil.getInstance().getOtherDevice().closeLight1();
|
|
|
}
|
|
|
- a++;*/
|
|
|
-// reportDeviceEvent("haoge");
|
|
|
- SendSmsResponse("(测试123)");
|
|
|
+ a++;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ public View.OnClickListener btnClickSendMsg = new View.OnClickListener() {
|
|
|
+ //发送短信 事件测试
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ SendSmsResponse("(测试12355656)");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ public View.OnClickListener btnClickGetDeviceValue = new View.OnClickListener() {
|
|
|
+ //获取属性
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ int hour=readTime();
|
|
|
+ Log.i("当前时间hour是:",hour+"dian");
|
|
|
+// getDeviceProperty("1");
|
|
|
+ Log.i(TAG,"纬度"+mMapLocationInfo.getLatitude()+"经度"+mMapLocationInfo.getLongitude());
|
|
|
}
|
|
|
};
|
|
|
public View.OnClickListener btnClickreadWeight = new View.OnClickListener() {
|
| xqd
@@ -330,8 +376,20 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
System.out.println("btnClickrestartApp");
|
|
|
restartApp();//重启方法
|
|
|
}
|
|
|
- private Object getSystemService(String name) {
|
|
|
- return getApplication().getSystemService(name);
|
|
|
+ };
|
|
|
+ public View.OnClickListener btnClickrestartAndroid = new View.OnClickListener() {
|
|
|
+ //重启app
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ restartAndroid();//重启系统
|
|
|
+ }
|
|
|
+ };
|
|
|
+ public View.OnClickListener btnClickfinishApp = new View.OnClickListener() {
|
|
|
+ //关闭app
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ System.out.println("btnClickfinishApp");
|
|
|
+ System.exit(0);
|
|
|
}
|
|
|
};
|
|
|
public View.OnClickListener btnClickReport = new View.OnClickListener() {
|
| xqd
@@ -715,7 +773,13 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
if (topic.endsWith("thing/event/property/post_reply")){ //推送设备属性的回包。
|
|
|
}
|
|
|
if(topic.endsWith("thing/service/restartApp")){
|
|
|
- restartApp();
|
|
|
+ restartApp();//重启app
|
|
|
+ }
|
|
|
+ if(topic.endsWith("thing/service/finishApp")){
|
|
|
+ System.exit(0);//关闭app
|
|
|
+ }
|
|
|
+ if(topic.endsWith("thing/service/restartAndroidSystem")){
|
|
|
+ restartAndroid();//重启系统
|
|
|
}
|
|
|
if(topic.endsWith("thing/service/RemoteOpen")){// 云端开门的请求。
|
|
|
// SerialPortUtil.getInstance().getPushRodDevice().pushRod();
|
| xqd
@@ -1025,84 +1089,96 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
* 上报状态
|
|
|
*/
|
|
|
public void reportProperty() {
|
|
|
- Log.i(TAG,"上报数据");
|
|
|
- try{
|
|
|
- Integer weight = 0;
|
|
|
- Log.i("num=1","读一次称重");
|
|
|
- weight = SerialPortUtil.getInstance().getWeightDevice().readWeight();//读称重
|
|
|
- if(weight==1){
|
|
|
- weight = SerialPortUtil.getInstance().getWeightDevice().readWeight();//读称重
|
|
|
- }
|
|
|
+ Thread thread=new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ // publishRepeat();
|
|
|
+ Log.i(TAG,"上报数据");
|
|
|
+ try{
|
|
|
+ double longitude=107.31;
|
|
|
+ double latitude=23.16;
|
|
|
+ if(mMapLocationInfo!=null){
|
|
|
+ longitude=mMapLocationInfo.getLongitude();
|
|
|
+ latitude=mMapLocationInfo.getLatitude();
|
|
|
+ Log.i(TAG,mMapLocationInfo.toString()+"--地址:"+mMapLocationInfo.getAddress());
|
|
|
+
|
|
|
+ }
|
|
|
+ Integer weight = 0;
|
|
|
+ Log.i("num=1","读一次称重");
|
|
|
+ weight = SerialPortUtil.getInstance().getWeightDevice().readWeight();//读称重
|
|
|
+ if(weight==1){
|
|
|
+ weight = SerialPortUtil.getInstance().getWeightDevice().readWeight();//读称重
|
|
|
+ }
|
|
|
// weight=SerialPortUtil.getInstance().getOtherDevice().readWeight();//称重
|
|
|
- Integer capacity=0;
|
|
|
- capacity=SerialPortUtil.getInstance().getOtherDevice().getDistance();//超声波距离
|
|
|
- if(capacity==0){
|
|
|
- capacity=SerialPortUtil.getInstance().getOtherDevice().getDistance();//超声波距离
|
|
|
- }
|
|
|
- Integer magDoorSwitch=0;
|
|
|
- magDoorSwitch=SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();//门磁
|
|
|
- Integer currentTemperature=0;
|
|
|
- currentTemperature=SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
- if(currentTemperature==0){
|
|
|
- currentTemperature=SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
- }
|
|
|
- Log.i(TAG,"----------------------------------------");
|
|
|
+ Integer capacity=0;
|
|
|
+ capacity=SerialPortUtil.getInstance().getOtherDevice().getDistance();//超声波距离
|
|
|
+ if(capacity==0){
|
|
|
+ capacity=SerialPortUtil.getInstance().getOtherDevice().getDistance();//超声波距离
|
|
|
+ }
|
|
|
+ Integer magDoorSwitch=0;
|
|
|
+ magDoorSwitch=SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();//门磁
|
|
|
+ Integer currentTemperature=0;
|
|
|
+ currentTemperature=SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
+ if(currentTemperature==0){
|
|
|
+ currentTemperature=SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
+ }
|
|
|
+ Log.i(TAG,"----------------------------------------");
|
|
|
|
|
|
- Map<String, ValueWrapper> locationMap = new HashMap<>();
|
|
|
- Map<String, ValueWrapper> reportData = new HashMap<>();
|
|
|
+ Map<String, ValueWrapper> locationMap = new HashMap<>();
|
|
|
+ Map<String, ValueWrapper> reportData = new HashMap<>();
|
|
|
// SPUtils.getInstance().put("RodNumber","4721");
|
|
|
- String rodNumberStr= SPUtils.getInstance().getString("RodNumber");
|
|
|
- if(rodNumberStr.equals("")){
|
|
|
- rodNumberStr="0";
|
|
|
- }
|
|
|
- int rodNumberInt=Integer.parseInt(rodNumberStr);
|
|
|
- String rodSwitchStr=SPUtils.getInstance().getString("RodSwitch");
|
|
|
- if(rodSwitchStr.equals("")){
|
|
|
- rodSwitchStr="0";
|
|
|
- }
|
|
|
- int rodSwitchInt=Integer.parseInt(rodSwitchStr);
|
|
|
+ String rodNumberStr= SPUtils.getInstance().getString("RodNumber");
|
|
|
+ if(rodNumberStr.equals("")){
|
|
|
+ rodNumberStr="0";
|
|
|
+ }
|
|
|
+ int rodNumberInt=Integer.parseInt(rodNumberStr);
|
|
|
+ String rodSwitchStr=SPUtils.getInstance().getString("RodSwitch");
|
|
|
+ if(rodSwitchStr.equals("")){
|
|
|
+ rodSwitchStr="0";
|
|
|
+ }
|
|
|
+ int rodSwitchInt=Integer.parseInt(rodSwitchStr);
|
|
|
// SPUtils.getInstance().put("LockNumber","7562");
|
|
|
- String lockNumberStr=SPUtils.getInstance().getString("LockNumber");
|
|
|
- if(lockNumberStr.equals("")){
|
|
|
- lockNumberStr="0";
|
|
|
- }
|
|
|
- int lockNumberInt=Integer.parseInt(lockNumberStr);
|
|
|
+ String lockNumberStr=SPUtils.getInstance().getString("LockNumber");
|
|
|
+ if(lockNumberStr.equals("")){
|
|
|
+ lockNumberStr="0";
|
|
|
+ }
|
|
|
+ int lockNumberInt=Integer.parseInt(lockNumberStr);
|
|
|
|
|
|
- int runningStateInt=SPUtils.getInstance().getInt("RunningState");
|
|
|
- reportData.put("RodOpenNum",new ValueWrapper.IntValueWrapper(rodNumberInt));
|
|
|
- reportData.put("LockOpenNum",new ValueWrapper.IntValueWrapper(lockNumberInt));
|
|
|
+ int runningStateInt=SPUtils.getInstance().getInt("RunningState");
|
|
|
+ reportData.put("RodOpenNum",new ValueWrapper.IntValueWrapper(rodNumberInt));
|
|
|
+ reportData.put("LockOpenNum",new ValueWrapper.IntValueWrapper(lockNumberInt));
|
|
|
|
|
|
- reportData.put("Weight", new ValueWrapper.IntValueWrapper(weight)); //重量 单位 --- 克
|
|
|
- reportData.put("CurrentTemperature", new ValueWrapper.IntValueWrapper(currentTemperature));//温度,范围正负 ,精确到小数点后2位
|
|
|
- reportData.put("RestCapacity", new ValueWrapper.IntValueWrapper(capacity)); //距离值,单位mm
|
|
|
- reportData.put("MagDoorSwitch", new ValueWrapper.BooleanValueWrapper(magDoorSwitch));//门磁 0-关闭状态 1-开门状态
|
|
|
+ reportData.put("Weight", new ValueWrapper.IntValueWrapper(weight)); //重量 单位 --- 克
|
|
|
+ reportData.put("CurrentTemperature", new ValueWrapper.IntValueWrapper(currentTemperature));//温度,范围正负 ,精确到小数点后2位
|
|
|
+ reportData.put("RestCapacity", new ValueWrapper.IntValueWrapper(capacity)); //距离值,单位mm
|
|
|
+ reportData.put("MagDoorSwitch", new ValueWrapper.BooleanValueWrapper(magDoorSwitch));//门磁 0-关闭状态 1-开门状态
|
|
|
|
|
|
- reportData.put("LockSwitch", new ValueWrapper.BooleanValueWrapper(lockSwitch)); //锁开关状态:0-关锁 1-解锁 解锁后3s就关锁
|
|
|
- reportData.put("RodSwitch", new ValueWrapper.BooleanValueWrapper(rodSwitchInt)); //推杆状态:0-关闭状态 1-打开 开门
|
|
|
+ reportData.put("LockSwitch", new ValueWrapper.BooleanValueWrapper(lockSwitch)); //锁开关状态:0-关锁 1-解锁 解锁后3s就关锁
|
|
|
+ reportData.put("RodSwitch", new ValueWrapper.BooleanValueWrapper(rodSwitchInt)); //推杆状态:0-关闭状态 1-打开 开门
|
|
|
|
|
|
- reportData.put("RunningState", new ValueWrapper.BooleanValueWrapper(runningStateInt)); // 0正常
|
|
|
+ reportData.put("RunningState", new ValueWrapper.BooleanValueWrapper(runningStateInt)); // 0正常
|
|
|
// 1设备故障 未识别到称重设备 报警 未识别到杆、门磁、锁、温度、红外、超声波设备 报警
|
|
|
// 2温度过高 报警
|
|
|
// 3收运门意外打开报警
|
|
|
// 4称重失灵报警 错误一次就再读一次 超过两次读取错误就报警
|
|
|
// 5温度和超声波失灵警告 失灵显示的000000000
|
|
|
|
|
|
- System.out.println(IMEI+"DeviceId");
|
|
|
- reportData.put("IMEI", new ValueWrapper.StringValueWrapper(IMEI));
|
|
|
- locationMap.put("longitude", new ValueWrapper.DoubleValueWrapper(107.31));
|
|
|
- locationMap.put("latitude", new ValueWrapper.DoubleValueWrapper(23.16));
|
|
|
- locationMap.put("altitude", new ValueWrapper.DoubleValueWrapper(523.1));
|
|
|
- reportData.put("GeoLocation", new ValueWrapper.StructValueWrapper(locationMap)); //
|
|
|
-
|
|
|
- int queryCurrent=SPUtils.getInstance().getInt("queryCurrent");
|
|
|
- Log.i(TAG, "称重" + weight.toString() + "距离" + capacity.toString() + "温度" + currentTemperature);
|
|
|
- textReportData.set("称重 " + weight.toString() + ";距离 " + capacity.toString() + "mm;温度 " +
|
|
|
- currentTemperature+"度;门磁 "+magDoorSwitch+";杆状态 "+rodSwitchInt+";锁状态 "+lockSwitch+";杆开门次数 "+rodNumberInt+";开锁次数 "+lockNumberInt+";被夹次数"+queryCurrent
|
|
|
- );
|
|
|
-
|
|
|
- String text = "称重 " + weight.toString() + ";距离 " + capacity.toString() + "mm;温度 " + currentTemperature+"度;门磁 "+magDoorSwitch+";杆状态 "+
|
|
|
- rodSwitchInt+";锁状态 "+lockSwitch+";杆开门次数 "+rodNumberInt+";开锁次数 "+lockNumberInt+";被夹次数"+queryCurrent+"------------------------------";
|
|
|
- Log.i(TAG, text + "=textReportData---------------------");
|
|
|
+ System.out.println(IMEI+"DeviceId");
|
|
|
+ reportData.put("IMEI", new ValueWrapper.StringValueWrapper(IMEI));
|
|
|
+ locationMap.put("longitude", new ValueWrapper.DoubleValueWrapper(longitude));
|
|
|
+ locationMap.put("latitude", new ValueWrapper.DoubleValueWrapper(latitude));
|
|
|
+ locationMap.put("altitude", new ValueWrapper.DoubleValueWrapper(523.1));
|
|
|
+ reportData.put("GeoLocation", new ValueWrapper.StructValueWrapper(locationMap)); //
|
|
|
+
|
|
|
+ int queryCurrent=SPUtils.getInstance().getInt("queryCurrent");
|
|
|
+ Log.i(TAG, "称重" + weight.toString() + "距离" + capacity.toString() + "温度" + currentTemperature);
|
|
|
+ textReportData.set("称重 " + weight.toString() + ";距离 " + capacity.toString() + "mm;温度 " +
|
|
|
+ currentTemperature+"度;门磁 "+magDoorSwitch+";杆状态 "+rodSwitchInt+";锁状态 "+lockSwitch+";杆开门次数 "+rodNumberInt+";开锁次数 "+lockNumberInt+";被夹次数"+queryCurrent+";运行状态"+runningStateInt
|
|
|
+ );
|
|
|
+
|
|
|
+ String text = "称重 " + weight.toString() + ";距离 " + capacity.toString() + "mm;温度 " + currentTemperature+"度;门磁 "+magDoorSwitch+";杆状态 "+
|
|
|
+ rodSwitchInt+";锁状态 "+lockSwitch+";杆开门次数 "+rodNumberInt+";开锁次数 "+lockNumberInt+";被夹次数"+queryCurrent+"------------------------------";
|
|
|
+ Log.i(TAG, text + "=textReportData---------------------");
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
| xqd
@@ -1123,6 +1199,11 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ thread.start();
|
|
|
+
|
|
|
}
|
|
|
/*
|
|
|
* 上报给蓝牙的数据格式
|
| xqd
@@ -1255,35 +1336,50 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
return reportData.toString();
|
|
|
}
|
|
|
//设备事件上报
|
|
|
- public static void reportDeviceEvent(String identifier){
|
|
|
- HashMap<String, ValueWrapper> hashMap = new HashMap<>();
|
|
|
+ public static void reportDeviceEvent(String identifier, String event, int num){
|
|
|
+ /* HashMap<String, ValueWrapper> hashMap = new HashMap<>();
|
|
|
// TODO 用户根据实际情况设置
|
|
|
// hashMap.put("ErrorCode", new ValueWrapper.IntValueWrapper(0));
|
|
|
- hashMap.put("ErrorCode",new ValueWrapper.IntValueWrapper(3));
|
|
|
-// hashMap.put("event",identifier);
|
|
|
+ if(num==1){
|
|
|
+ hashMap.put("warnEvent",new ValueWrapper.StringValueWrapper(event));
|
|
|
+ }else if(num==2){
|
|
|
+ hashMap.put("errorEvent",new ValueWrapper.StringValueWrapper(event));
|
|
|
+ }
|
|
|
OutputParams params = new OutputParams(hashMap);
|
|
|
Log.i("设备故障",identifier+"====="+params);
|
|
|
-// int networkInfo=netWorkInfo();
|
|
|
|
|
|
-// if(netWorkInfo!=0){
|
|
|
-//
|
|
|
-// }
|
|
|
-// LinkKit.getInstance().getDeviceThing().thingEventPost(identifier, params, new IPublishResourceListener() {
|
|
|
-// @Override
|
|
|
-// public void onSuccess(String resId, Object o) { // 事件上报成功
|
|
|
-// Log.i("事件上报","上报成功");
|
|
|
-// }
|
|
|
-// @Override
|
|
|
-// public void onError(String resId, AError aError) { // 事件上报失败
|
|
|
-// Log.i("事件上报","上报失败");
|
|
|
-// }
|
|
|
-// });
|
|
|
+ LinkKit.getInstance().getDeviceThing().thingEventPost(identifier, params, new IPublishResourceListener() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String resId, Object o) { // 事件上报成功
|
|
|
+ Log.i("事件上报","上报成功");
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onError(String resId, AError aError) { // 事件上报失败
|
|
|
+ Log.i("事件上报","上报失败");
|
|
|
+ }
|
|
|
+ });*/
|
|
|
}
|
|
|
private void getDeviceProperty(String identifier){
|
|
|
// 根据 identifier 获取当前物模型中该属性的值
|
|
|
- LinkKit.getInstance().getDeviceThing().getPropertyValue(identifier);
|
|
|
+
|
|
|
+ Log.i("获取属性","-----------------------");
|
|
|
+ Log.i("获取属性",""+LinkKit.getInstance().getDeviceThing().getPropertyValue("Weight"));
|
|
|
+ Log.i("获取属性",""+LinkKit.getInstance().getDeviceThing());
|
|
|
+ Log.i("获取属性",""+LinkKit.getInstance().getDeviceThing().toString());
|
|
|
+ Log.i("获取属性",""+LinkKit.getInstance().getDeviceThing().getPropertyValue("Weight").getValue());
|
|
|
+ ValueWrapper.IntValueWrapper weight= (ValueWrapper.IntValueWrapper) LinkKit.getInstance().getDeviceThing().getPropertyValue("Weight");
|
|
|
+ Log.i("获取属性",""+weight.getValue());
|
|
|
// 获取所有属性
|
|
|
- LinkKit.getInstance().getDeviceThing().getProperties();
|
|
|
+// LinkKit.getInstance().getDeviceThing().getProperties();
|
|
|
+ for(int i=0;i<LinkKit.getInstance().getDeviceThing().getProperties().size();i++){
|
|
|
+ Log.i("全部属性---------",""+LinkKit.getInstance().getDeviceThing().getProperties().get(i).getName());
|
|
|
+ Log.i("全部属性---------",""+LinkKit.getInstance().getDeviceThing().getProperties().get(i).getAccessMode());
|
|
|
+ Log.i("全部属性---------",""+LinkKit.getInstance().getDeviceThing().getProperties().get(i).getDesc());
|
|
|
+ Log.i("全部属性---------",""+LinkKit.getInstance().getDeviceThing().getProperties().get(i).getIdentifier());
|
|
|
+ Log.i("全部属性---------",""+LinkKit.getInstance().getDeviceThing().getProperties().get(i).getDataType());
|
|
|
+ }
|
|
|
+ Log.i("全部属性---------",""+LinkKit.getInstance().getDeviceThing().getProperties());
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public void registerAliIoTListener(){
|
| xqd
@@ -1394,9 +1490,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
publishRequest.topic = "/a13H8L6bDyf/device2/user/checkOnlineStatus";
|
|
|
publishRequest.payloadObj = "{\"id\":"+ publishRequest.msgId+", \"version\":\"1.0\",\"time\":" + System.currentTimeMillis() + "}";
|
|
|
Integer networkInt=netWorkInfo();
|
|
|
-
|
|
|
Log.i(TAG,"network网络"+networkInt);
|
|
|
-
|
|
|
LinkKit.getInstance().publish(publishRequest, new IConnectSendListener() {
|
|
|
@Override
|
|
|
public void onResponse(ARequest aRequest, AResponse aResponse) {
|
| xqd
@@ -1912,31 +2006,40 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
|
|
|
System.exit(0);
|
|
|
}
|
|
|
-
|
|
|
+ public void restartAndroid(){
|
|
|
+ //获取root权限,前提是设备已经root过
|
|
|
+ try {
|
|
|
+ Process process = Runtime.getRuntime().exec("su");
|
|
|
+ //执行重启命令
|
|
|
+ Runtime.getRuntime().exec("su -c reboot");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
private Object getSystemService(String name) {
|
|
|
return getApplication().getSystemService(name);
|
|
|
}
|
|
|
|
|
|
public void repeatTask() {
|
|
|
Log.i("----------------------","ok");
|
|
|
- task3 =new TimerTask(){
|
|
|
- public void run(){
|
|
|
- publishRepeat();
|
|
|
- Log.i("Task","300秒循环");
|
|
|
- }
|
|
|
- };
|
|
|
- timer.schedule(task3,60000,300000);
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTimeInMillis(System.currentTimeMillis());
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 11);
|
|
|
- calendar.set(Calendar.MINUTE, 26);
|
|
|
- task2=new TimerTask() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- openLight();
|
|
|
- }
|
|
|
- };
|
|
|
- timer.schedule(task2,0,1800000);
|
|
|
+// task3 =new TimerTask(){
|
|
|
+// public void run(){
|
|
|
+// publishRepeat();
|
|
|
+// Log.i("Task","300秒循环");
|
|
|
+// }
|
|
|
+// };
|
|
|
+// timer.schedule(task3,60000,600000);
|
|
|
+// Calendar calendar = Calendar.getInstance();
|
|
|
+// calendar.setTimeInMillis(System.currentTimeMillis());
|
|
|
+// calendar.set(Calendar.HOUR_OF_DAY, 11);
|
|
|
+// calendar.set(Calendar.MINUTE, 26);
|
|
|
+// task2=new TimerTask() {
|
|
|
+// @Override
|
|
|
+// public void run() {
|
|
|
+// openLight();
|
|
|
+// }
|
|
|
+// };
|
|
|
+// timer.schedule(task2,0,1800000);
|
|
|
|
|
|
task1=new TimerTask() {
|
|
|
@Override
|
| xqd
@@ -1944,7 +2047,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
publish();
|
|
|
}
|
|
|
};
|
|
|
- timer.schedule(task1,600000,600000);
|
|
|
+ timer.schedule(task1,600000,1800000);
|
|
|
}
|
|
|
private void publishRepeat(){
|
|
|
Integer currentTemperature= SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
| xqd
@@ -1955,37 +2058,30 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
SPUtils.getInstance().put("queryCurrent",num+1);//记录被夹次数
|
|
|
SerialPortUtil.getInstance().getOtherDevice().clearCurrent();
|
|
|
}
|
|
|
- if(currentTemperature>90){
|
|
|
+ if(currentTemperature>60){
|
|
|
SPUtils.getInstance().put("RunningState",2);//温度过高
|
|
|
Log.i(TAG,"温度过高");
|
|
|
Integer networkInt=netWorkInfo();
|
|
|
if(networkInt!=0){
|
|
|
- reportProperty();
|
|
|
+// reportProperty();
|
|
|
//短信通知
|
|
|
SendSmsResponse("温度过高");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- if(currentTemperature>40){
|
|
|
-// SerialPortUtil.getInstance().getOtherDevice().openuFan();//打开分钟
|
|
|
+ if(currentTemperature>25){
|
|
|
+// SerialPortUtil.getInstance().getOtherDevice().openuFan();//打开风扇
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().openLight4();
|
|
|
}else{
|
|
|
- // SerialPortUtil.getInstance().getOtherDevice().closeFan();//打开分钟
|
|
|
+ // SerialPortUtil.getInstance().getOtherDevice().closeFan();//打开风扇
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().closeLight4();
|
|
|
}
|
|
|
|
|
|
if(magDoorSwitch==1){
|
|
|
if(SPUtils.getInstance().getString("magDoorSwitch").equals("0")){
|
|
|
SPUtils.getInstance().put("RunningState",3);
|
|
|
Log.i(TAG,"收运门意外打开");
|
|
|
- Integer networkInt=netWorkInfo();
|
|
|
- /* if(networkInt!=0){
|
|
|
- reportProperty();
|
|
|
- //短信通知
|
|
|
- try {
|
|
|
- SendSmsResponse("收运门意外打开");
|
|
|
- } catch (ClientException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }*/
|
|
|
+ SendSmsResponse("收运门意外打开");
|
|
|
}
|
|
|
}
|
|
|
// if(currentTemperature<100&magDoorSwitch==0) {
|
| xqd
@@ -2004,18 +2100,26 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
|
|
|
public void openLight(){
|
|
|
Log.i("d定时","ok");
|
|
|
- if(readTime()>19||readTime()<1){
|
|
|
+ if(readTime()>18||readTime()<1){
|
|
|
Log.i("night","开灯");
|
|
|
-// SerialPortUtil.getInstance().getOtherDevice().openLight1();
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().openLight4();
|
|
|
}else {
|
|
|
Log.i("day","关灯");
|
|
|
-// SerialPortUtil.getInstance().getOtherDevice().closeLight1();
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().closeLight4();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public static void SendSmsResponse(String event){
|
|
|
- Log.i("短信","发送"+event);
|
|
|
+ if(event.equals("温度超声波失灵")){
|
|
|
+ reportDeviceEvent("errorEvent","温度超声波失灵",2);
|
|
|
+ Log.i("警告","发送"+event);
|
|
|
+ }else {
|
|
|
+ reportDeviceEvent("warnEvent",event,1);
|
|
|
+ Log.i("报警","发送"+event);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/*DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4FcFSGUX9ngzehwMMU6M", "SxG0xU9U7bqpCDoK0nMGo4pSXAdNHc");
|
|
|
IAcsClient client = new DefaultAcsClient(profile);
|
|
|
CommonRequest request = new CommonRequest();
|
| xqd
@@ -2038,10 +2142,10 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
} catch (ClientException e) {
|
|
|
e.printStackTrace();
|
|
|
}*/
|
|
|
- /*try {
|
|
|
+ /* try {
|
|
|
Response response = OkHttpUtils.post()
|
|
|
- .url("")
|
|
|
- .addParams("event", event)
|
|
|
+ .url("/api/v1/sendMessage/send")
|
|
|
+ .addParams("code", event)
|
|
|
.build().execute();
|
|
|
if (response.isSuccessful()) {
|
|
|
String jsonStr = response.body().string();
|