2024-11-15 02:30 AM - edited 2024-11-15 02:34 AM
I’m working on a project using an STM32F407G and a SIM7600 GSM module. After successfully sending AT commands via UART to configure the GSM module, I switched to PPPOS. I’m able to get a valid IP address, gateway, and netmask from the modem:
GSM: LTE_ppposInit
GSM: status_cb: Connected
GSM: ipaddr = 100.73.194.248
GSM: gateway = 10.64.64.64
GSM: netmask = 255.255.255.255
However, I’m encountering an issue with DNS resolution. Using netconn_gethostbyname, I can successfully resolve the IP for a hostname. But when I try using dns_gethostbyname, it fails with a DNS resolution error. The DNS server is correctly set (e.g., 1.1.1.1), but for some reason, dns_gethostbyname doesn’t work as expected. Here’s part of my code:
void dns_callback(const char *name, const ip_addr_t *ipaddr, void *arg) {
if (ipaddr != NULL) {
printf("Resolved IP: %s\n", ipaddr_ntoa(ipaddr));
} else {
printf("DNS resolution failed\n");
}
}
void resolve_hostname() {
ip_addr_t resolved_ip;
dns_init();
err_t err = dns_gethostbyname("test.mosquitto.org", &resolved_ip, dns_callback, NULL);
if (err == ERR_OK) {
printf("Resolved IP immediately: %s\n", ipaddr_ntoa(&resolved_ip));
} else if (err == ERR_INPROGRESS) {
printf("DNS resolution in progress\n");
} else {
printf("DNS resolution error: %d\n", err);
}
}
Any advice on why dns_gethostbyname might be failing even though netconn_gethostbyname works fine?