调试掉线重连
This commit is contained in:
parent
381b57f9f4
commit
15f3aa15d2
@ -123,45 +123,45 @@ static void ali_mqtt_rgb_ctrl_msg_arrive (void *pcontext, void *handle, iotx_mqt
|
||||
if (root == RT_NULL)
|
||||
{
|
||||
LOG_D("cJSON parse failed.");
|
||||
goto __door_ctrl_exit;
|
||||
goto __rgb_ctrl_exit;
|
||||
}
|
||||
|
||||
id = cJSON_GetObjectItem(root, "id");
|
||||
if (id == RT_NULL)
|
||||
{
|
||||
LOG_D("cJSON get object[id] failed.");
|
||||
goto __door_ctrl_exit;
|
||||
goto __rgb_ctrl_exit;
|
||||
}
|
||||
|
||||
params = cJSON_GetObjectItem(root, "params");
|
||||
if (params == RT_NULL)
|
||||
{
|
||||
LOG_D("cJSON get object[params] failed.");
|
||||
goto __door_ctrl_exit;
|
||||
goto __rgb_ctrl_exit;
|
||||
}
|
||||
|
||||
rgb_red = cJSON_GetObjectItem(params, "rgb_red");
|
||||
if (rgb_red == RT_NULL)
|
||||
{
|
||||
LOG_D("cJSON get object[rgb_red] failed.");
|
||||
goto __door_ctrl_exit;
|
||||
goto __rgb_ctrl_exit;
|
||||
}
|
||||
rgb_green = cJSON_GetObjectItem(params, "rgb_green");
|
||||
if (rgb_green == RT_NULL)
|
||||
{
|
||||
LOG_D("cJSON get object[rgb_green] failed.");
|
||||
goto __door_ctrl_exit;
|
||||
goto __rgb_ctrl_exit;
|
||||
}
|
||||
rgb_blue = cJSON_GetObjectItem(params, "rgb_blue");
|
||||
if (rgb_red == RT_NULL)
|
||||
{
|
||||
LOG_D("cJSON get object[rgb_blue] failed.");
|
||||
goto __door_ctrl_exit;
|
||||
goto __rgb_ctrl_exit;
|
||||
}
|
||||
LOG_D("rgb_red=%d;rgb_green=%d;rgb_blue=%d",
|
||||
rgb_red->valueint,rgb_green->valueint,rgb_blue->valueint );
|
||||
|
||||
__door_ctrl_exit:
|
||||
__rgb_ctrl_exit:
|
||||
if (root)
|
||||
cJSON_Delete(root);
|
||||
}
|
||||
@ -174,6 +174,7 @@ static void ali_mqtt_event_handle(void *pcontext, void *pclient, iotx_mqtt_event
|
||||
iotx_mqtt_topic_info_pt topic_info = (iotx_mqtt_topic_info_pt)msg->msg;
|
||||
if (topic_info == RT_NULL)
|
||||
{
|
||||
is_mqtt_disconnect = 1;
|
||||
LOG_D("Topic info is null! Exit.");
|
||||
return;
|
||||
}
|
||||
@ -286,83 +287,85 @@ static void mqtt_period_task()
|
||||
}
|
||||
static void mqtt_thread_main_thread(void *arg)
|
||||
{
|
||||
/* ȷ<><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)
|
||||
{
|
||||
struct netdev *netdev_link = netdev_get_first_by_flags(NETDEV_FLAG_LINK_UP);
|
||||
if (netdev_link)
|
||||
if (RT_NULL != mqtt_client_hd)
|
||||
{
|
||||
netdev_low_level_set_link_status(netdev_link, 1);
|
||||
break;
|
||||
}
|
||||
IOT_MQTT_Destroy(&mqtt_client_hd);
|
||||
mqtt_client_hd = RT_NULL;
|
||||
}
|
||||
if (topic_buff != RT_NULL)
|
||||
{
|
||||
rt_free(topic_buff);
|
||||
topic_buff = RT_NULL;
|
||||
}
|
||||
|
||||
topic_buff = mqtt_check_load_topic();
|
||||
if (topic_buff == RT_NULL)
|
||||
{
|
||||
LOG_D("Load MQTT Topic failed!");
|
||||
return;
|
||||
}
|
||||
/* Initialize MQTT parameter */
|
||||
iotx_mqtt_param_t mqtt_params;
|
||||
rt_memset(&mqtt_params, 0x0, sizeof(mqtt_params));
|
||||
|
||||
rt_thread_mdelay(rt_tick_from_millisecond(RT_TICK_PER_SECOND));
|
||||
}
|
||||
|
||||
if (topic_buff != RT_NULL)
|
||||
{
|
||||
rt_free(topic_buff);
|
||||
topic_buff = RT_NULL;
|
||||
}
|
||||
mqtt_params.customize_info = MQTT_MAN_INFO_STRING;
|
||||
|
||||
/* timeout of request. uint: ms */
|
||||
mqtt_params.request_timeout_ms = MQTT_REQUEST_TIMEOUT;
|
||||
/* internal of keepalive checking: 60s~300s */
|
||||
mqtt_params.keepalive_interval_ms = MQTT_KEEPALIVE_INTERNAL * 1000;
|
||||
/* default is 0 */
|
||||
mqtt_params.clean_session = 0;
|
||||
/* MQTT read/write buffer size */
|
||||
mqtt_params.read_buf_size = MQTT_MSGLEN;
|
||||
mqtt_params.write_buf_size = MQTT_MSGLEN;
|
||||
/* configure handle of event */
|
||||
mqtt_params.handle_event.h_fp = ali_mqtt_event_handle;
|
||||
mqtt_params.handle_event.pcontext = RT_NULL;
|
||||
|
||||
topic_buff = mqtt_check_load_topic();
|
||||
if (topic_buff == RT_NULL)
|
||||
{
|
||||
LOG_D("Load MQTT Topic failed!");
|
||||
return;
|
||||
}
|
||||
/* Initialize MQTT parameter */
|
||||
iotx_mqtt_param_t mqtt_params;
|
||||
rt_memset(&mqtt_params, 0x0, sizeof(mqtt_params));
|
||||
|
||||
mqtt_params.customize_info = MQTT_MAN_INFO_STRING;
|
||||
|
||||
/* timeout of request. uint: ms */
|
||||
mqtt_params.request_timeout_ms = MQTT_REQUEST_TIMEOUT;
|
||||
/* internal of keepalive checking: 60s~300s */
|
||||
mqtt_params.keepalive_interval_ms = MQTT_KEEPALIVE_INTERNAL * 1000;
|
||||
/* default is 0 */
|
||||
mqtt_params.clean_session = 0;
|
||||
/* MQTT read/write buffer size */
|
||||
mqtt_params.read_buf_size = MQTT_MSGLEN;
|
||||
mqtt_params.write_buf_size = MQTT_MSGLEN;
|
||||
/* configure handle of event */
|
||||
mqtt_params.handle_event.h_fp = ali_mqtt_event_handle;
|
||||
mqtt_params.handle_event.pcontext = RT_NULL;
|
||||
|
||||
/* construct a MQTT device with specify parameter */
|
||||
mqtt_client_hd = IOT_MQTT_Construct(&mqtt_params);
|
||||
if (RT_NULL == mqtt_client_hd)
|
||||
{
|
||||
LOG_D("construct MQTT failed!");
|
||||
}
|
||||
/* sbuscribe all topic */
|
||||
for (int i = 0; i < (sizeof(mqtt_sub_item) / sizeof(mqtt_subscribe_item)); i++)
|
||||
{
|
||||
if (mqtt_sub_item[i].topic_handle_func == RT_NULL)
|
||||
continue;
|
||||
|
||||
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)
|
||||
/* construct a MQTT device with specify parameter */
|
||||
mqtt_client_hd = IOT_MQTT_Construct(&mqtt_params);
|
||||
if (RT_NULL == mqtt_client_hd)
|
||||
{
|
||||
LOG_D("IOT_MQTT_Subscribe() failed, topic = %s", &topic_buff[i * 128]);
|
||||
LOG_D("construct MQTT failed!");
|
||||
}
|
||||
/* sbuscribe all topic */
|
||||
for (int i = 0; i < (sizeof(mqtt_sub_item) / sizeof(mqtt_subscribe_item)); i++)
|
||||
{
|
||||
if (mqtt_sub_item[i].topic_handle_func == RT_NULL)
|
||||
continue;
|
||||
|
||||
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]);
|
||||
}
|
||||
else
|
||||
LOG_D("IOT_MQTT_Subscribe success,topic=%s\r\n", &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);
|
||||
while (1)
|
||||
{
|
||||
/* handle the MQTT packet received from TCP or SSL connection */
|
||||
IOT_MQTT_Yield(mqtt_client_hd, 200);
|
||||
|
||||
/* ÿ10sִ<73><D6B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if ((mqtt_period_cnt % 50) == 0)
|
||||
while (1)
|
||||
{
|
||||
mqtt_period_task();
|
||||
if(is_mqtt_disconnect == 0)
|
||||
{
|
||||
/* handle the MQTT packet received from TCP or SSL connection */
|
||||
IOT_MQTT_Yield(mqtt_client_hd, 200);
|
||||
|
||||
/* ÿ10sִ<73><D6B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if ((mqtt_period_cnt % 50) == 0)
|
||||
{
|
||||
mqtt_period_task();
|
||||
}
|
||||
mqtt_period_cnt++;
|
||||
}else
|
||||
{
|
||||
LOG_D("thread_main_mqtt_disconnect = 1");
|
||||
rt_thread_mdelay(100);
|
||||
}
|
||||
}
|
||||
mqtt_period_cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
static void mqtt_connect_check_thread(void *arg)
|
||||
@ -376,40 +379,44 @@ static void mqtt_connect_check_thread(void *arg)
|
||||
{
|
||||
if (is_mqtt_disconnect >= 20)
|
||||
{
|
||||
netdev_link = netdev_get_first_by_flags(NETDEV_FLAG_LINK_UP);
|
||||
if (!rt_strcmp(netdev_link->name, "esp0"))
|
||||
{
|
||||
/* GPRSģ<53><C4A3><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>жϵ<D0B6><CFB5><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD> */
|
||||
netdev_link->ops->set_down(netdev_link);
|
||||
rt_thread_mdelay(rt_tick_from_millisecond(RT_TICK_PER_SECOND));
|
||||
netdev_link->ops->set_up(netdev_link);
|
||||
netdev_link = netdev_get_by_name("esp0");
|
||||
netdev_link->ops->set_down(netdev_link);
|
||||
rt_thread_mdelay(rt_tick_from_millisecond(RT_TICK_PER_SECOND));
|
||||
netdev_link->ops->set_up(netdev_link);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>жϵ<D0B6>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
while(netdev_is_internet_up(netdev_link) != 1)
|
||||
{
|
||||
rt_thread_mdelay(5000);
|
||||
}
|
||||
/* next period to check */
|
||||
is_mqtt_disconnect = 1;
|
||||
is_mqtt_disconnect = 0;
|
||||
LOG_D("connect_check_is_mqtt_disconnect = 0");
|
||||
}
|
||||
else
|
||||
{
|
||||
is_mqtt_disconnect++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
is_mqtt_disconnect = 0;
|
||||
LOG_D("is_mqtt_disconnect = 0");
|
||||
}
|
||||
}
|
||||
rt_thread_mdelay(rt_tick_from_millisecond(RT_TICK_PER_SECOND * 3));
|
||||
rt_thread_mdelay(100);
|
||||
}
|
||||
}
|
||||
static int ali_mqtt_init(void)
|
||||
int ali_mqtt_init(void)
|
||||
{
|
||||
rt_thread_t tid;
|
||||
|
||||
tid = rt_thread_create("ali.main", mqtt_thread_main_thread, RT_NULL, 6 * 1024, RT_THREAD_PRIORITY_MAX / 2, 10);
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
tid = rt_thread_create("mqtt.chk", mqtt_connect_check_thread, RT_NULL, 512, RT_THREAD_PRIORITY_MAX / 2 + 1, 10);
|
||||
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);
|
||||
MSH_CMD_EXPORT(ali_mqtt_init, ali_mqtt_init);
|
||||
//MSH_CMD_EXPORT(ali_mqtt_init, ali_mqtt_init);
|
||||
|
||||
|
@ -17,10 +17,10 @@
|
||||
|
||||
/* defined the LED0 pin: PH10 */
|
||||
#define LED0_PIN GET_PIN(H, 10)
|
||||
|
||||
extern int ali_mqtt_init(void);
|
||||
void netdev_callback(struct netdev *netdev, enum netdev_cb_type type)
|
||||
{
|
||||
rt_kprintf("IOT_MQTT_netdev_cb_type=%d\r\n", type);
|
||||
rt_kprintf("netdev_cb_type=%d\r\n", type);
|
||||
}
|
||||
int main(void)
|
||||
{
|
||||
@ -50,7 +50,7 @@ int main(void)
|
||||
{
|
||||
rt_kprintf("NTP sync fail.\n");
|
||||
}
|
||||
|
||||
ali_mqtt_init();
|
||||
while (count++)
|
||||
{
|
||||
rt_pin_write(LED0_PIN, PIN_HIGH);
|
||||
|
@ -117,10 +117,30 @@
|
||||
<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>
|
||||
<Name>-U52FF6B066570555010461587 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO11 -FD20000000 -FC6000 -FN2 -FF0STM32F7x_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F767IGTx$CMSIS\Flash\STM32F7x_1024.FLM) -FF1STM32F767_W25QXX -FS190000000 -FL11000000</Name>
|
||||
<Name>-U52FF6B066570555010461587 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP") -D00(5BA02477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO11 -FD20000000 -FC6000 -FN2 -FF0STM32F7x_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F767IGTx$CMSIS\Flash\STM32F7x_1024.FLM) -FF1STM32F767_W25QXX -FS190000000 -FL11000000</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
@ -140,12 +160,12 @@
|
||||
<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>
|
||||
@ -420,7 +440,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>Drivers</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
|
@ -188,8 +188,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