优化了一下网络连接,

This commit is contained in:
小马_666 2025-06-10 17:22:59 +08:00
parent a26e8a73b5
commit b274562f53
4 changed files with 571 additions and 509 deletions

View File

@ -2,7 +2,7 @@
* @Author: mbw
* @Date: 2024-10-23 17:14:16
* @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2025-06-06 08:48:12
* @LastEditTime: 2025-06-06 14:00:40
* @FilePath: \ble_bjq_ch303rct6_ml307\applications\main.c
* @Descrt_thread_
*
@ -302,7 +302,7 @@ int main(void)
LOG_D("工作时长:%d", work_duration);
// 读取历史记录总数
g_Calibration_status = Flash_Get_Calibration_State();
rt_thread_mdelay(100);
rt_thread_mdelay(10);
}
else
{

View File

@ -127,6 +127,7 @@ void TEST_Ml307_Reset(void)
{
Ml307_Reset (RT_NULL);
}
MSH_CMD_EXPORT (TEST_Ml307_Reset, "test_ml307_reset");
#endif
@ -863,6 +864,7 @@ int Time_Calibration(struct at_device *device)
at_delete_resp (resp);
return RT_ERROR;
}
/* ============================= ml307 device operations ============================= */
#define AT_SEND_CMD(client, resp, resp_line, timeout, cmd) \
@ -874,6 +876,7 @@ int Time_Calibration(struct at_device *device)
goto __exit; \
} \
} while (0)
/* initialize for ml307 */
static void ml307_init_thread_entry (void *parameter)
{
@ -915,6 +918,11 @@ static void ml307_init_thread_entry(void *parameter)
result = -RT_ETIMEOUT;
goto __exit;
}
if (at_obj_exec_cmd(device->client, resp, "AT+MCFG=\"simhot\",0") != RT_EOK)
{
result = -RT_ERROR;
goto __exit;
}
/* disable echo */
AT_SEND_CMD (client, resp, 0, ML307_AT_DEFAULT_TIMEOUT, "ATE0");
/* get module version */
@ -1031,7 +1039,11 @@ static void ml307_init_thread_entry(void *parameter)
result = -RT_ERROR;
goto __exit;
}
if (at_obj_exec_cmd (device->client, resp, "AT+CGATT=1") != RT_EOK)
{
result = -RT_ERROR;
goto __exit;
}
char parsed_data[10] = {0};
for (i = 0; i < CGATT_RETRY; i++)
{
@ -1108,7 +1120,11 @@ static void ml307_init_thread_entry(void *parameter)
rt_memset ((char *)ml307.imsi, 0, ML307_IMSI_LEN);
Get_IotImsi ((char *)&ml307.imsi[0], ML307_IMSI_LEN);
}
if (at_obj_exec_cmd (device->client, resp, "AT+CEREG=1") != RT_EOK)
{
result = -RT_ERROR;
goto __exit;
}
/* check the GPRS network is registered */
for (i = 0; i < CEREG_RETRY; i++)
{
@ -1133,12 +1149,11 @@ static void ml307_init_thread_entry(void *parameter)
result = -RT_ERROR;
goto __exit;
}
// if (at_obj_exec_cmd(device->client, resp, "AT+MIPCALL=1,1") != RT_EOK)
// // if (at_obj_exec_cmd(device->client, resp, "AT+MIPCALL=0") != RT_EOK)
// {
// result = -RT_ERROR;
// goto __exit;
// }
if (at_obj_exec_cmd(device->client, resp, "AT+MIPCALL=1,1") != RT_EOK)
{
result = -RT_ERROR;
goto __exit;
}
#if defined(AT_DEBUG)
/* check the GPRS network IP address */
for (i = 0; i < IPADDR_RETRY; i++)
@ -1474,6 +1489,7 @@ int ml307_device_class_register(void)
return at_device_class_register (class, AT_DEVICE_CLASS_ML307);
}
// INIT_DEVICE_EXPORT(ml307_device_class_register);
#endif //! IOT_MODULE_SWITCH

View File

@ -2,7 +2,7 @@
* @Author: mbw
* @Date: 2024-11-30 15:46:21
* @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2025-06-06 08:37:07
* @LastEditTime: 2025-06-06 14:02:27
* @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_ml307.c
* @Description:
*
@ -310,7 +310,6 @@ uint8_t dec_to_bcd(uint8_t dec)
return ((dec / 10) << 4) | (dec % 10);
}
int test (int argc, char **argv)
{
uint8_t a = atoi (argv[1]);
@ -322,8 +321,8 @@ int test(int argc, char **argv)
LOG_D ("in = 0x%02X, %d", b, b);
return b;
}
MSH_CMD_EXPORT(test, "test");
MSH_CMD_EXPORT (test, "test");
int _Update_Valve_Data (struct Ml307_Ops *ops)
{
@ -986,6 +985,7 @@ int Ml307_Process_Events (Ml307Event ml307_recv_event, struct at_device *device,
#ifdef TEST_ENABLE
RTC_ShowTime(); // 每次发送打印下时间,容易定位问题
#endif
cnt++;
LOG_D ("%s上报, cnt :%d", event->event_name, cnt);
int result = event->send_func (device, ml307_ops);
@ -1008,7 +1008,6 @@ int Ml307_Process_Events (Ml307Event ml307_recv_event, struct at_device *device,
{
// 收不到说明在平台未注册或者信号不行,此时ml307_connect_sever_flag 为0但ml307_conncet_tcp_flag = 1此时不发起重连等待事件触发就行
ret = RT_ERROR;
}
}
}
@ -2026,6 +2025,32 @@ static void Ml307_Life_Thread_Entry (void *parameter)
goto __exit;
}
rt_uint8_t i = 0;
/* check the GPRS network is registered */
for (i = 0; i < 10; i++)
{
if (at_obj_exec_cmd (device->client, resp, "AT+CEREG?") == RT_EOK)
{
int link_stat = 0;
if (at_resp_parse_line_args_by_kw (resp, "+CEREG:", "+CEREG: %*d,%d", &link_stat) > 0)
{
if ((link_stat == 1) || (link_stat == 5))
{
LOG_D ("%s device GPRS is registered", device->name);
break;
}
}
}
rt_thread_mdelay (1000);
}
if (i == 10)
{
LOG_E ("%s device GPRS is register failed", device->name);
result = -RT_ERROR;
goto __exit;
}
/* check SIM card */
for (i = 0; i < 60; i++)
{
@ -2072,7 +2097,28 @@ static void Ml307_Life_Thread_Entry (void *parameter)
result = -RT_ERROR;
goto __exit;
}
for (i = 0; i < 60; i++)
{
if (at_obj_exec_cmd (device->client, resp, "AT+CGACT=1") == RT_EOK)
{
LOG_D ("pdp激活成功");
break;
}
else
{
// AT+CGACT=0,1 //去激活 PDP
if (at_obj_exec_cmd (device->client, resp, "AT+CGACT=0") == RT_EOK)
{
LOG_D ("pdp去激活成功");
}
}
rt_thread_mdelay (5000);
}
if (i == 60)
{
result = -RT_ERROR;
goto __exit;
}
/* check the GPRS network is registered */
for (i = 0; i < 60; i++)
{

View File

@ -134,7 +134,7 @@
#define RT_USING_AT
// #define NETDEV_USING_PING//用来监测和平台之间的延时
#ifdef ENABLE_LOG_ALL
// #define AT_DEBUG
#define AT_DEBUG
#endif
#define AT_USING_CLIENT