add pm2d5 demo for evb_g0
add pm2d5 demo for evb_g0
This commit is contained in:
422
devices/m5311_tencent_firmware/m5311_tencent_firmware.c
Normal file
422
devices/m5311_tencent_firmware/m5311_tencent_firmware.c
Normal file
@@ -0,0 +1,422 @@
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
#include "tos_at.h"
|
||||
#include "tos_hal.h"
|
||||
#include "tencent_firmware_module_wrapper.h"
|
||||
#include "m5311_tencent_firmware.h"
|
||||
|
||||
/*
|
||||
* config dev info to module, do this operate only once in factroy is suggested
|
||||
*/
|
||||
int m5311_tencent_firmware_module_info_set(device_info_t *info, tls_mode_t mode)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCDEVINFOSET:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCDEVINFOSET=%d,\"%s\",\"%s\",\"%s\"\r\n",
|
||||
mode, info->product_id, info->device_name, info->device_serc);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* mqtt setup connect */
|
||||
int m5311_tencent_firmware_module_mqtt_conn(mqtt_param_t init_params)
|
||||
{
|
||||
int try = 0;
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTCONN:OK");
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCMQTTCONN=%d,%d,%d,%d,%d\r\n", init_params.tls_mode,
|
||||
init_params.command_timeout, init_params.keep_alive_interval_ms,
|
||||
init_params.clean_session, init_params.auto_connect_enable);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* mqtt disconn */
|
||||
int m5311_tencent_firmware_module_mqtt_discon(void)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+TCMQTTDISCONN\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int m5311_tencent_firmware_module_mqtt_publ(const char *topic, qos_t qos, char *payload)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, ">");
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+TCMQTTPUBL=\"%s\",%d,%d\r\n", topic, qos, strlen(payload)-2);
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTPUB:OK");
|
||||
tos_at_raw_data_send(&echo, 1000, (uint8_t *)payload, strlen(payload));
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* mqtt pub msg */
|
||||
int m5311_tencent_firmware_module_mqtt_pub(const char *topic, qos_t qos, char *payload)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTPUB:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+TCMQTTPUB=\"%s\",%d,\"%s\"\r\n", topic, qos, payload);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int m5311_tencent_firmware_module_mqtt_sub(char *topic, qos_t qos)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTSUB:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCMQTTSUB=\"%s\",%d\r\n", topic, qos);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int m5311_tencent_firmware_module_mqtt_unsub(const char *topic)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTUNSUB:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCMQTTUNSUB=\"%s\"\r\n", topic);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int m5311_tencent_firmware_module_mqtt_state_get(mqtt_state_t *state)
|
||||
{
|
||||
char *str;
|
||||
int ret_state;
|
||||
at_echo_t echo;
|
||||
char echo_buffer[64];
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+TCMQTTSTATE?\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+TCMQTTSTATE:");
|
||||
if (!str)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
sscanf(str, "+TCMQTTSTATE:%d", &ret_state);
|
||||
if (ret_state == 0) {
|
||||
*state = MQTT_STATE_DISCONNECTED;
|
||||
return 0;
|
||||
} else if (ret_state == 1) {
|
||||
*state = MQTT_STATE_CONNECTED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int m5311_tencent_firmware_module_debug_level_set(int log_level)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+TCTEMLOG=%d\r\n", log_level);
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int m5311_tencent_firmware_join_net(void)
|
||||
{
|
||||
int try = 0;
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "OK");
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 5000, "AT+TCREGNET?\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int m5311_tencent_firmware_init(void)
|
||||
{
|
||||
printf("Init m5311 with tencent firmware ...\n");
|
||||
|
||||
if (m5311_tencent_firmware_join_net() != 0) {
|
||||
printf("m5311 restore FAILED\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Init m5311 with tencent firmware Done\n" );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int m5311_tencent_firmware_ota_set(ota_mode_t mode, char *version)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCOTASET:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCOTASET=%d,\"%s\"\r\n", mode, version);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
k_sem_t ota_fw_info_sem;
|
||||
|
||||
int m5311_tencent_firmware_ota_read_fwinfo(ota_fw_info_t *ota_fw_info)
|
||||
{
|
||||
at_echo_t echo;
|
||||
char echo_buffer[64];
|
||||
uint8_t FileSize[10] = {0};
|
||||
uint32_t updateFileSize = 0;
|
||||
|
||||
/* wait update command frome cloud forever */
|
||||
if(K_ERR_NONE != tos_sem_create_max(&ota_fw_info_sem, 0, 1)) {
|
||||
return -1;
|
||||
}
|
||||
tos_sem_pend(&ota_fw_info_sem, TOS_TIME_FOREVER);
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), "+TCFWINFO:");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCFWINFO?\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
|
||||
sscanf(echo_buffer, "%*[^\"]%*c%[^\"]%*[^,]%*c%[^,]%*[^\"]%*c%[^\"]", ota_fw_info->fw_version, FileSize, ota_fw_info->fw_md5);
|
||||
for(int i = 0; i<10; i++)
|
||||
{
|
||||
if(FileSize[i] == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
updateFileSize = updateFileSize*10 + (FileSize[i] - 0x30);
|
||||
}
|
||||
ota_fw_info->fw_size = updateFileSize;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
k_chr_fifo_t ota_fw_data_chr_fifo;
|
||||
k_sem_t ota_fw_data_sem;
|
||||
|
||||
static int m5311_tencent_firmware_ota_read_fwdata(uint8_t *ota_fw_data_buffer,uint16_t read_len)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
if(K_ERR_NONE != tos_chr_fifo_create(&ota_fw_data_chr_fifo, ota_fw_data_buffer, read_len)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(K_ERR_NONE != tos_sem_create_max(&ota_fw_data_sem, 0, 1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
|
||||
tos_at_cmd_exec(&echo, 300, "AT+TCREADFWDATA=%d\r\n", read_len);
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_sem_pend(&ota_fw_data_sem, TOS_TIME_FOREVER);
|
||||
|
||||
return tos_chr_fifo_pop_stream(&ota_fw_data_chr_fifo, ota_fw_data_buffer, read_len);
|
||||
}
|
||||
|
||||
static mqtt_message_t mqtt_message;
|
||||
|
||||
void m5311_tencent_firmware_recvpub(void)
|
||||
{
|
||||
/*
|
||||
+TCMQTTRCVPUB:"xxx/yyy/zzz",44,"{"type":"get", "clientToken":"123456781234"}"
|
||||
*/
|
||||
|
||||
uint8_t data;
|
||||
int read_len = 0, payload_len = 0;
|
||||
|
||||
memset(&mqtt_message, 0, sizeof(mqtt_message));
|
||||
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
if (data == '"') {
|
||||
continue;
|
||||
} else if (data == ',') {
|
||||
break;
|
||||
}
|
||||
if (read_len < sizeof(mqtt_message.topic)) {
|
||||
mqtt_message.topic[read_len++] = data;
|
||||
}
|
||||
}
|
||||
if (read_len == sizeof(mqtt_message.topic)) {
|
||||
mqtt_message.topic[read_len - 1] = '\0';
|
||||
} else {
|
||||
mqtt_message.topic[read_len] = '\0';
|
||||
}
|
||||
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
if (data == ',') {
|
||||
break;
|
||||
}
|
||||
payload_len = payload_len * 10 + (data - '0');
|
||||
}
|
||||
|
||||
if (payload_len > sizeof(mqtt_message.payload)) {
|
||||
payload_len = sizeof(mqtt_message.payload);
|
||||
}
|
||||
|
||||
read_len = tos_at_uart_read((uint8_t*)mqtt_message.payload, payload_len + 2);
|
||||
if (read_len != payload_len + 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
tos_mail_q_post(&mqtt_message_mail, &mqtt_message, sizeof(mqtt_message_t));
|
||||
}
|
||||
|
||||
void m5311_tencent_firmware_recvcmd(void)
|
||||
{
|
||||
/*
|
||||
+TCOTASTATUS:UPDATEFAIL
|
||||
+TCOTASTATUS:UPDATESUCCESS
|
||||
*/
|
||||
uint8_t buffer[20];
|
||||
int read_len = 13;
|
||||
|
||||
if (tos_at_uart_read(buffer, read_len) != read_len) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!strstr((char*)buffer, "UPDATESUCCESS")) {
|
||||
return;
|
||||
}
|
||||
|
||||
tos_sem_post(&ota_fw_info_sem);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void m5311_tencent_firmware_recvfwdata(void)
|
||||
{
|
||||
/*
|
||||
+TCREADFWDATA:256,<HEX Data>
|
||||
*/
|
||||
uint8_t data;
|
||||
uint16_t data_len = 0, read_len = 0;
|
||||
static uint8_t buffer[128];
|
||||
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
if (data == ',') {
|
||||
break;
|
||||
}
|
||||
data_len = data_len * 10 + (data - '0');
|
||||
}
|
||||
|
||||
do {
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
read_len = MIN(data_len, sizeof(buffer));
|
||||
if (tos_at_uart_read(buffer, read_len) != read_len) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tos_chr_fifo_push_stream(&ota_fw_data_chr_fifo, buffer, read_len) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
data_len -= read_len;
|
||||
} while (data_len > 0);
|
||||
|
||||
tos_sem_post(&ota_fw_data_sem);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
at_event_t m5311_tencent_firmware_at_event[] = {
|
||||
{ "+TCMQTTRCVPUB:", m5311_tencent_firmware_recvpub },
|
||||
{ "+TCREADFWDATA:", m5311_tencent_firmware_recvfwdata },
|
||||
{ "+TCOTASTATUS:", m5311_tencent_firmware_recvcmd },
|
||||
};
|
||||
|
||||
tencent_firmware_module_t tencent_firmware_module_m5311 = {
|
||||
.init = m5311_tencent_firmware_init,
|
||||
.info_set = m5311_tencent_firmware_module_info_set,
|
||||
.mqtt_conn = m5311_tencent_firmware_module_mqtt_conn,
|
||||
.mqtt_discon = m5311_tencent_firmware_module_mqtt_discon,
|
||||
.mqtt_pub = m5311_tencent_firmware_module_mqtt_pub,
|
||||
.mqtt_publ = m5311_tencent_firmware_module_mqtt_publ,
|
||||
.mqtt_sub = m5311_tencent_firmware_module_mqtt_sub,
|
||||
.mqtt_unsub = m5311_tencent_firmware_module_mqtt_unsub,
|
||||
.mqtt_state_get = m5311_tencent_firmware_module_mqtt_state_get,
|
||||
.debug_level_set = m5311_tencent_firmware_module_debug_level_set,
|
||||
.ota_set = m5311_tencent_firmware_ota_set,
|
||||
.ota_read_fwinfo = m5311_tencent_firmware_ota_read_fwinfo,
|
||||
.ota_read_fwdata = m5311_tencent_firmware_ota_read_fwdata,
|
||||
};
|
||||
|
||||
int m5311_tencent_firmware_sal_init(hal_uart_port_t uart_port)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if (tos_at_init(uart_port, m5311_tencent_firmware_at_event,
|
||||
sizeof(m5311_tencent_firmware_at_event) /
|
||||
sizeof(m5311_tencent_firmware_at_event[0])) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tos_tf_module_register(&tencent_firmware_module_m5311) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((ret = tos_tf_module_init()) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
28
devices/m5311_tencent_firmware/m5311_tencent_firmware.h
Normal file
28
devices/m5311_tencent_firmware/m5311_tencent_firmware.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* Tencent is pleased to support the open source community by making TencentOS
|
||||
* available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* If you have downloaded a copy of the TencentOS binary from Tencent, please
|
||||
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
|
||||
*
|
||||
* If you have downloaded a copy of the TencentOS source code from Tencent,
|
||||
* please note that TencentOS source code is licensed under the BSD 3-Clause
|
||||
* License, except for the third-party components listed below which are
|
||||
* subject to different license terms. Your integration of TencentOS into your
|
||||
* own projects may require compliance with the BSD 3-Clause License, as well
|
||||
* as the other licenses applicable to the third-party components included
|
||||
* within TencentOS.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __m5311_TENCENT_FIRMWARE_H__
|
||||
#define __m5311_TENCENT_FIRMWARE_H__
|
||||
|
||||
#include "tos_hal.h"
|
||||
|
||||
|
||||
int m5311_tencent_firmware_sal_init(hal_uart_port_t uart_port);
|
||||
int m5311_tencent_firmware_join_ap(const char *ssid, const char *pwd);
|
||||
|
||||
#endif /* __m5311_TENCENT_FIRMWARE_H__ */
|
||||
|
118
devices/m5311_tencent_firmware/mqtt_iot_explorer_tc_demo.c
Normal file
118
devices/m5311_tencent_firmware/mqtt_iot_explorer_tc_demo.c
Normal file
@@ -0,0 +1,118 @@
|
||||
#include "tos_k.h"
|
||||
#include "m5311_tencent_firmware.h"
|
||||
#include "tencent_firmware_module_wrapper.h"
|
||||
|
||||
|
||||
#define PRODUCT_ID "BDDSF87WEA"
|
||||
#define DEVICE_NAME "dev001"
|
||||
#define DEVICE_KEY "2/sOZRAJ6B+vMNNXS41w5g=="
|
||||
|
||||
#define REPORT_DATA_TEMPLATE "{\\\"method\\\":\\\"report\\\"\\,\\\"clientToken\\\":\\\"00000001\\\"\\,\\\"params\\\":{\\\"ch20_ppm_value\\\":%.3f}}"
|
||||
|
||||
void default_message_handler(mqtt_message_t* msg)
|
||||
{
|
||||
printf("callback:\r\n");
|
||||
printf("---------------------------------------------------------\r\n");
|
||||
printf("\ttopic:%s\r\n", msg->topic);
|
||||
printf("\tpayload:%s\r\n", msg->payload);
|
||||
printf("---------------------------------------------------------\r\n");
|
||||
}
|
||||
|
||||
char payload[256] = {0};
|
||||
static char report_topic_name[TOPIC_NAME_MAX_SIZE] = {0};
|
||||
static char report_reply_topic_name[TOPIC_NAME_MAX_SIZE] = {0};
|
||||
|
||||
k_mail_q_t mail_q;
|
||||
|
||||
|
||||
void mqtt_demo_task(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int size = 0;
|
||||
int lightness = 0;
|
||||
mqtt_state_t state;
|
||||
|
||||
char *product_id = PRODUCT_ID;
|
||||
char *device_name = DEVICE_NAME;
|
||||
char *key = DEVICE_KEY;
|
||||
|
||||
device_info_t dev_info;
|
||||
memset(&dev_info, 0, sizeof(device_info_t));
|
||||
|
||||
float ch20_ppm_value = 0.067;
|
||||
|
||||
/**
|
||||
* Please Choose your AT Port first, default is HAL_UART_2(USART2)
|
||||
*/
|
||||
ret = m5311_tencent_firmware_sal_init(HAL_UART_PORT_1);
|
||||
|
||||
if (ret < 0) {
|
||||
printf("m5311 tencent firmware sal init fail, ret is %d\r\n", ret);
|
||||
}
|
||||
|
||||
strncpy(dev_info.product_id, product_id, PRODUCT_ID_MAX_SIZE);
|
||||
strncpy(dev_info.device_name, device_name, DEVICE_NAME_MAX_SIZE);
|
||||
strncpy(dev_info.device_serc, key, DEVICE_SERC_MAX_SIZE);
|
||||
tos_tf_module_info_set(&dev_info, TLS_MODE_PSK);
|
||||
|
||||
mqtt_param_t init_params = DEFAULT_MQTT_PARAMS;
|
||||
if (tos_tf_module_mqtt_conn(init_params) != 0) {
|
||||
printf("module mqtt conn fail\n");
|
||||
} else {
|
||||
printf("module mqtt conn success\n");
|
||||
}
|
||||
|
||||
if (tos_tf_module_mqtt_state_get(&state) != -1) {
|
||||
printf("MQTT: %s\n", state == MQTT_STATE_CONNECTED ? "CONNECTED" : "DISCONNECTED");
|
||||
}
|
||||
|
||||
/* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>topic */
|
||||
size = snprintf(report_reply_topic_name, TOPIC_NAME_MAX_SIZE, "$thing/down/property/%s/%s", product_id, device_name);
|
||||
|
||||
if (size < 0 || size > sizeof(report_reply_topic_name) - 1) {
|
||||
printf("sub topic content length not enough! content size:%d buf size:%d", size, (int)sizeof(report_reply_topic_name));
|
||||
}
|
||||
if (tos_tf_module_mqtt_sub(report_reply_topic_name, QOS0, default_message_handler) != 0) {
|
||||
printf("module mqtt sub fail\n");
|
||||
} else {
|
||||
printf("module mqtt sub success\n");
|
||||
}
|
||||
|
||||
memset(report_topic_name, sizeof(report_topic_name), 0);
|
||||
size = snprintf(report_topic_name, TOPIC_NAME_MAX_SIZE, "$thing/up/property/%s/%s", product_id, device_name);
|
||||
|
||||
if (size < 0 || size > sizeof(report_topic_name) - 1) {
|
||||
printf("pub topic content length not enough! content size:%d buf size:%d", size, (int)sizeof(report_topic_name));
|
||||
}
|
||||
|
||||
|
||||
while (1) {
|
||||
|
||||
/* <20>ϱ<EFBFBD>ֵ */
|
||||
memset(payload, 0, sizeof(payload));
|
||||
snprintf(payload, sizeof(payload), REPORT_DATA_TEMPLATE, ch20_ppm_value);
|
||||
|
||||
if (lightness > 100) {
|
||||
lightness = 0;
|
||||
}
|
||||
|
||||
if (tos_tf_module_mqtt_pub(report_topic_name, QOS0, payload) != 0) {
|
||||
printf("module mqtt pub fail\n");
|
||||
break;
|
||||
} else {
|
||||
printf("module mqtt pub success\n");
|
||||
}
|
||||
|
||||
tos_sleep_ms(5000);
|
||||
}
|
||||
}
|
||||
|
||||
void application_entry(void *arg)
|
||||
{
|
||||
|
||||
mqtt_demo_task();
|
||||
while (1) {
|
||||
printf("This is a mqtt demo!\r\n");
|
||||
tos_task_delay(1000);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user