I would like to simply ping both some local IPs and global IPs to check if they are alive (+/- returning the ping time). I am still new to Arduino and was wondering if there would be an easier way than attempting to establish a TCP connection?
Is it possible to obtain the MAC address of a device that is connected to the local network (given I have assigned the device a static local IP)?
Hmm, you could always grab the mac address from your router / dhcp table if you wanted!
I think the CC3000 driver has a ping function built in that you could use (from netapp.h in core-common-lib) https://github.com/spark/core-common-lib/blob/master/CC3000_Host_Driver/netapp.c
//*****************************************************************************
//
//! netapp_ping_send
//!
//! @param ip destination IP address
//! @param pingAttempts number of echo requests to send
//! @param pingSize send buffer size which may be up to 1400 bytes
//! @param pingTimeout Time to wait for a response,in milliseconds.
//!
//! @return return on success 0, otherwise error.
//!
//! @brief send ICMP ECHO_REQUEST to network hosts
//!
//! @note If an operation finished successfully asynchronous ping report
//! event will be generated. The report structure is as defined
//! by structure netapp_pingreport_args_t.
//!
//! @warning Calling this function while a previous Ping Requests are in
//! progress will stop the previous ping request.
//*****************************************************************************
#ifndef CC3000_TINY_DRIVER
extern long netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, unsigned long ulPingSize, unsigned long ulPingTimeout);
#endif
//*****************************************************************************
//
//! netapp_ping_stop
//!
//! @param none
//!
//! @return On success, zero is returned. On error, -1 is returned.
//!
//! @brief Stop any ping request.
//!
//!
//*****************************************************************************
#ifndef CC3000_TINY_DRIVER
extern long netapp_ping_stop();
#endif
//*****************************************************************************
//
//! netapp_ping_report
//!
//! @param none
//!
//! @return none
//!
//! @brief Request for ping status. This API triggers the CC3000 to send
//! asynchronous events: HCI_EVNT_WLAN_ASYNC_PING_REPORT.
//! This event will carry the report structure:
//! netapp_pingreport_args_t. This structure is filled in with ping
//! results up till point of triggering API.
//! netapp_pingreport_args_t:\n packets_sent - echo sent,
//! packets_received - echo reply, min_round_time - minimum
//! round time, max_round_time - max round time,
//! avg_round_time - average round time
//!
//! @note When a ping operation is not active, the returned structure
//! fields are 0.
//!
//*****************************************************************************
#ifndef CC3000_TINY_DRIVER
extern void netapp_ping_report();
#endif
I was hoping to get Spark core to obtain connected deviceās MAC address on the private network to match up a predefined list, so it can tell who is present in the house (on the network).
I have spent some time reading up on CC3000 netapp (which is not much), but find it a bit complex to simply enquire whether a local IP address exists. In order to get a report from the ping, I will have to use a callback function and the process is asynchronous. Any chance you can provide a short sample code based on the function?
Hmm, sounds like an interesting project, Iām not sure how to build this offhand, I would have to dig around in the firmware a bit, but Iām guessing there should be a way to accomplish this. Maybe someone more familiar can jump in and help write up an example. Otherwise Iāll circle back when I get a chance and see what would work.
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.
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.
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!
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.
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.
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?
@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.