user_main.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /******************************************************************************
  2. * Copyright 2013-2014 Espressif Systems (Wuxi)
  3. *
  4. * FileName: user_main.c
  5. *
  6. * Description: entry file of user application
  7. *
  8. * Modification history:
  9. * 2014/1/1, v1.0 create this file.
  10. *******************************************************************************/
  11. #include "ets_sys.h"
  12. #include "osapi.h"
  13. #include "user_interface.h"
  14. #include "smartconfig.h"
  15. void ICACHE_FLASH_ATTR
  16. smartconfig_done(sc_status status, void *pdata)
  17. {
  18. switch(status) {
  19. case SC_STATUS_WAIT:
  20. os_printf("SC_STATUS_WAIT\n");
  21. break;
  22. case SC_STATUS_FIND_CHANNEL:
  23. os_printf("SC_STATUS_FIND_CHANNEL\n");
  24. break;
  25. case SC_STATUS_GETTING_SSID_PSWD:
  26. os_printf("SC_STATUS_GETTING_SSID_PSWD\n");
  27. sc_type *type = pdata;
  28. if (*type == SC_TYPE_ESPTOUCH) {
  29. os_printf("SC_TYPE:SC_TYPE_ESPTOUCH\n");
  30. } else {
  31. os_printf("SC_TYPE:SC_TYPE_AIRKISS\n");
  32. }
  33. break;
  34. case SC_STATUS_LINK:
  35. os_printf("SC_STATUS_LINK\n");
  36. struct station_config *sta_conf = pdata;
  37. wifi_station_set_config(sta_conf);
  38. wifi_station_disconnect();
  39. wifi_station_connect();
  40. break;
  41. case SC_STATUS_LINK_OVER:
  42. os_printf("SC_STATUS_LINK_OVER\n");
  43. if (pdata != NULL) {
  44. uint8 phone_ip[4] = {0};
  45. os_memcpy(phone_ip, (uint8*)pdata, 4);
  46. os_printf("Phone ip: %d.%d.%d.%d\n",phone_ip[0],phone_ip[1],phone_ip[2],phone_ip[3]);
  47. }
  48. smartconfig_stop();
  49. break;
  50. }
  51. }
  52. void user_rf_pre_init(void)
  53. {
  54. }
  55. void user_init(void)
  56. {
  57. os_printf("SDK version:%s\n", system_get_sdk_version());
  58. smartconfig_set_type(SC_TYPE_ESPTOUCH); //SC_TYPE_ESPTOUCH,SC_TYPE_AIRKISS,SC_TYPE_ESPTOUCH_AIRKISS
  59. wifi_set_opmode(STATION_MODE);
  60. smartconfig_start(smartconfig_done);
  61. }