WiFiSmartConfig.ino 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. *******************************************************************************
  3. * Copyright (c) 2022 by M5Stack
  4. * Equipped with M5Core sample source code
  5. * 配套 M5Core 示例源代码
  6. * Visit for more information: https://docs.m5stack.com/en/core/gray
  7. * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray
  8. *
  9. * Describe: WIFI Smart Config. WIFI智能配网
  10. * Date: 2021/7/30
  11. *******************************************************************************
  12. * Fill in WIFI configuration information through mobile APP to connect M5Core
  13. *to relevant WIFI 通过手机APP填写WIFI配置信息使 M5Core连接至相关WIFI APP
  14. *Download Address:
  15. *https://www.espressif.com/en/products/software/esp-touch/resources APP下载地址:
  16. *https://www.espressif.com/zh-hans/products/software/esp-touch/resources
  17. */
  18. #include <M5Stack.h>
  19. #include "WiFi.h"
  20. void setup() {
  21. M5.begin(); // Init M5Core. 初始化 M5Core
  22. M5.Power.begin(); // Init power 初始化电源模块
  23. WiFi.mode(WIFI_AP_STA); // Set the wifi mode to the mode compatible with
  24. // the AP and Station, and start intelligent
  25. // network configuration
  26. WiFi.beginSmartConfig(); // 设置wifi模式为AP 与 Station
  27. // 兼容模式,并开始智能配网
  28. // Wait for the M5Core to receive network information from the phone
  29. //等待M5Core接收到来自手机的配网信息
  30. M5.Lcd.println(
  31. "\nWaiting for Phone SmartConfig."); // Screen print format string.
  32. // 屏幕打印格式化字符串
  33. while (!WiFi.smartConfigDone()) { // If the smart network is not completed.
  34. // 若智能配网没有完成
  35. delay(500);
  36. M5.Lcd.print(".");
  37. }
  38. M5.Lcd.println("\nSmartConfig received.");
  39. M5.Lcd.println("Waiting for WiFi");
  40. while (
  41. WiFi.status() !=
  42. WL_CONNECTED) { // M5Core will connect automatically upon receipt of
  43. // the configuration information, and return true if
  44. // the connection is successful.
  45. // 收到配网信息后M5Core将自动连接,若连接成功将返回true
  46. delay(500);
  47. M5.Lcd.print(".");
  48. }
  49. M5.Lcd.print("\nWiFi Connect To: ");
  50. M5.Lcd.println(WiFi.SSID()); // Output Network name. 输出网络名称
  51. M5.Lcd.print("IP address: ");
  52. M5.Lcd.println(WiFi.localIP()); // Output IP Address. 输出IP地址
  53. M5.Lcd.print("RSSI: ");
  54. M5.Lcd.println(WiFi.RSSI()); // Output signal strength. 输出信号强度
  55. }
  56. void loop() {}