README_zh.md

5.0基线代码获取

[基线代码获取]https://gitee.com/openharmony/docs/blob/master/zh-cn/release-notes/OpenHarmony-v5.0.0-release.md#源码获取

一. 动态库sdk的下载和编译

二. 本参考Demo的下载和编译

  1. 下载源码applications_sample_iot_connect_samples
  2. 将下载的applications_sample_iot_connect_samples文件夹拷贝到applications/sample文件夹
  3. 将applications_sample_iot_connect_samples文件夹改名iot_connect_samples
  4. 可参考yarward_iotc/digital_signage编写自己的demo,并将自己的demo添加到编译子系统中

三 添加编译子系统构建APP demo

以社区开源产品(rk3568)为例,其余产品可按实际位置自行修改

  1. 修改文件根目录下的BUILD.gn, 将自己想编译的demo目标添加到deps中
# 如编译wifi_ble_combo/yarward_iotc_iotc/digital_signage示例
group("iot_connect_samples") {
  if (iot_connect_samples_feature_appPath == "wifi_ble_combo/yarward_iotc/digital_signage") {
    deps = [ "$app_build_path:yarward_iotc_app" ]
  }
}
  1. 修改文件根目录下的bundle.json
# 如编译wifi_ble_combo/yarward_iotc_iotc/digital_signage示例
        "build": {
            "sub_component": [
                "//applications/sample/iot_connect_samples:iot_connect_samples",
                "//applications/sample/iot_connect_samples/wifi_ble_combo/yarward_iotc/digital_signage/etc/init:iot_connect_combo.cfg"
            ],
            "inner_kits": [],
            "test": []
        }
  1. 如编译wifi_ble_combo/yarward_iotc/digital_signage的示例,需iot_connect_samples_feature_appPath变量的值 vendor/hihope/rk3568/config.json 中添加
    "subsystem": "applications",
      "components": [
        {
          "component": "iot_connect_samples",
          "features": [
            "iot_connect_samples_feature_appPath = wifi_ble_combo/yarward_iotc/digital_signage"  #编译demo示例可选,可为空
          ]
        }
      ]
  1. productdefine/common/products/ohos-sdk.json
      "subsystem": "applications",
      "components": [
        { "component": "iot_connect_samples" },
        ...
      ]
  1. build/compile_standard_whitelist.json
    "third_deps_bundle_not_add": [
        "//applications/sample/iot_connect_samples:iot_connect_samples",
        ...
    ]
  1. 已解决编译程序无法自启动运行 需要在BUILD.gn文件中作如下修改 路径: applications/sample/iot_connect_samples/wifi_ble_combo/yarward_iotc/digital_signage/etc/init/BUILD.gn 修改如下内容

ohos_prebuilt_etc("iot_connect_combo.cfg") { source = "iot_connect_combo.cfg" relative_install_dir = "init" part_name = "iot_connect_samples" subsystem_name = "applications" }


对high_privilege_process_list.json文件增加如下内容 路径如下: vendor/hihope/rk3568/security_config/high_privilege_process_list.json

修改内容


    {
        "name": "yarward_iotc_app",
        "uid": "root",
        "gid": "root"
    }

修改selinux.gni文件,使编译出来的镜像不开启selinux 路径为: base/security/selinux_adapter/selinux.gni 修改内容


declare_args() { selinux_adapter_enforce = false }


四. DNS问题修复说明

找到resolvconf.c文件 路径: third_party/musl/src/network/resolvconf.c 在get_resolv_conf_ext函数中会有报错 DNS_CONFIG_PRINT("__get_resolv_conf OHOS_GET_CONFIG_FUNC_NAME err %d\n", ret); 再次行前面添加 goto etc_resolv_conf; 可修复无法DNS解析问题 修改完需要重新编译系统 修改后的代码如下


int get_resolv_conf_ext(struct resolvconf *conf, char *search, size_t search_sz, int netid) { char line[256]; unsigned char _buf[256]; FILE *f, _f; int nns = 0;

conf->ndots = 1;
conf->timeout = 5;
conf->attempts = 2;
if (search) *search = 0;

#if OHOS_DNS_PROXY_BY_NETSYS GetConfig func = load_config_getter(); if (!func) { DNS_CONFIG_PRINT("%s: loading %s failed, use %s as a fallback", func, OHOS_GET_CONFIG_FUNC_NAME, DNS_RESOLV_CONF_PATH); goto etc_resolv_conf; }

struct resolv_config config = {0};
int ret = func(netid, &config);
if (ret < 0) {
	goto etc_resolv_conf;
	DNS_CONFIG_PRINT("__get_resolv_conf OHOS_GET_CONFIG_FUNC_NAME err %d\n", ret);

#ifndef LITEOS MUSL_LOGE("%{public}s: %{public}d: resolv_config return: %{public}d for netid %{public}d", func, LINE, ret, netid); #endif return EAI_NONAME; } int32_t timeout_second = config.timeout_ms / 1000;

netsys_conf: if (timeout_second > 0) { if (timeout_second >= 60) { conf->timeout = 60; } else { conf->timeout = timeout_second; } } if (config.retry_count > 0) { if (config.retry_count >= 10) { conf->attempts = 10; } else { conf->attempts = config.retry_count; } } for (int i = 0; i < MAX_SERVER_NUM; ++i) { if (config.nameservers[i] == NULL || config.nameservers[i][0] == 0 || nns >= MAXNS) { continue; } if (__lookup_ipliteral(conf->ns + nns, config.nameservers[i], AF_UNSPEC) > 0) { nns++; } }

    if (nns != 0) {
        goto get_conf_ok;
    }

etc_resolv_conf: #endif f = __fopen_rb_ca(DNS_RESOLV_CONF_PATH, &_f, _buf, sizeof _buf); if (!f) switch (errno) { case ENOENT: case ENOTDIR: case EACCES: goto no_resolv_conf; default: #ifndef LITEOS MUSL_LOGE("%{public}s: %{public}d: open resolv.conf failed with Unexpected errno: %{public}d", func, LINE, errno); #endif return -1; }

while (fgets(line, sizeof line, f)) {
	char *p, *z;
	if (!strchr(line, '\n') && !feof(f)) {
		/* Ignore lines that get truncated rather than
		 * potentially misinterpreting them. */
		int c;
		do c = getc(f);
		while (c != '\n' && c != EOF);
		continue;
	}
	if (!strncmp(line, "options", 7) && isspace(line[7])) {
		p = strstr(line, "ndots:");
		if (p && isdigit(p[6])) {
			p += 6;
			unsigned long x = strtoul(p, &z, 10);
			if (z != p) conf->ndots = x > 15 ? 15 : x;
		}
		p = strstr(line, "attempts:");
		if (p && isdigit(p[9])) {
			p += 9;
			unsigned long x = strtoul(p, &z, 10);
			if (z != p) conf->attempts = x > 10 ? 10 : x;
		}
		p = strstr(line, "timeout:");
		if (p && (isdigit(p[8]) || p[8]=='.')) {
			p += 8;
			unsigned long x = strtoul(p, &z, 10);
			if (z != p) conf->timeout = x > 60 ? 60 : x;
		}
		continue;
	}
	if (!strncmp(line, "nameserver", 10) && isspace(line[10])) {
		if (nns >= MAXNS) continue;
		for (p=line+11; isspace(*p); p++);
		for (z=p; *z && !isspace(*z); z++);
		*z=0;
		if (__lookup_ipliteral(conf->ns+nns, p, AF_UNSPEC) > 0)
			nns++;
		continue;
	}

	if (!search) continue;
	if ((strncmp(line, "domain", 6) && strncmp(line, "search", 6))
	    || !isspace(line[6]))
		continue;
	for (p=line+7; isspace(*p); p++);
	size_t l = strlen(p);
	/* This can never happen anyway with chosen buffer sizes. */
	if (l >= search_sz) continue;
	memcpy(search, p, l+1);
}

__fclose_ca(f);

no_resolv_conf: if (!nns) { __lookup_ipliteral(conf->ns, "127.0.0.1", AF_UNSPEC); nns = 1; }

get_conf_ok: conf->nns = nns;

return 0;

}


五.selinux校验处理

启动编译的可执行文件需要selinux权限,调试时可选择临时关闭和临时关闭,或者根据需求进行配置

  1. 使用下面命令进行关闭selinux hdc shell mount -o rw,remount / hdc shell "sed -i 's/enforcing/permissive/g' /system/etc/selinux/config" hdc shell "cat /system/etc/selinux/config |grep SELINUX="

  2. selinux配置相关服务 参考selinux配置

六、SN问题

修改ble_svc_custom_sec_data.c foundation/communication/iot_connect/core/ble/application/profile/ble_svc_custom_sec_data.c 在BuildBleCustomSecDataService后面增加如下代码,进行发两遍处理 LinkLayerReportSvcDataEnc(BLE_SVC_CUSTOM_SEC_DATA, (const uint8_t *)*out, *outLen); 修改后如下 static int32_t BleCustomSecDataGetChar(IotcJson *vendorItem, uint8_t **out, uint32_t *outLen, DevCtlGetCharStates getChar) { IotcJson *arrayObj = NULL; int32_t ret = getChar(vendorItem, &arrayObj); if (ret != IOTC_OK) { IOTC_LOGW("get char control error %d", ret); return ret; }

#if IOTC_CONF_AILIFE_SUPPORT ret = BuildBleCustomSecDataSingleService(arrayObj, out, outLen); #else ret = BuildBleCustomSecDataService(arrayObj, out, outLen); LinkLayerReportSvcDataEnc(BLE_SVC_CUSTOM_SEC_DATA, (const uint8_t *)*out, *outLen); #endif IotcJsonDelete(arrayObj); if (ret != IOTC_OK) { IOTC_LOGW("build get char json array %d", ret); return ret; }

return IOTC_OK;

}