2022-01-12 17:24:18 +08:00
|
|
|
/**
|
|
|
|
|
*
|
2022-02-11 15:06:16 +08:00
|
|
|
* Copyright (c) 2020-2022 IRbaby-IRext
|
2022-01-12 17:24:18 +08:00
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
|
|
#include "IRbabySerial.h"
|
2022-01-30 11:24:38 +08:00
|
|
|
#include "IRbabyAlink.h"
|
2022-01-12 17:24:18 +08:00
|
|
|
#include "IRbabyGlobal.h"
|
|
|
|
|
|
2022-01-30 10:47:36 +08:00
|
|
|
#define TOPIC_NAME_MAX (64)
|
2022-01-12 17:24:18 +08:00
|
|
|
|
2022-01-30 10:47:36 +08:00
|
|
|
#define PRODUCT_KEY "a1WlzsJh50b"
|
|
|
|
|
#define DEVICE_NAME "IRIS_Kit_Dev"
|
|
|
|
|
#define DEVICE_SECRET "9df2c6b48e4c66519718cc236fc9fb79"
|
|
|
|
|
#define REGION_ID "cn-shanghai"
|
|
|
|
|
|
|
|
|
|
#define USER_NAME "strawmanbobi@irext.net"
|
2022-01-12 17:24:18 +08:00
|
|
|
|
|
|
|
|
static AliyunIoTSDK iot;
|
|
|
|
|
static char IRIS_UPSTREAM_TOPIC[TOPIC_NAME_MAX] = { 0 };
|
2022-01-30 10:47:36 +08:00
|
|
|
static ep_state_t endpoint_state = FSM_IDLE;
|
2022-01-12 17:24:18 +08:00
|
|
|
|
|
|
|
|
static void registerCallback();
|
|
|
|
|
static void irisAlinkCallback(const char *topic, uint8_t *data, int length);
|
2022-01-30 10:47:36 +08:00
|
|
|
static void sendIrisKitHeartBeat();
|
2022-01-12 17:24:18 +08:00
|
|
|
|
|
|
|
|
void connectToAliyunIoT() {
|
|
|
|
|
INFOLN("Try connecting to Aliyun IoT");
|
|
|
|
|
iot.begin(wifi_client, PRODUCT_KEY, DEVICE_NAME, DEVICE_SECRET, REGION_ID);
|
|
|
|
|
INFOLN("Aliyun IoT connect done");
|
|
|
|
|
snprintf(IRIS_UPSTREAM_TOPIC, TOPIC_NAME_MAX - 1, "/%s/%s/user/iris/upstream", PRODUCT_KEY,
|
|
|
|
|
DEVICE_NAME);
|
|
|
|
|
registerCallback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void checkAlinkMQTT() {
|
|
|
|
|
iot.loop();
|
2022-01-30 10:47:36 +08:00
|
|
|
sendIrisKitHeartBeat();
|
2022-01-12 17:24:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// not only for IRIS related topic based session
|
|
|
|
|
void sendRawData(const char* topic, const uint8_t *data, int length) {
|
|
|
|
|
iot.sendCustomData(topic, data, length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AliyunIoTSDK getSession() {
|
|
|
|
|
return iot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void registerCallback() {
|
|
|
|
|
iot.registerCustomCallback(irisAlinkCallback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void irisAlinkCallback(const char *topic, uint8_t *data, int length) {
|
|
|
|
|
INFO("IRIS Alink callback triggerd : topic = ");
|
|
|
|
|
INFO(topic);
|
|
|
|
|
INFO(", data = ");
|
|
|
|
|
INFO((char*)data);
|
|
|
|
|
INFO(", length = ");
|
|
|
|
|
INFOLN(length);
|
|
|
|
|
}
|
2022-01-30 10:47:36 +08:00
|
|
|
|
|
|
|
|
static void sendIrisKitHeartBeat() {
|
|
|
|
|
|
|
|
|
|
}
|