location_client.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include <rtthread.h>
  2. #include <wlan_mgnt.h>
  3. #include <wifi_config.h>
  4. #include <webclient.h>
  5. #include <ntp_client.h>
  6. #include <wayz_pos.h>
  7. #ifdef PKG_WAYZ_IOTKIT_WIFI_SSID
  8. #define WAYZ_WIFI_SSID PKG_WAYZ_IOTKIT_WIFI_SSID
  9. #else
  10. #define WAYZ_WIFI_SSID "thread"
  11. #endif
  12. #ifdef PKG_WAYZ_IOTKIT_WIFI_PASSWORD
  13. #define WAYZ_WIFI_PWD PKG_WAYZ_IOTKIT_WIFI_PASSWORD
  14. #else
  15. #define WAYZ_WIFI_PWD "12345678"
  16. #endif
  17. #define DEV_NAME "PANDDRA"
  18. #define VENDER "ALIENTEK"
  19. #define PRODUCT "FINDU01"
  20. #define SN "1234567"
  21. #define TENANT "WAYZ"
  22. #define POINT_FRQ 3000
  23. #define ACCESS_KEY "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // 需要申请
  24. static void location_client_entry(void *parament)
  25. {
  26. char mac_addr[17] = {0};
  27. char ret = 0;
  28. get_sta_mac_addr(mac_addr);
  29. rt_kprintf("station mac : %s \r\n", mac_addr);
  30. twifi_info *wlan_info;
  31. tdeviec_info *dev_info;
  32. wlan_info = wifi_param_init(WAYZ_WIFI_SSID, WAYZ_WIFI_PWD);
  33. dev_info = dev_para_init(DEV_NAME, VENDER, PRODUCT, SN, TENANT);
  34. ret = dev_register_init(wlan_info, dev_info, ACCESS_KEY);
  35. if (ret != DEV_REGISTER_OK)
  36. {
  37. rt_kprintf("\033[31;22mdevice register failure. \033[0m\n");
  38. return ;
  39. }
  40. tlocation_info location = {0};
  41. ret = get_position_info(wlan_info, ACCESS_KEY, RT_NULL, &location);
  42. if (RT_ERROR == ret)
  43. {
  44. rt_kprintf("\033[31;22mthe device failed to obtain latitude and longitude information.\033[0m\n");
  45. }
  46. else
  47. {
  48. location_print(location);
  49. }
  50. while (1)
  51. {
  52. ret = get_position_info(wlan_info, ACCESS_KEY, RT_NULL, &location);
  53. if (RT_ERROR == ret)
  54. {
  55. rt_kprintf("\033[31;22mthe device failed to obtain latitude and longitude information.\033[0m\n");
  56. }
  57. else
  58. {
  59. location_print(location);
  60. }
  61. rt_thread_mdelay(POINT_FRQ);
  62. rt_memset(&location, 0, sizeof (location));
  63. }
  64. }
  65. int location_client_start(void)
  66. {
  67. rt_thread_t tid;
  68. tid = rt_thread_create("location_client", location_client_entry, RT_NULL, 6 * 1024, RT_THREAD_PRIORITY_MAX / 3 - 1, 5);
  69. if (tid)
  70. {
  71. rt_thread_startup(tid);
  72. return RT_EOK;
  73. }
  74. return -RT_ERROR;
  75. }
  76. #ifdef RT_USING_FINSH
  77. #include <finsh.h>
  78. FINSH_FUNCTION_EXPORT_ALIAS(location_client_start, location_test, location client test start);
  79. #ifdef FINSH_USING_MSH
  80. MSH_CMD_EXPORT_ALIAS(location_client_start, location_test, location client test start);
  81. #endif
  82. #endif