|
|
@@ -22,6 +22,7 @@
|
|
|
#define ESP32_WAIT_CONNECT_TIME 5000
|
|
|
#define ESP32_THREAD_STACK_SIZE 2048
|
|
|
#define ESP32_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 2)
|
|
|
+unsigned int ESP32_GMR_AT_VERSION;
|
|
|
|
|
|
/* ============================= esp32 network interface operations ============================= */
|
|
|
|
|
|
@@ -408,7 +409,8 @@ static int esp32_netdev_ping(struct netdev *netdev, const char *host,
|
|
|
}
|
|
|
|
|
|
/* parse the third line of response data, get the IP address */
|
|
|
- if (at_resp_parse_line_args_by_kw(resp, "+CIPDOMAIN:", "+CIPDOMAIN:\"%[^\"]\"", ip_addr) < 0)
|
|
|
+ if (at_resp_parse_line_args_by_kw(resp, "+CIPDOMAIN:", (esp32_get_at_version() <= ESP32_DEFAULT_AT_VERSION_NUM) ? \
|
|
|
+ "+CIPDOMAIN:%s" : "+CIPDOMAIN:\"%[^\"]\"", ip_addr) < 0)
|
|
|
{
|
|
|
result = -RT_ERROR;
|
|
|
goto __exit;
|
|
|
@@ -421,7 +423,8 @@ static int esp32_netdev_ping(struct netdev *netdev, const char *host,
|
|
|
goto __exit;
|
|
|
}
|
|
|
|
|
|
- if (at_resp_parse_line_args_by_kw(resp, "+", "+PING:%d", &req_time) < 0)
|
|
|
+ if (at_resp_parse_line_args_by_kw(resp, "+", (esp32_get_at_version() <= ESP32_DEFAULT_AT_VERSION_NUM) ?
|
|
|
+ "+%d" : "+PING:%d", &req_time) < 0)
|
|
|
{
|
|
|
result = -RT_ERROR;
|
|
|
goto __exit;
|
|
|
@@ -638,6 +641,7 @@ static void esp32_init_thread_entry(void *parameter)
|
|
|
AT_SEND_CMD(client, resp, "AT+CWMODE=1");
|
|
|
/* get module version */
|
|
|
AT_SEND_CMD(client, resp, "AT+GMR");
|
|
|
+ ESP32_GMR_AT_VERSION = esp32_at_version_to_hex(at_resp_get_line(resp, 1));
|
|
|
/* show module version */
|
|
|
for (i = 0; i < resp->line_counts - 1; i++)
|
|
|
{
|
|
|
@@ -930,4 +934,57 @@ static int esp32_device_class_register(void)
|
|
|
}
|
|
|
INIT_DEVICE_EXPORT(esp32_device_class_register);
|
|
|
|
|
|
+/**
|
|
|
+ * Convert the ESP32 AT version string to hexadecimal
|
|
|
+ *
|
|
|
+ * @param string containing the AT version
|
|
|
+ *
|
|
|
+ * @return hex_number: Hexadecimal AT version number, example: 1.4.1.1 -> 0x1040101
|
|
|
+ */
|
|
|
+unsigned int esp32_at_version_to_hex(const char *str)
|
|
|
+{
|
|
|
+ const char *version_prefix = "AT version:";
|
|
|
+ char *version_start;
|
|
|
+ unsigned int numbers[4];
|
|
|
+ unsigned int hex_number;
|
|
|
+
|
|
|
+ if (str == NULL || *str == '\0')
|
|
|
+ {
|
|
|
+ LOG_E("Invalid AT version format\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Get AT version string */
|
|
|
+ version_start = strstr(str, version_prefix);
|
|
|
+ if (version_start)
|
|
|
+ {
|
|
|
+ if (sscanf(version_start, "AT version:%d.%d.%d.%d", &numbers[0], &numbers[1], &numbers[2], &numbers[3]) == 4)
|
|
|
+ {
|
|
|
+
|
|
|
+ hex_number = (numbers[0] << 24) | (numbers[1] << 16) | (numbers[2] << 8) | numbers[3];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LOG_W("The AT instruction format is not standard\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LOG_W("The AT+GMR instruction is not supported\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return hex_number;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * This function is used to obtain the ESP32 AT version number.
|
|
|
+ *
|
|
|
+ * @return hex_number: Hexadecimal AT version number, example: 1.4.1.1 -> 0x1040101
|
|
|
+ */
|
|
|
+unsigned int esp32_get_at_version(void)
|
|
|
+{
|
|
|
+ return ESP32_GMR_AT_VERSION;
|
|
|
+}
|
|
|
#endif /* AT_DEVICE_USING_ESP32 */
|