# Linux集成指南

## **一、获取SDK**

登录灯塔首页，创建应用，填入基本应用信息，即可获取独一无二的AppKey，并下载SDK；

[点此下载SDK for Linux](/beacon-help/sdkhuo-qu/sdk-for-linux.md)

## **二、集成SDK**

压缩文件分三个部分内容：

```
lib32/libbeacon.so
lib64/libbeacon.so
include/
```

其中lib32/libbeacon.so在32位linux系统上使用；lib64/libbeacon.so在64位linux系统上使用；include目录内为需要的头文件。

如何集成使用？

### 1、引入头文件

```
#include "include/beacon.h"
```

### 2、初始化SDK

```
// 设置进程名
SetProcessName(argv[0]);
// 设置产品名+产品版本
SetProductInfo("smart_sound_box", "v1.0.0");
// 设置设备唯一标识（用于统计日活）
SetDeviceID("xxxxxxxx");
// 传入appkey+渠道号初始化sdk
InitSDK("0M000A1RC72MXXRH", "1001");
```

参考上面代码，根据自己设备信息传入对应参数值。

### 3、事件上报

```
// 同步上报（无附加参数）
ReportEvent("test_01");
// 异步上报（有附加参数）
Map* param = NEW_MAP_STRING;
AddParam(param, "key1", "Value1");
AddParam(param, "key2","Value2");
AsynReportEventWithParams("asyn_test_02");
DELETE_MAP_STRING(param);
```

提供两中上报方式：同步上报和异步上报。

两种上报方式都支持是否携带附加参数，附加参数是一个Map类型，通过AddParam函数添加key/value。

## &#x4E09;**、基本接口**

* **设置日志是否打开和实时联调开关接口**

```
void SetLogable(BOOL enable_local_log, BOOL enable_realtime_test)
```

**enable\_local\_log ：TRUE表示打开本地log日志**

**enable\_realtime\_test ：TRUE表示使用实时联调来验证日志上报情况**

**可以在web管理页面的“数据查询”->“接入实时联调”中实时查看上报事件日志**

* **设置本地日志打印等级**

```
void SetLogLevel(unsigned int level)
```

**level ：主要等级有B\_DEBUG/B\_INFO/B\_WARN/B\_ERROR/B\_ALARM/B\_FATAL，默认是B\_DEBUG。如果等级设置为B\_ERROR时则本地log日志只会展示B\_ERROR/B\_ALARM/B\_FATAL三种类型日志**

* **设置智能设备的系统和机型**

```
void SetDeviceInfo(const char* os_version, const char* model)
```

**os\_version ：智能设备的操作系统版本**

**model ：设备的型号，类似移动端品牌如”Mix2”**

* **设置产品名和产品版本**

```
void SetProductInfo(const char* product_name, const char* product_version)
```

**product\_name ：产品名称，类似移动端的App名**

**product\_version ：产品版本号**

* **设置当前设备的唯一号（必须要填写否则无法统计日活等数据）**

```
void SetDeviceID(const char* device_id)
```

**device\_id ： 唯一表示该智能设备的号码**

* **设置用户ID**

```
void SetUserID(const char* user_id)
```

**user\_id ：产品自己的用户体系下用户ID，如登录的用户QQ号等**

* **设置应用所在进程的进程名**

```
void SetProcessName(const char* argv0)
```

**argv0 ：进程名**

* **初始化SDK（必须调用）**

```
void InitSDK(const char* app_key, const char* channel)
```

**app\_key ：灯塔上注册产品时产生的AppKey**

**channel ：渠道号**

* **退出SDK（释放SDK线程池所占资源）**

```
void ExitSDK()
```

* **同步上报事件**

```
int ReportEvent(const char* event_name)
int ReportEventWithParams(const char* event_name, Map* params)
```

**event\_name ：事件名**

**params ：事件附加参数（key/value形式添加附加参数）**

* **异步上报事件**

```
int AsynReportEvent(const char* event_name)
int AsynReportEventWithParams(const char* event_name, Map* params)
```

**event\_name ：事件名**

**params ：事件附加参数（key/value形式添加附加参数）**

还有疑问？欢迎反馈给<tbeacon@tencent.com>，会有专人为您服务。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://beacon-help.gitbook.io/beacon-help/sdk-wen-dang/sdkji-cheng-zhi-nan/linuxji-cheng-zhi-nan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
