Skip to content

Instantly share code, notes, and snippets.

@Links2004
Last active Jan 23, 2016
Embed
What would you like to do?
ping.cpp
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include "Esp.h"
const char* ssid = "ZON-6860";
const char* password = "b90979db9305";
extern "C" {
#include "user_interface.h"
}
void user_ping_recv(void *arg, void *pdata){
struct ping_resp *ping_resp = (struct ping_resp *)pdata;
struct ping_option *ping_opt = (struct ping_option *)arg;
if (ping_resp->ping_err == -1)
os_printf("ping host fail \r\n");
else
os_printf("ping recv: byte = %d, time = %d ms \r\n",ping_resp->bytes,ping_resp->resp_time);
}
void user_ping_sent(void *arg, void *pdata){
os_printf("user ping finish \r\n");
}
void user_test_ping(void){
struct ping_option *ping_opt = NULL;
const char* ping_ip = "192.168.1.114";
ping_opt = (struct ping_option *)malloc(sizeof(struct ping_option));
ping_opt->count = 10; // try to ping how many times
ping_opt->coarse_time = 2; // ping interval
ping_opt->ip = ipaddr_addr(ping_ip);
ping_regist_recv(ping_opt,user_ping_recv);
ping_regist_sent(ping_opt,user_ping_sent);
ping_start(ping_opt);
}
void setup() {
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
Serial.print("wifi_station_get_hostname: ");
Serial.println(wifi_station_get_hostname());
Serial.println(ESP.getChipId());
Serial.println(WiFi.localIP());
user_test_ping();
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment