调试阿里云物联网平台
This commit is contained in:
parent
4de6f893a1
commit
2cb947c882
@ -62,7 +62,7 @@ CONFIG_RT_USING_DEVICE=y
|
||||
# CONFIG_RT_USING_DEVICE_OPS is not set
|
||||
# CONFIG_RT_USING_INTERRUPT_INFO is not set
|
||||
CONFIG_RT_USING_CONSOLE=y
|
||||
CONFIG_RT_CONSOLEBUF_SIZE=128
|
||||
CONFIG_RT_CONSOLEBUF_SIZE=512
|
||||
CONFIG_RT_CONSOLE_DEVICE_NAME="uart1"
|
||||
CONFIG_RT_VER_NUM=0x40002
|
||||
CONFIG_ARCH_ARM=y
|
||||
@ -331,8 +331,8 @@ CONFIG_PKG_AT_DEVICE_PATH="/packages/iot/at_device"
|
||||
CONFIG_AT_DEVICE_USING_ESP8266=y
|
||||
CONFIG_AT_DEVICE_ESP8266_INIT_ASYN=y
|
||||
CONFIG_AT_DEVICE_ESP8266_SAMPLE=y
|
||||
CONFIG_ESP8266_SAMPLE_WIFI_SSID="ChinaNet-ssssss"
|
||||
CONFIG_ESP8266_SAMPLE_WIFI_PASSWORD="SQHWLK9394"
|
||||
CONFIG_ESP8266_SAMPLE_WIFI_SSID="xgld1"
|
||||
CONFIG_ESP8266_SAMPLE_WIFI_PASSWORD="xgld64627816"
|
||||
CONFIG_ESP8266_SAMPLE_CLIENT_NAME="uart3"
|
||||
CONFIG_ESP8266_SAMPLE_RECV_BUFF_LEN=512
|
||||
# CONFIG_AT_DEVICE_USING_RW007 is not set
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "cJSON.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <netdev.h>
|
||||
#include <sht3x.h>
|
||||
|
||||
#define LOG_TAG "ali-sdk"
|
||||
#define LOG_LVL LOG_LVL_DBG
|
||||
@ -21,8 +22,8 @@
|
||||
#define MQTT_MAN_INFO_STRING "DiyMultiMeter"
|
||||
|
||||
/* <20>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ */
|
||||
#define ALI_SERVICE_RGB_CTRL_SUB "Topic-ServiceDoorCtrlSub"
|
||||
#define ALI_SERVICE_RGB_CTRL_REPLY_PUB "Topic-ServiceDoorCtrlReplyPub"
|
||||
#define ALI_SERVICE_RGB_CTRL_SUB "Topic-ServiceRGBCtrlSub"
|
||||
#define ALI_SERVICE_RGB_CTRL_REPLY_PUB "Topic-ServiceRGBCtrlReplyPub"
|
||||
/* <20>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><CFB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ */
|
||||
#define ALI_PROPERTY_POST_PUB "Topic-PropertyPostPub"
|
||||
#define ALI_PROPERTY_POST_REPLY_SUB "Topic-PropertyPostReplySub"
|
||||
@ -32,6 +33,7 @@ static uint32_t mqtt_period_cnt = 0;
|
||||
static uint32_t mqtt_packet_id = 1;
|
||||
static void ali_mqtt_rgb_ctrl_msg_arrive(void *pcontext, void *handle, iotx_mqtt_event_msg_pt msg);
|
||||
static void ali_mqtt_property_post_msg_arrive(void *pcontext, void *handle, iotx_mqtt_event_msg_pt msg);
|
||||
extern sht3x_device_t aliget_sht30_singleshot(void);
|
||||
extern int HAL_GetProductKey(char product_key[IOTX_PRODUCT_KEY_LEN + 1]);
|
||||
extern int HAL_GetProductSecret(char product_secret[IOTX_PRODUCT_SECRET_LEN + 1]);
|
||||
extern int HAL_GetDeviceName(char device_name[IOTX_DEVICE_NAME_LEN + 1]);
|
||||
@ -93,9 +95,9 @@ static char * mqtt_check_load_topic(void)
|
||||
for (topic_idx = 0; topic_idx < sub_items; topic_idx++)
|
||||
{
|
||||
if (!rt_strcmp(mqtt_sub_item[topic_idx].topic_filter, ALI_SERVICE_RGB_CTRL_SUB))
|
||||
rt_snprintf(&topic[topic_idx * 128], MQTT_TOPIC_MAX_SIZE, "/sys/%s/%s/thing/service/rgb_ctrl", product_key, device_name);
|
||||
rt_snprintf(&topic[topic_idx * 128], MQTT_TOPIC_MAX_SIZE, "/sys/%s/%s/thing/service/RGBCtrl", product_key, device_name);
|
||||
else if (!rt_strcmp(mqtt_sub_item[topic_idx].topic_filter, ALI_SERVICE_RGB_CTRL_REPLY_PUB))
|
||||
rt_snprintf(&topic[topic_idx * 128], MQTT_TOPIC_MAX_SIZE, "/sys/%s/%s/thing/service/rgb_ctrl_reply", product_key, device_name);
|
||||
rt_snprintf(&topic[topic_idx * 128], MQTT_TOPIC_MAX_SIZE, "/sys/%s/%s/thing/service/RGBCtrl_reply", product_key, device_name);
|
||||
else if (!rt_strcmp(mqtt_sub_item[topic_idx].topic_filter, ALI_PROPERTY_POST_PUB))
|
||||
rt_snprintf(&topic[topic_idx * 128], MQTT_TOPIC_MAX_SIZE, "/sys/%s/%s/thing/event/property/post", product_key, device_name);
|
||||
else if (!rt_strcmp(mqtt_sub_item[topic_idx].topic_filter, ALI_PROPERTY_POST_REPLY_SUB))
|
||||
@ -111,7 +113,43 @@ static char * mqtt_check_load_topic(void)
|
||||
}
|
||||
static void ali_mqtt_rgb_ctrl_msg_arrive (void *pcontext, void *handle, iotx_mqtt_event_msg_pt msg)
|
||||
{
|
||||
cJSON *root, *id, *params, *rgb_idx;
|
||||
iotx_mqtt_topic_info_pt ptopic_info = (iotx_mqtt_topic_info_pt) msg->msg;
|
||||
|
||||
LOG_D("subcrible message arrive: %.*s.", ptopic_info->topic_len, ptopic_info->ptopic);
|
||||
|
||||
root = cJSON_Parse(ptopic_info->payload);
|
||||
if (root == RT_NULL)
|
||||
{
|
||||
LOG_D("cJSON parse failed.");
|
||||
goto __door_ctrl_exit;
|
||||
}
|
||||
|
||||
id = cJSON_GetObjectItem(root, "id");
|
||||
if (id == RT_NULL)
|
||||
{
|
||||
LOG_D("cJSON get object[id] failed.");
|
||||
goto __door_ctrl_exit;
|
||||
}
|
||||
|
||||
params = cJSON_GetObjectItem(root, "params");
|
||||
if (params == RT_NULL)
|
||||
{
|
||||
LOG_D("cJSON get object[params] failed.");
|
||||
goto __door_ctrl_exit;
|
||||
}
|
||||
|
||||
rgb_idx = cJSON_GetObjectItem(params, "rgb_idx");
|
||||
if (rgb_idx == RT_NULL)
|
||||
{
|
||||
LOG_D("cJSON get object[rgb_idx] failed.");
|
||||
goto __door_ctrl_exit;
|
||||
}
|
||||
LOG_D("id=%.*s;rgb_idx=%.*s", rt_strlen(id->valuestring), id->valuestring, rt_strlen(rgb_idx->valuestring), rgb_idx->valuestring);
|
||||
|
||||
__door_ctrl_exit:
|
||||
if (root)
|
||||
cJSON_Delete(root);
|
||||
}
|
||||
static void ali_mqtt_property_post_msg_arrive (void *pcontext, void *handle, iotx_mqtt_event_msg_pt msg)
|
||||
{
|
||||
@ -182,14 +220,13 @@ static void ali_mqtt_event_handle(void *pcontext, void *pclient, iotx_mqtt_event
|
||||
break;
|
||||
}
|
||||
}
|
||||
static void mqtt_period_task(void)
|
||||
static void mqtt_period_task()
|
||||
{
|
||||
/* get current time */
|
||||
rt_uint64_t now;
|
||||
now = (rt_uint64_t)(time(RT_NULL) - (3600 * 8));
|
||||
now = now * 1000L;
|
||||
sht3x_device_t sht30_device;
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><CFB1>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD> */
|
||||
sht30_device = aliget_sht30_singleshot();
|
||||
if(sht30_device != RT_NULL)
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><CFB1><EFBFBD>ʪ<EFBFBD><CAAA> */
|
||||
{
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
if (root)
|
||||
@ -197,8 +234,8 @@ static void mqtt_period_task(void)
|
||||
cJSON *js_params = cJSON_CreateObject();
|
||||
cJSON *js_quality = cJSON_CreateObject();
|
||||
cJSON *js_status = cJSON_CreateObject();
|
||||
cJSON *js_device = cJSON_CreateObject();
|
||||
if (js_params && js_quality && js_status && js_device)
|
||||
|
||||
if (js_params && js_quality && js_status )
|
||||
{
|
||||
char str_id[16];
|
||||
rt_memset(str_id, 0, sizeof(str_id));
|
||||
@ -207,13 +244,8 @@ static void mqtt_period_task(void)
|
||||
|
||||
cJSON_AddStringToObject(root, "version", "1.0");
|
||||
cJSON_AddItemToObject(root, "params", js_params);
|
||||
cJSON_AddItemToObject(js_params, "CurrentHumidity", js_quality);
|
||||
cJSON_AddStringToObject(js_quality, "value", "28");
|
||||
cJSON_AddNumberToObject(js_quality, "time", now);
|
||||
cJSON_AddItemToObject(js_params, "CurrentTemperature", js_status);
|
||||
cJSON_AddStringToObject(js_status, "value", "100");
|
||||
cJSON_AddNumberToObject(js_status, "time", now);
|
||||
|
||||
cJSON_AddNumberToObject(js_params, "CurrentHumidity", sht30_device->humidity);
|
||||
cJSON_AddNumberToObject(js_params, "CurrentTemperature", sht30_device->temperature);
|
||||
cJSON_AddStringToObject(root, "method", "thing.event.property.post");
|
||||
char *msg_pub = cJSON_PrintUnformatted(root);
|
||||
if (msg_pub)
|
||||
@ -240,13 +272,17 @@ static void mqtt_period_task(void)
|
||||
}
|
||||
static void mqtt_thread_main_thread(void *arg)
|
||||
{
|
||||
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
struct netdev* net = netdev_get_by_name("esp0");
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>жϵ<D0B6>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
while(netdev_is_internet_up(net) != 1)
|
||||
/* ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD>ִ<EFBFBD><D6B4><EFBFBD>߳<EFBFBD> */
|
||||
while (1)
|
||||
{
|
||||
rt_thread_mdelay(200);
|
||||
struct netdev *netdev_link = netdev_get_first_by_flags(NETDEV_FLAG_LINK_UP);
|
||||
if (netdev_link)
|
||||
{
|
||||
netdev_low_level_set_link_status(netdev_link, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
rt_thread_mdelay(rt_tick_from_millisecond(RT_TICK_PER_SECOND));
|
||||
}
|
||||
|
||||
if (topic_buff != RT_NULL)
|
||||
@ -294,8 +330,10 @@ static void mqtt_thread_main_thread(void *arg)
|
||||
|
||||
if (IOT_MQTT_Subscribe(mqtt_client_hd, &topic_buff[i * 128], mqtt_sub_item[i].qos, mqtt_sub_item[i].topic_handle_func, mqtt_sub_item[i].pcontext) < 0)
|
||||
{
|
||||
LOG_D("IOT_MQTT_Subscribe() failed, topic = %s", &topic_buff[i * 128]);
|
||||
}
|
||||
LOG_D("IOT_MQTT_Subscribe() failed, topic = %s", &topic_buff[i * 128]);
|
||||
}
|
||||
else
|
||||
LOG_D("IOT_MQTT_Subscribe success,topic=%s\r\n", &topic_buff[i * 128]);
|
||||
}
|
||||
|
||||
IOT_MQTT_Yield(mqtt_client_hd, 200);
|
||||
@ -306,22 +344,14 @@ static void mqtt_thread_main_thread(void *arg)
|
||||
|
||||
/* ÿ10sִ<73><D6B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if ((mqtt_period_cnt % 50) == 0)
|
||||
mqtt_period_task();
|
||||
|
||||
{
|
||||
mqtt_period_task();
|
||||
}
|
||||
mqtt_period_cnt++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void mqtt_connect_check_thread(void *arg)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
rt_thread_mdelay(5000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int ali_mqtt_init(void)
|
||||
{
|
||||
rt_thread_t tid;
|
||||
@ -330,10 +360,6 @@ static int ali_mqtt_init(void)
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
|
||||
tid = rt_thread_create("ali.chk", mqtt_connect_check_thread, RT_NULL, 512, RT_THREAD_PRIORITY_MAX / 2 + 1, 10);
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
INIT_APP_EXPORT(ali_mqtt_init);
|
||||
|
@ -20,12 +20,26 @@
|
||||
#define THREAD_TIMESLICE 5
|
||||
|
||||
static rt_thread_t tid1 = RT_NULL;
|
||||
static struct rt_mailbox sht30_mb;
|
||||
static char mb_pool[16];
|
||||
static struct rt_mailbox sht30_gfxmb;
|
||||
static struct rt_mailbox sht30_alimb;
|
||||
static char gfxmb_pool[16];
|
||||
static char alimb_pool[16];
|
||||
static sht3x_device_t sht3x_device = RT_NULL;
|
||||
sht3x_device_t get_sht30_singleshot(void)
|
||||
sht3x_device_t gfxget_sht30_singleshot(void)
|
||||
{
|
||||
if (rt_mb_recv(&sht30_mb, (rt_ubase_t *)&sht3x_device, RT_WAITING_FOREVER) == RT_EOK)
|
||||
if (rt_mb_recv(&sht30_gfxmb, (rt_ubase_t *)&sht3x_device, RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
return sht3x_device;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
}
|
||||
sht3x_device_t aliget_sht30_singleshot(void)
|
||||
{
|
||||
if (rt_mb_recv(&sht30_alimb, (rt_ubase_t *)&sht3x_device, RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
return sht3x_device;
|
||||
}
|
||||
@ -48,7 +62,8 @@ static void sht30_collect_thread_entry(void *parameter)
|
||||
{
|
||||
if(RT_EOK == sht3x_read_singleshot(sht3x_device))
|
||||
{
|
||||
rt_mb_send(&sht30_mb, (rt_uint32_t)sht3x_device);
|
||||
rt_mb_send(&sht30_gfxmb, (rt_uint32_t)sht3x_device);
|
||||
rt_mb_send(&sht30_alimb, (rt_uint32_t)sht3x_device);
|
||||
LOG_D("sht30 humidity : %d.%d ", (int)sht3x_device->humidity, (int)(sht3x_device->humidity * 10) % 10);
|
||||
LOG_D("temperature: %d.%d\n", (int)sht3x_device->temperature, (int)(sht3x_device->temperature * 10) % 10);
|
||||
}
|
||||
@ -64,11 +79,22 @@ static void sht30_collect_thread_entry(void *parameter)
|
||||
int sht30_collect(void)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
/* 初始化一个 mailbox */
|
||||
result = rt_mb_init(&sht30_mb,
|
||||
/* 初始化mailbox */
|
||||
result = rt_mb_init(&sht30_gfxmb,
|
||||
"sht30_mbt", /* 名称是 sht30_mbt */
|
||||
&mb_pool[0], /* 邮箱用到的内存池是 mb_pool */
|
||||
sizeof(mb_pool) / 4, /* 邮箱中的邮件数目,因为一封邮件占 4 字节 */
|
||||
&gfxmb_pool[0], /* 邮箱用到的内存池是 mb_pool */
|
||||
sizeof(gfxmb_pool) / 4, /* 邮箱中的邮件数目,因为一封邮件占 4 字节 */
|
||||
RT_IPC_FLAG_FIFO); /* 采用 FIFO 方式进行线程等待 */
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
LOG_D("init mailbox failed.\n");
|
||||
return -1;
|
||||
}
|
||||
/* 初始化mailbox */
|
||||
result = rt_mb_init(&sht30_alimb,
|
||||
"sht30_mbt", /* 名称是 sht30_mbt */
|
||||
&alimb_pool[0], /* 邮箱用到的内存池是 mb_pool */
|
||||
sizeof(alimb_pool) / 4, /* 邮箱中的邮件数目,因为一封邮件占 4 字节 */
|
||||
RT_IPC_FLAG_FIFO); /* 采用 FIFO 方式进行线程等待 */
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
extern "C"
|
||||
{
|
||||
sht3x_device_t get_sht30_singleshot(void);
|
||||
sht3x_device_t gfxget_sht30_singleshot(void);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -19,7 +19,7 @@ void Model::tick()
|
||||
{
|
||||
#ifndef SIMULATOR
|
||||
sht3x_device_t sht30_device;
|
||||
sht30_device = get_sht30_singleshot();
|
||||
sht30_device = gfxget_sht30_singleshot();
|
||||
if(sht30_device != RT_NULL)
|
||||
{
|
||||
modelListener->update_sensor_event(sht30_device);
|
||||
|
@ -117,6 +117,26 @@
|
||||
<pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon>
|
||||
</DebugOpt>
|
||||
<TargetDriverDllRegistry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>ARMRTXEVENTFLAGS</Key>
|
||||
<Name>-L70 -Z18 -C0 -M0 -T1</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGTARM</Key>
|
||||
<Name>(1010=-1,-1,-1,-1,0)(6017=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(6016=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>ARMDBGFLAGS</Key>
|
||||
<Name></Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGUARM</Key>
|
||||
<Name>(105=-1,-1,-1,-1,0)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>ST-LINKIII-KEIL_SWO</Key>
|
||||
@ -134,18 +154,25 @@
|
||||
</SetRegEntry>
|
||||
</TargetDriverDllRegistry>
|
||||
<Breakpoint/>
|
||||
<WatchWindow1>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>mqtt_sub_item</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<Tracepoint>
|
||||
<THDelay>0</THDelay>
|
||||
</Tracepoint>
|
||||
<DebugFlag>
|
||||
<trace>0</trace>
|
||||
<periodic>0</periodic>
|
||||
<aLwin>0</aLwin>
|
||||
<aLwin>1</aLwin>
|
||||
<aCover>0</aCover>
|
||||
<aSer1>0</aSer1>
|
||||
<aSer2>0</aSer2>
|
||||
<aPa>0</aPa>
|
||||
<viewmode>0</viewmode>
|
||||
<viewmode>1</viewmode>
|
||||
<vrSel>0</vrSel>
|
||||
<aSym>0</aSym>
|
||||
<aTbox>0</aTbox>
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#define RT_USING_DEVICE
|
||||
#define RT_USING_CONSOLE
|
||||
#define RT_CONSOLEBUF_SIZE 128
|
||||
#define RT_CONSOLEBUF_SIZE 512
|
||||
#define RT_CONSOLE_DEVICE_NAME "uart1"
|
||||
#define RT_VER_NUM 0x40002
|
||||
#define ARCH_ARM
|
||||
@ -189,8 +189,8 @@
|
||||
#define AT_DEVICE_USING_ESP8266
|
||||
#define AT_DEVICE_ESP8266_INIT_ASYN
|
||||
#define AT_DEVICE_ESP8266_SAMPLE
|
||||
#define ESP8266_SAMPLE_WIFI_SSID "ChinaNet-ssssss"
|
||||
#define ESP8266_SAMPLE_WIFI_PASSWORD "SQHWLK9394"
|
||||
#define ESP8266_SAMPLE_WIFI_SSID "xgld1"
|
||||
#define ESP8266_SAMPLE_WIFI_PASSWORD "xgld64627816"
|
||||
#define ESP8266_SAMPLE_CLIENT_NAME "uart3"
|
||||
#define ESP8266_SAMPLE_RECV_BUFF_LEN 512
|
||||
#define PKG_USING_AT_DEVICE_LATEST_VERSION
|
||||
|
Loading…
x
Reference in New Issue
Block a user