HELP: ping www."host".com using arduino


can me how ping servers www.google.com , count number of request timed out reset device if got 30 consecutive or accumulated request timed out. reset number(request timed out) again. im having problems ethernet module enc28j60 doesnt reconnect itself  webserver/data logging server "iot-ph.com"  when adsl modem power cycled(turned off , on).

any input guys appreciated im totally new here in arduino , had little knowledge c++ since looks java


//arduino , enc28j60
//upload code arduino board using arduino 1.0.6 or newer version
//for tutorials may visit http://thinkingparts.blogspot.com/2015/08/home-automation-diy-version-internet.html
#include <ethercard.h>
#include "dht.h"
#define dhtpin 9     // pin we're connected to
#define dhttype dht11   // dht 22  (am2302)
dht dht(dhtpin, dhttype);
// ethernet interface mac address, must unique on lan
static byte mymac[] = { 0x74,0x69,0x69,0x2d,0x30,0x31 };
byte ethernet::buffer[700];
static uint32_t timer;
//change value of id
//----------------------
string id = "deviceid"; 
//----------------------
string uid = "0";
string m1;
string ss1, ss2, ss3;
string aa0, aa1, aa2;
string c1, c2, c3;
int s1, s2, s3;
int a1, a2, a3;
int pin1out = 2;
int pin2out = 4;
int pin3out = 6;
int pin1in = 3;
int pin2in = 5;
int pin3in = 7;
string d;
char buf[90];
const char website[] progmem = "www.iot-ph.com";
static void my_callback (byte status, word off, word len)
{
  ethernet::buffer[off+300] = 0;
  m1 = strstr((const char*) ethernet::buffer + off, "cmd1");
}
void setup ()
{
  pinmode(pin1out, output);
  pinmode(pin2out, output);
  pinmode(pin3out, output);
  pinmode(pin1in, input);
  pinmode(pin2in, input);
  pinmode(pin3in, input);
  serial.begin(9600);
  dht.begin();
  serial.println("\n[webclient]");
  if (ether.begin(sizeof ethernet::buffer, mymac) == 0)
    serial.println( "failed access ethernet controller");
  if (!ether.dhcpsetup())
    serial.println("dhcp failed");
  //ether.printip("ip:  ", ether.myip);
  //ether.printip("gw:  ", ether.gwip); 
  //ether.printip("dns: ", ether.dnsip); 
  if (!ether.dnslookup(website))
    serial.println("dns failed");
  //ether.printip("srv: ", ether.hisip);
  delay(1000);
}
void loop ()
{
  ether.packetloop(ether.packetreceive());
  if (millis() > timer)
  {
    timer = millis() + 4000;
    serial.println();
    ether.browseurl(pstr("/account/diy_cmd_sts.php"), buf, website, my_callback);
    process();
    readdht11();
    convert2string();
    readytosend();
  }
}
void process()
{
  c1=m1.substring(5,6);
  c2=m1.substring(11,12);
  c3=m1.substring(17,18);
  s1 = digitalread(pin1in) + 1;
  s2 = digitalread(pin2in) + 1;
  s3 = digitalread(pin3in) + 1;
  if(c1=="2"){
    digitalwrite(pin1out,low);
  }
  else if(c1=="1"){
    digitalwrite(pin1out,high);
  }
  if(c2=="2"){
    digitalwrite(pin2out,low);
  }
  else if(c2=="1"){
    digitalwrite(pin2out,high);
  }
  if(c3=="2"){
    digitalwrite(pin3out,low);
  }
  else if(c3=="1"){
    digitalwrite(pin3out,high);
  }
}
void readdht11()
{
    delay(2000);
  a1 = dht.readhumidity();
  a2 = dht.readtemperature();
  serial.print("temperature is= ");
  serial.println(a1);
  serial.print("humidity is= ");
  serial.println(a2);
  a3 = 1;
}
void convert2string()
{
  serial.print("received is= ");
  serial.println(m1);
  if ((m1=="") || (m1=="0"))
  {
    c1="9";
    c2="9";
    c3="9";
    s1=9;
    s2=9;
    s3=9;
    a1=9;
    a2=9;
    a3=9;
  }
  else
  {
   // serial.println(m1);
  }
  if(s1==1){
    s1=2;
  }
  else{
    s1=1;
  }
  if(s2==1){
    s2=2;
  }
  else{
    s2=1;
  }
  if(s3==1){
    s3=2;
  }
  else{
    s3=1;
  }
  ss1 = string(s1);
  ss2 = string(s2);
  ss3 = string(s3);
  aa0 = string(a1);
  aa1 = string(a2);
  aa2 = string(a3);
}
void readytosend()
{
  d = "?id=" + id + "&uid=" + uid + "&type=2";
  d += "&c1=" + c1 + "&s1=" + ss1;
  d += "&c2=" + c2 + "&s2=" + ss2;
  d += "&c3=" + c3 + "&s3=" + ss3;
  d += "&a1=" + aa0;
  d += "&a2=" + aa1;
  d += "&a3=" + aa2;
  d.tochararray(buf,90);
  //serial.println(buf);
}



Arduino Forum > Using Arduino > Programming Questions > HELP: ping www."host".com using arduino


arduino

Comments