Arduino to Server

Hi I am having trouble to my Arduino Project. My computer, where my Web and MySqL Server i running, has an IP address of 192.168.0.1.

Arduino Code:

#include <EtherCard.h>

static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[700];
static uint32_t timer;

char website[] PROGMEM = "192.168.0.102";

static void my_callback (byte status, word off, word len) {
  Serial.println(">>>");
  Ethernet::buffer[off+300] = 0;
  Serial.print((const char*) Ethernet::buffer + off);
  Serial.println("...");
}

void setup () {
  Serial.begin(9600);
  Serial.println("\n[webClient]");

  if (ether.begin(sizeof Ethernet::buffer, mymac,22) == 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.printIp("DNS: ", ether.dnsip);  

  if (!ether.dnsLookup(website))
    Serial.println("DNS failed");
    
  ether.printIp("SRV: ", ether.hisip);
}

void loop () {
  ether.packetLoop(ether.packetReceive());
  
  if (millis() > timer) {
    timer = millis() + 5000;
    Serial.println();
    Serial.print("<<< REQ ");
    ether.hisport = 80;//to access  local host
    itoa(myInt, myIntAsString, 10);
    ether.browseUrl(PSTR("/write_data.php?"), "value=ghghgh", website, my_callback);
  }
}

PHP Code:

<?php
$dbusername="root";
$dbpassword="";
$server="localhost"; 
$dbconnect= mysqli_connect($server,$dbusername,$dbpassword); 
$dbselect= mysqli_select_db($dbconnect,"sensor");
$myvariable=@$_GET['value'];
$sql="insert into sensor.mydata values ('".$myvariable."')"; 
mysqli_query($dbconnect,$sql);
?>

With this. it says DNS Failed @ 0.0.0.0 server.
I am using Arduino MEGA 2560 and ENC28J60

1 Like

My computer, where my Web and MySqL Server i running, has an IP address of 192.168.0.1.

What is the router address, then?

char website[] PROGMEM = "192.168.0.102";

So, why are you using some other address?

Why are you having to do a DNS lookup (Domain Name Services) when you already KNOW the IP address that DNS is supposed to return?