-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 Release.2.2.441,2.2版本,OKHttp3库更新,新增保存传感器数据
- Loading branch information
1 parent
2a911b9
commit 67fd958
Showing
16 changed files
with
188 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...HAMOSProjectY Android/app/src/main/java/com/haohanyh/hamos/managedata/SaveSensorData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.haohanyh.hamos.managedata; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.util.Log; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.RandomAccessFile; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class SaveSensorData { | ||
//浩瀚银河此类保存用户如下信息: | ||
/* 5. 使用者的护花使者的传感器信息、电机开关情况、传感器信息时间、华为云提交次数 | ||
* (内容为附近温度、空气湿度和土壤湿度) | ||
*/ | ||
private static final String TAG = "浩瀚银河保存传感器文件:"; | ||
int count = 0; | ||
private String Dir = null; | ||
public void setDir(String dir) { Dir = dir; } | ||
private String temp = null;//附近温度 | ||
private String humi = null;//空气湿度 | ||
private String soil = null;//土壤湿度 | ||
private String time = null;//信息时间 | ||
private String num = null;//提交次数 | ||
|
||
public SaveSensorData() {}; | ||
public static SaveSensorData NeedSaveData() { return SaveSensorData.savedata.thing; } | ||
protected static class savedata { private static final SaveSensorData thing = new SaveSensorData(); } | ||
//HAMOSActivity写入值,用于保存 | ||
public void setTemp(String temp) { this.temp = temp; } | ||
public void setHumi(String humi) { this.humi = humi; } | ||
public void setSoil(String soil) { this.soil = soil; } | ||
public void setTime(String time) { this.time = time; } | ||
public void setNum(String num) { this.num = num; } | ||
|
||
/* 通过华为云API该页面:https://apiexplorer.developer.huaweicloud.com/apiexplorer/doc?product=IoTDA&api=ShowDeviceShadow | ||
* 我们可以得知:properties为设备影子的属性数据,event_time为事件操作时间。 | ||
* 华为云对event_time有格式规定:yyyyMMdd'T'HHmmss'Z',如20151212T121212Z。 | ||
* 那么我们可以举例:20220828T180036Z,为2022年8月28号18时00分36秒。 | ||
* 那么,String Stime,就能说明这里注释的一切~ | ||
*/ | ||
public String ProcessDataToWriteFile() { | ||
String Snum = "华为云IoTDA数据记录次数:" + num; | ||
String Stemp = "附近温度:" + temp; | ||
String Shumi = "空气湿度:" + humi; | ||
String Ssoil = "土壤湿度:" + soil; | ||
String Stime = "信息时间:" + time.substring(0,4) + "年" + time.substring(4,6) + "月" + time.substring(6,8) + "日" + time.substring(9,11) + "时" + time.substring(11,13) + "分" + time.substring(13,15) + "秒"; | ||
return Snum + "\t" + Stemp + "\t" + Shumi + "\t" + Ssoil + "\t" + Stime + "\n"; | ||
} | ||
|
||
/** | ||
* WriteFile(),保存文件到我们的一亩三分地里~不乱存 | ||
*/ | ||
@SuppressLint("SdCardPath") | ||
public void WriteFile() { | ||
Log.v(TAG,"开始"); | ||
try { | ||
File file = new File(Dir + "/HAMOSData"); | ||
if(!file.exists()) { file.mkdir(); }//判断目录是否存在,不存在就得创建 | ||
File file2 = new File(Dir + "/HAMOSData/Sensor"); | ||
if(!file2.exists()) { file2.mkdir(); }//判断目录是否存在,不存在就得创建 | ||
File newFile = new File(file2 + "/Sensor.txt"); | ||
if(!newFile.exists()) { newFile.createNewFile(); }//判断文件是否存在,不存在就得创建 | ||
//经过多次版本测试,我们终于得到了确切目录树: /storage/emulated/0/HAMOSData/Sensor/Sensor.txt | ||
String Path = Dir + "/HAMOSData/Sensor/Sensor.txt"; | ||
File targetFile = new File(Path); | ||
RandomAccessFile randomAccessFile = new RandomAccessFile(targetFile,"rw"); | ||
long fileLength = randomAccessFile.length();//神来之笔,我要知道这个JSON里面,存了多少字节了,就靠long fileLength! | ||
randomAccessFile.seek(fileLength); | ||
randomAccessFile.write(ProcessDataToWriteFile().getBytes(StandardCharsets.UTF_8));//写入我们保存的用户信息 | ||
randomAccessFile.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
count++; | ||
Log.v(TAG,"保存"+count+"次,数据于华为云IoTDA版本为" + num +",感谢您使用浩瀚银河2.2灰度测试功能!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+125 KB
HaohanyhHAMOSProjectY Android/app/src/main/res/drawable-nodpi/fuzhou2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions
49
HaohanyhHAMOSProjectY Android/app/src/main/res/layout/debugapi.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout 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:background="@drawable/fuzhou2" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@color/Pink_is_fancy" | ||
android:gravity="bottom|left" | ||
android:text="@string/haohanyh_hamos_lights_project" | ||
android:textColor="@color/white" | ||
android:textSize="24sp" | ||
android:textStyle="italic" | ||
tools:ignore="TextContrastCheck" /> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="60dp" | ||
android:background="@color/Pink_is_fancy" | ||
android:gravity="left|center" | ||
android:orientation="horizontal" | ||
tools:ignore="RtlHardcoded"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="40dp" | ||
android:gravity="center" | ||
android:text="@string/haohanyh_hamos_lights_project_manymain3" | ||
android:textColor="@color/black" | ||
android:textSize="18sp" /> | ||
|
||
</LinearLayout> | ||
|
||
<ScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" /> | ||
|
||
</ScrollView> | ||
|
||
</LinearLayout> |
3 changes: 2 additions & 1 deletion
3
HaohanyhHAMOSProjectY Android/app/src/main/res/values/strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.