forked from legenddcr/aliyun-mqtt-arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aliyun_mqtt.h
68 lines (57 loc) · 2.38 KB
/
aliyun_mqtt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Aliyun_mqtt.h - Library for connect to Aliyun MQTT server with authentication by
product key, device name and device secret.
https://www.alibabacloud.com/help/product/30520.htm
*/
#ifndef _ALIYUN_MATT_H
#define _ALIYUN_MATT_H
#include <Arduino.h>
#include <PubSubClient.h>
/**
* Connect to Alibaba Cloud MQTT server. In connection process, it will try several times for
* possible network failure. For authentication issue, it will return false at once.
*
* @param mqttClient: Caller provide a valid PubSubClient object (initialized with network client).
* @param productKey: Product Key, get from Alibaba Cloud Link Platform.
* @param deviceName: Device Name, get from Alibaba Cloud Link Platform.
* @param deviceSecret: Device Secret, get from Alibaba Cloud Link Platform.
*
* @param region: Optional region, use "cn-shanghai" as default. It can be "us-west-1",
* "ap-southeast-1" etc. Refer to Alibaba Cloud Link Platform.
*
*
* @return true if connect succeed, otherwise false.
*/
extern "C" bool connectAliyunMQTT(
PubSubClient &mqttClient,
const char *productKey,
const char *deviceName,
const char *deviceSecret,
const char *region = "cn-shanghai");
/**
* Two new added APIs are designed for devices with limited resource like Arduino UNO.
* Since it is hard to calculate HMAC256 on such devices, the calculation can be done externally.
*
* These two APIs should be used together with external HMAC256 calculation tools, e.g.
* http://tool.oschina.net/encrypt?type=2
* They can be used together to replace connectAliyunMQTT on resource-limited devices.
*/
/**
* This API should be called in setup() phase to init all MQTT parameters. Since HMAC256
* calculation is executed extenrally, a fixed timestamp string should be provided, such
* as "23668" etc. The same timestamp string is also used to calculate HMAC256 result.
*
* Other params are similar to them in connectAliyunMQTT.
*/
extern "C" void mqttPrepare(
const char *timestamp,
const char *productKey,
const char *deviceName,
const char *deviceSecret,
const char *region = "cn-shanghai");
/**
* Use tools here to calculate HMAC256: http://tool.oschina.net/encrypt?type=2
* The calculated result should be defined as constants and passed when call this function.
*/
extern "C" bool connectAliyunMQTTWithPassword(PubSubClient &mqttClient, const char *password);
#endif