Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <ESP8266HTTPClient.h>
  3.  
  4.  
  5. const char* ssid = "ZON-6860";
  6. const char* password = "b90979db9305";
  7.  
  8.  
  9. // Expose Espressif SDK functionality - wrapped in ifdef so that it still
  10. // compiles on other platforms
  11. #ifdef ESP8266
  12. extern "C" {
  13. #include "user_interface.h"
  14. #include "Esp.h"
  15.  
  16. }
  17. #endif
  18.  
  19. void setup() {
  20. Serial.begin(115200);
  21. #ifdef ESP8266
  22. extern "C" {
  23. void ICACHE_FLASH_ATTR user_ping_recv(void *arg, void *pdata){
  24. struct ping_resp *ping_resp = pdata;
  25. struct ping_option *ping_opt = arg;
  26.  
  27. if (ping_resp->ping_err == -1)
  28. os_printf("ping host fail \r\n");
  29. else
  30. os_printf("ping recv: byte = %d, time = %d ms \r\n",ping_resp->bytes,ping_resp->resp_time);
  31.  
  32. }
  33.  
  34. void ICACHE_FLASH_ATTR user_ping_sent(void *arg, void *pdata){
  35. os_printf("user ping finish \r\n");
  36. }
  37.  
  38.  
  39. void ICACHE_FLASH_ATTR user_test_ping(void){
  40. struct ping_option *ping_opt = NULL;
  41. const char* ping_ip = "192.168.1.5";
  42.  
  43. ping_opt = (struct ping_option *)os_zalloc(sizeof(struct ping_option));
  44.  
  45. ping_opt->count = 10; // try to ping how many times
  46. ping_opt->coarse_time = 2; // ping interval
  47. ping_opt->ip = ipaddr_addr(ping_ip);
  48.  
  49. ping_regist_recv(ping_opt,user_ping_recv);
  50. ping_regist_sent(ping_opt,user_ping_sent);
  51.  
  52. ping_start(ping_opt);
  53.  
  54. }
  55. }
  56. #endif
  57.  
  58.  
  59. delay(10);
  60.  
  61. // We start by connecting to a WiFi network
  62.  
  63. Serial.println();
  64. Serial.println();
  65. Serial.print("Connecting to ");
  66. Serial.println(ssid);
  67.  
  68. WiFi.begin(ssid, password);
  69.  
  70. while (WiFi.status() != WL_CONNECTED) {
  71. delay(500);
  72. Serial.print(".");
  73. }
  74.  
  75. Serial.println("");
  76. Serial.println("WiFi connected");
  77. Serial.println("IP address: ");
  78. Serial.println(WiFi.localIP());
  79. }
  80.  
  81. void loop() {
  82. // Call Espressif SDK functionality - wrapped in ifdef so that it still
  83. // compiles on other platforms
  84. #ifdef ESP8266
  85. Serial.print("wifi_station_get_hostname: ");
  86. Serial.println(wifi_station_get_hostname());
  87. Serial.println(ESP.getChipId());
  88.  
  89. #endif
  90.  
  91. Serial.println(WiFi.localIP());
  92.  
  93.  
  94.  
  95.  
  96.  
  97. delay(1000);
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement