Skip to content

Commit

Permalink
✨ Release.2.2.284,2.2版本,正常启动上线,预留调试API入口
Browse files Browse the repository at this point in the history
  • Loading branch information
Hny0305Lin committed Aug 15, 2022
1 parent ce08b83 commit e490f2c
Show file tree
Hide file tree
Showing 30 changed files with 566 additions and 53 deletions.
5 changes: 5 additions & 0 deletions HaohanyhHAMOSProjectY Android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions HaohanyhHAMOSProjectY Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ android {
minSdk 26
targetSdk 32
versionCode 1
//灰度测试偷跑2.1版本第8次测试
versionName "Alpha.2.1.8.2022.0728.Haohanyh.Comet"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -32,7 +30,7 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.10.0'

implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation project(path: ':app:huawei')
testImplementation 'junit:junit:4.+'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

public class Data {
//华为云IAM账号
private final String JsonDomainName = "";
private final String JsonName = "";
private final String JsonPassword = "";
private static final String JsonDomainName = "";
private static final String JsonName = "";
private static final String JsonPassword = "";
//重构,让其他类获取Data类的数据
public String getJsonDomainName() { return JsonDomainName; }
public String getJsonName() { return JsonName; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import android.util.Log;

import androidx.annotation.NonNull;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -104,8 +106,8 @@ public void CreateJsonToKnowDomainidneedpose(String json) {
/*
* 创建JSON转String,方便ControlSenderneedpost()函数(CreateCommand 下发设备命令),进行使用和理解。
*/
public void CreateJsonToControlSenderneedpost(String project_id,String device_id,String service_id,String command_name,String command_param,String command_value) {
String jsonParas = "";
public void CreateJsonToControlSenderneedpost(String service_id,String command_name,String command_param,String command_value) {
String jsonParas;
JSONObject object = new JSONObject();
try {
JSONObject jsonObject = new JSONObject();
Expand All @@ -114,7 +116,7 @@ public void CreateJsonToControlSenderneedpost(String project_id,String device_id
object.put(command_param, command_value);
jsonObject.put("paras", object);
jsonParas = jsonObject.toString();
ControlSenderneedpost(jsonParas,project_id,device_id);
ControlSenderneedpost(jsonParas);
} catch (JSONException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -342,24 +344,26 @@ public boolean HaohanyhOranMeCDNDecideData(String Url, String S_data_device_id,
* 护花使者:采用E53-IA1,MotorStatus
* 小熊派:(E53-IA1 MotorStatus、LightStatus)(E53-ST1 BeepStatus)(E53_SC1 LightStatus)
*/
public void ControlSenderneedpost(String json,String project_id,String device_id) {
public void ControlSenderneedpost(String json) {
Knowtokenneedpost();
String url = "https://iotda.cn-north-4.myhuaweicloud.com/v5/iot/" + GetHuawei().getProject_id() + "/devices/" + GetHuawei().getDevice_info() + "/commands";
RequestBody body = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), json);
Request request = new Request.Builder()
.url("https://iotda.cn-north-4.myhuaweicloud.com/v5/iot/" + project_id + "/devices/" + device_id + "/commands")
.url(url)
.addHeader("X-Auth-Token",HUAWEITOKEN)
.post(body)
.build();

OkHttpClient mOkHttpClient = new OkHttpClient();
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
public void onFailure(@NonNull Call call, @NonNull IOException e) {
Log.e("ControlSenderneedpost,Failed",e.getLocalizedMessage() + ",失败");
}

@Override
public void onResponse(Call call, Response response) throws IOException {
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
Log.i("ControlSenderneedpost,Finished","函数链接: " + Objects.requireNonNull(response.body()).string());
Log.v("浩瀚银河:", "真正浇花中!");
}
});
}
Expand Down Expand Up @@ -424,12 +428,12 @@ public void ResetSecretneedpost() {
OkHttpClient mOkHttpClient = new OkHttpClient();
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
public void onFailure(@NonNull Call call, @NonNull IOException e) {
Log.e("ResetSecretneedpost,Failed",e.getLocalizedMessage() + ",失败");
}

@Override
public void onResponse(Call call, Response response) throws IOException {
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
if(response.code() == 200){
//反正每次都是200,索性不看Log了
//Log.i("OK","code=200,才算成功");
Expand Down
16 changes: 12 additions & 4 deletions HaohanyhHAMOSProjectY Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.haohanyh.hamos.projecty">
package="com.haohanyh.hamos.projecty"
android:versionName="@string/app_version">
<!--MainActivity和HAMOSActivity需求权限-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!--MainActivity 2.2正常启动获取Wi-Fi名称需求权限-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!--NFCActivity需求权限-->
<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.haohanyh.hamos.arithmetic;

public class StringUtils {//字符串处理算法

//下面老三样了,建议是不要动
protected StringUtils() { }
public static StringUtils GetData() { return Stringshuju.Stringshuju; }
protected static class Stringshuju { private static final StringUtils Stringshuju = new StringUtils(); }

//2.2判断华为云账号所使用
private final String HuaweiSmallLetter = "abcdefghijklmnopqrstuvwxyz";
private final String NormalCharacter = "`~!@#$%^&*()-_=+[{}]|\\:;\"',<.>/?";
public String getHuaweiSmallLetter() { return HuaweiSmallLetter; }
public String getNormalCharacter() { return NormalCharacter; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class Data {
private final String WPA_address = "";
private final String WPA_pwd = "";

//重构,让其他类获取Data类的数据
public String getWPA_address() { return WPA_address; }
public String getWPA_pwd() { return WPA_pwd; }

//下面老三样了,建议是不要动
protected Data() { }
public static Data GetData() { return data.shuju; }
protected static class data { private static final Data shuju = new Data(); }

//2.1更新,重写构造函数
public String getWPA_pwd() { return WPA_pwd; }
public String getWPA_address() { return WPA_address; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.haohanyh.hamos.networkAPI;

public class AKeystoneCreateUserTokenByPassword {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.haohanyh.hamos.networkAPI;

public class BKeystoneListProjects {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.haohanyh.hamos.networkAPI;

public class CCreateProduct {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.haohanyh.hamos.networkAPI;

public class DAddDevice {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.haohanyh.hamos.networkAPI;

public class EListDevices {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.haohanyh.hamos.networkAPI;

public class FResetDeviceSecret {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.haohanyh.hamos.networkAPI;

public class GShowDeviceShadow {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.haohanyh.hamos.networkAPI;

public class HCreateCommand {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.haohanyh.hamos.networkAPI;

public class IHaohanyh_OranMeCDN_ListDevices {
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void GoToNFCSetting(final Context context) {
if (alertDialog == null) {
Log.v("浩瀚银河:", "弹窗提醒前往设置NFC: " + "成功");
alertDialog = new AlertDialog.Builder(context)
.setTitle("Haohanyh-ProjectY-NFC")
.setTitle("Haohanyh HAMOS ProjectY,需要NFC功能")
.setMessage("当前应用需要您开启NFC,是否立即去设置界面开启?")
.setPositiveButton("去设置", new DialogInterface.OnClickListener() {
@SuppressLint("ObsoleteSdkInt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public class HAMOSActivity extends Activity {
//进程类,继承父类Threads
public HuhuaThread huhua;
public WaterControlThread water;
//2.0版本,我们在彻底摆脱部分数据填写,这三个项目ID硬件ID什么的,慢慢的我们可以不用手动填写了。
private String project_id = GetHuawei().getProject_id();
private String device_id = GetHuawei().getDevice_info();
//服务ID、命令名字、命令服务名、命令属性(也就是上报值),后面的链接是在线调试,可以帮助你得到这些变量。
//(配置好你的板子的过程,也配置了这些,如果忘记了但不想重新创建设备,就这么找吧)
//https://console.huaweicloud.com/iotdm/?region=cn-north-4#/dm-portal/monitor/online-debugger
Expand All @@ -57,15 +54,15 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
Init();
Toast.makeText(HAMOSActivity.this,"您现在可以关闭NFC且重启小熊派开发板了",Toast.LENGTH_SHORT).show();

TimerTask task = new TimerTask() {
@Override
public void run() {
count++;
Log.v("浩瀚银河HAMOS运行计时:", String.valueOf(count));
if(count == 3) { Log.v("浩瀚银河:", "护花使者即将开始采集数据"); }
if(count >= 4) { HuHuaStart(); }
if(count >= 5) { WaterStart(); }
if(count >= 6) { Log.v("浩瀚银河:", "护花使者,正式开始!"); }
if(count >= 4) { WaterStart(); }
if(count >= 12 && count % 3 == 2) { HuHuaStart(); }
}
};
newtimer.schedule(task,300,1000);
Expand Down Expand Up @@ -101,7 +98,7 @@ public class HuhuaThread extends Thread {
* 自动跑,不用理它,我基本上帮你们写好了这些了。
*/
public void run() {
String result = GetHuawei().Knowdeviceneedget("https://iotda.cn-north-4.myhuaweicloud.com/v5/iot/" + project_id + "/devices/" + device_id + "/shadow");
String result = GetHuawei().Knowdeviceneedget("https://iotda.cn-north-4.myhuaweicloud.com/v5/iot/" + GetHuawei().getProject_id() + "/devices/" + GetHuawei().getDevice_info() + "/shadow");
//我们把从华为云,通过get函数查询到的设备数据,做数据显示和浇花控制。
DataChangeShow(result);
}
Expand Down Expand Up @@ -184,7 +181,6 @@ public void onClick(View view) {
command_value = "ON";
Toast.makeText(HAMOSActivity.this, "浇花中", Toast.LENGTH_SHORT).show();
WaterSomeFlower();
Toast.makeText(HAMOSActivity.this, "浇花完成", Toast.LENGTH_SHORT).show();
}
});
}
Expand All @@ -194,7 +190,10 @@ public void onClick(View view) {
*/
private void WaterSomeFlower() {
//请保证6个东西你都填写了再执行该函数~
GetHuawei().CreateJsonToControlSenderneedpost(project_id,device_id,service_id,command_name,command_param,command_value);
GetHuawei().CreateJsonToControlSenderneedpost(service_id,command_name,command_param,command_value);
Log.v("浩瀚银河:", "浇花中!");
}
}


}
Loading

0 comments on commit e490f2c

Please sign in to comment.