Ping на nano нескольких хостов
- Войдите на сайт для отправки комментариев
Сб, 09/01/2016 - 15:47
Всем привет. Есть код
#include <EtherCard.h>
int outputPin = 6; // LED1 to pin 6
int anotherOutputPin = 7; // LED2 to pin 7
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[700];
static uint32_t timer;
static uint32_t count;
static uint32_t all;
// called when a ping comes in (replies to it are automatic)
static void gotPinged (byte* ptr) {
ether.printIp(">>> ping from: ", ptr);
}
void setup () {
pinMode(outputPin, OUTPUT);
pinMode(anotherOutputPin, OUTPUT);
digitalWrite(anotherOutputPin, HIGH);
digitalWrite(outputPin, HIGH);
count=0;
all=0;
Serial.begin(57600);
Serial.println("\n[pings]");
if (ether.begin(sizeof Ethernet::buffer, mymac,10) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.parseIp(ether.hisip, "192.168.88.1");
//#endif
ether.printIp("SRV: ", ether.hisip);
// call this to report others pinging us
ether.registerPingCallback(gotPinged);
timer = -9999999; // start timing out right away
Serial.println();
}
void loop () {
word len = ether.packetReceive(); // go receive new packets
word pos = ether.packetLoop(len); // respond to incoming pings
if (len > 0 && ether.packetLoopIcmpCheckReply(ether.hisip)) {
Serial.print(" ");
Serial.print((micros() - timer) * 0.001, 3);
Serial.println(" ms");
count=0;
all=0;
}
// ping a remote server once every few seconds
if (micros() - timer >= 5000000)
{
if ((ether.packetLoopIcmpCheckReply(ether.hisip))==0){
count=count+1; }
ether.printIp("Pinging: ", ether.hisip);
Serial.println("Count ");
Serial.println(count);
Serial.println("all ");
Serial.println(all);
timer = micros();
ether.clientIcmpRequest(ether.hisip);
if (count>5)
{
digitalWrite(outputPin, LOW); // turn the LED off by making the voltage LOW
delay(20000);
digitalWrite(outputPin, HIGH); // turn the LED on (HIGH is the voltage level)
count=0;
all=all+1;
}
if (all>2)
digitalWrite(outputPin, LOW);
}
}
Не могу сообразить, как натравить ардуино на пинг нескольких устройств? Т.е. просто пингуем подряд несколько устройств и получаем от них ответы. Ну а дальше я уже сам анализиурю что с ними делать :)
Массивы и циклы.