How to ping or get MAC Address to check if alive?

Tried figuring out how to use it.....

void setup() {
int IP[4];
IP[0] = 192;
IP[1] = 168;
IP[2] = 1;
IP[3] = 1;

pinMode(D7,OUTPUT);
digitalWrite(D7,HIGH);
//netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, unsigned long ulPingSize, unsigned long ulPingTimeout)
netapp_ping_send((unsigned long *)IP,4,4,100);

}

void loop() {
digitalWrite(D7,HIGH);
delay(200);
digitalWrite(D7,LOW);
delay(200);
}

I posted about this over here:

2 Likes

@bko awesome!

I was trying hard to figure out how to get the netapp_ping_report()…

possible?

@timolol,

@bko has an example code working!

2 Likes

I just tested this with a known working and known not working address and the “success” is not if the host answers or not–just if the ping was sent (which I see going by). Id see the pings going out on my router.

The netapp_ping_report looks like it is declared wrong since it does not return the value of the struct with the data.

1 Like

I’m guessing what everyone here really nts is some kind of reduced functionality nmap (find devices and mac addresses).

I just wanted to let everyone know that I am trying to get the ping report working but it is not working yet.

Even with the ping report, you will not get the MAC address of the remote host, you get packets sent, packets received, minimum round trip time, maximum round trip time, and average round trip time.

I report back here when I get some better news.

3 Likes

Thank you for your help and expertise, @bko! :slight_smile:

OK, I have something that works and will get my pull request together and merge against the upcoming RSSI feature. It currently looks like this:

  unsigned long packetsReceived = Network.ping(IPAddress(10,0,0,2));
  //or try 10 times instead of the default 5 
  unsigned long packetsReceived2 = Network.ping(IPAddress(10,0,0,2), 10);

There are some interesting trade-offs to be made here since the local subnet is very fast (3-5ms round-trip typically) but from where I am to spark.io is 140ms round-trip, so that the timeout value has to be fairly large (500ms). There may be more work to do here to avoid cloud disconnect.

I was able to ping my iOS gizmo on the local subnet and see quick results and then put it in airplane mode and see the zero packetsReceived. I was also able to ping some well-known hosts on the broader internet.

Special thanks to @david_s5 for a boost on this one!

3 Likes

awesome! initial help changed into code improvement for all the :spark: owners :wink:

For those who are interested and can build locally:

Test program:

#include "application.h"

IPAddress google(74,125,225,52);
IPAddress yahoo(98,139,180,149);
IPAddress spark(62,116,130,8);

void setup() {
    Serial.begin(9600);
    delay(2000);
}

void loop() {
  Serial.print("G: ");
  Serial.println(Network.ping(google));
  Serial.print(" Y: ");
  Serial.println(Network.ping(yahoo));
  Serial.print(" S: ");
  Serial.println(Network.ping(spark));    
  Serial.print(" Fail: ");
  Serial.println(Network.ping(IPAddress(10,0,0,200)));    
  delay(10000);
}

Printing ‘5’ for the first three meaning 5 successful pings out of 5 and 0 for the last one is correct. You may need to change the IPAddress of the fail test to something not in use on your network.

2 Likes

I’ve been reading the forums for anything related to MAC address, and this is the closest thread I could find, so here goes:

I need to get the MAC address of my core in order to claim it. The Wifi network I am on is MAC-address filtered. It’s a school network and I am not the administrator of it, so I can’t check the router logs to get the MAC addresses. And it seems I can’t upload sketches in any way to the core until I claim it. So at the moment, it’s a brick until I get on another network or get the MAC address so I can register it on the school network.

Any solutions? Is there something I am missing?

@tigoe, look at the documentation for the function Network.macAddress().

http://docs.spark.io/firmware/#connection-management-network

Besides OTA, you can also flash your Core over USB using Spark CLI. :smile:

1 Like

Do you have spark-cli installed?

We can upload a code which disables Wifi and prints out the Mac address via serial for you to record down. :wink:

@peekay123, why did you reply so fast?! :stuck_out_tongue:

2 Likes

What about connecting it to your mobile phone AP, androids will tell you mac address of connected devices (not sure if iPhones do or not). you could use a serial terminal to input the SSID, security and password. Just put the core in listening mode and start the terminal and type ‘w’ and follow the prompts. full instructions for connecting with the terminal can be found on the docs site…

Am i right in thinking you need to get the mac address to give to the school so they can add it to the allowed list?

1 Like

@Hootie81 you are correct in thinking that, I need the MAC address so I can register it with the school, then it’ll be allowed to connect to the network.

@peekay123 I looked at the Network API, and tried to upload via the CLI, but it wouldn’t flash the core. I assumed it was because this core is not yet registered with my account, which I can’t do until it can get on the network, which it can’t do until I get and MAC address. It’s a chicken-egg problem.

Oh also, @Hootie81, the phone app won’t recognize a core that’s not connected to the same network it’s connected to. And my device is not yet connected to that network.

The way i was suggesting you wont be able to use the phone app to connect the core.

If you turn on the ‘access point’ or ‘wifi hotspot’ on your phone and connect the core to that.

to set the SSID and password on your core you will need to use the usb port and connect with a terminal. or borrow someone elses phone and connect that to your hotspot and use it to setup the core…

@tigoe, you don’t need to have a core claimed to flash your code via USB. However, because the core will not connect to the wifi/cloud, the user code will not run to see the MAC.

I think you could use your phone as an AP and then claim your core via USB using the CLI.

@tigoe, to go about doing this, simply connect with Serial Terminal and hit w

Setup an SSID with security type = OPEN.

Once you have done so, turn on the Hotspot on your mobile phone and setup the same SSID + Open network.

The core should connect and you will be able to see the MAC. :smiley: