wifi.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "esp_err.h"
  3. #include "esp_wifi_types.h"
  4. #include <stdbool.h>
  5. /**
  6. * Initialize WiFi in both AP and STA modes
  7. * @param ap_ssid AP SSID (if NULL, uses default)
  8. * @param ap_password AP password (if NULL, uses default or open)
  9. */
  10. void wifi_init_apsta(const char *ap_ssid, const char *ap_password);
  11. /**
  12. * Block until WiFi is connected and has an IP address
  13. * @param timeout_ms Timeout in milliseconds (0 = wait forever)
  14. * @return true if connected, false if timeout
  15. */
  16. bool wifi_wait_connected(uint32_t timeout_ms);
  17. /**
  18. * Get the device MAC address as a string (XX:XX:XX:XX:XX:XX)
  19. */
  20. void wifi_get_mac_str(char *mac_str, size_t len);
  21. /**
  22. * Check if WiFi STA is connected
  23. */
  24. bool wifi_is_connected(void);
  25. /**
  26. * Get current IP address as string
  27. * @param ip_str Output buffer
  28. * @param len Buffer size
  29. * @return ESP_OK on success
  30. */
  31. esp_err_t wifi_get_ip_str(char *ip_str, size_t len);
  32. /**
  33. * Scan for available WiFi networks
  34. * @param ap_list Output array of AP info (caller must free)
  35. * @param ap_count Output: number of APs found
  36. * @return ESP_OK on success
  37. */
  38. esp_err_t wifi_scan(wifi_ap_record_t **ap_list, uint16_t *ap_count);
  39. /**
  40. * Disconnect and stop WiFi
  41. */
  42. void wifi_stop(void);
  43. /**
  44. * Set the DHCP hostname from the given device name.
  45. * Sanitizes to a valid DNS label (lowercase, hyphens for spaces/symbols).
  46. * Takes effect on the next DHCP transaction.
  47. */
  48. void wifi_set_hostname(const char *device_name);