Author Topic: No Oak ping command?  (Read 2934 times)

Last_Mile

  • Newbie
  • *
  • Posts: 15
No Oak ping command?
« on: March 07, 2017, 03:03:37 pm »
I've been searching posts and the documentation.  I see no means of the Oak to send a ping over the wifi link.  Is there a reason there is no low level ping?

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: No Oak ping command?
« Reply #1 on: March 08, 2017, 02:22:32 am »
I've used the ESP8266Ping library when I needed ping on the ESP8266 or Oak. It should be available in the Arduino IDE library manager. If not, you can download it from https://github.com/dancol90/ESP8266Ping

Below is some code I wrote to test if it worked on the Oak, pinging a specific server on my network. It does a double flash if the ping is successful, or a single flash if it fails.

Code: [Select]
/*
 * With this library an ESP8266 can ping a remote machine and know if it's reachable.
 * It provides some basic measurements on ping messages (avg response time).
 */

#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>

const IPAddress remote_ip(192, 168, 0, 5);

void setup() {
  Serial.begin(115200);
  delay(10);
  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println("Connecting to WiFi");
 
  WiFi.begin();
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    Serial.print(".");
  }

  Serial.println();
  Serial.print("WiFi connected with ip "); 
  Serial.println(WiFi.localIP());

  Serial.print("Pinging ip ");
  Serial.println(remote_ip);

  pinMode(1,OUTPUT);

  if(Ping.ping(remote_ip)) {
    while(1)
    {
      digitalWrite(1,HIGH);
      delay(100);
      digitalWrite(1,LOW);
      delay(100);
      digitalWrite(1,HIGH);
      delay(100);
      digitalWrite(1,LOW);
      delay(1700);
    }
  } else {
    while(1)
    {
      digitalWrite(1,HIGH);
      delay(200);
      digitalWrite(1,LOW);
      delay(1800);
    }
  }
}

void loop() { }

Last_Mile

  • Newbie
  • *
  • Posts: 15
Re: No Oak ping command?
« Reply #2 on: March 13, 2017, 03:13:24 pm »
I'm new at this, so it took me a while to figure out how to use the ping library, but it works.  I was confused at first because five pings are actually sent out.  I would have thought ping would have been in the base libraries, but this does just fine.

Thank you very much.

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: No Oak ping command?
« Reply #3 on: March 13, 2017, 08:00:16 pm »
No problem. If you want to have a different number of pings than the default, you can specify that as a second parameter...

Code: [Select]
Ping.ping(ip_or_host, 10);