twitter and IDE1

I have tested the new twitter example for ide1. When I connect with Ethernet.begin(mac) everything is fine but if I try to connect with Ethernet.begin(mac,ip) the connection always fails (of course the ip I give is good in my network and it’s already associated with ethernet shield mac). Has anyone of you experienced the same?

I was reading the Ethernet library sources and in there it says that the default router is assumed to be X.X.X.1. If your router doesn't respond to the IP address you are using with the last octet set to 1 then it won't work.

what library are you using? Is this one? http://arduino.cc/playground/Code/TwitterLibrary

Ethernet.begin() from the Ethernet.cpp file in the Ethernet library.

The function begin() can take up to 5 arguments: 1) The MAC address of the Ethernet adapter. 2) The local IP address. 3) The IP address of the DNS Server (for doing name lookup) 4) The IP address of the default gateway (router) 5) The subnet mask (typically 255.255.255.0

If you leave off #5 it will use 255.255.255.0. If you also leave off the gateway address it will use the first three parts of the local IP address folowed by a 1 If you also leave off the DNS server address it will use the first three parts of the local IP address folowed by a 1 If you also leave off the local IP address it will use DHCP to acquire one.

If you specify a local IP address of A.B.C.D and your DNS server or gateway are not at A.B.C.1 you won't have a connection to the internet.

void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
{
  W5100.init();
  W5100.setMACAddress(mac);
  W5100.setIPAddress(local_ip._address);
  W5100.setGatewayIp(gateway._address);
  W5100.setSubnetMask(subnet._address);
  _dnsServerAddress = dns_server;
}

Note that with 1.0, the working order changed to the below.

  Ethernet.begin(mac, ip, gateway, subnet);

zoomkat: Note that with 1.0, the working order changed to the below.

  Ethernet.begin(mac, ip, gateway, subnet);

My information came straight from the1.0 Ethernet library source (Ethernet.cpp):

int EthernetClass::begin(uint8_t *mac_address)
{
  DhcpClass dhcp;

  // Initialise the basic info
  W5100.init();
  W5100.setMACAddress(mac_address);
  W5100.setIPAddress(IPAddress(0,0,0,0).raw_address());

  // Now try to get our config info from a DHCP server
  int ret = dhcp.beginWithDHCP(mac_address);
  if(ret == 1)
  {
    // We've successfully found a DHCP server and got our configuration info, so set things
    // accordingly
    W5100.setIPAddress(dhcp.getLocalIp().raw_address());
    W5100.setGatewayIp(dhcp.getGatewayIp().raw_address());
    W5100.setSubnetMask(dhcp.getSubnetMask().raw_address());
    _dnsServerAddress = dhcp.getDnsServerIp();
  }

  return ret;
}

void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip)
{
  // Assume the DNS server will be the machine on the same network as the local IP
  // but with last octet being '1'
  IPAddress dns_server = local_ip;
  dns_server[3] = 1;
  begin(mac_address, local_ip, dns_server);
}

void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server)
{
  // Assume the gateway will be the machine on the same network as the local IP
  // but with last octet being '1'
  IPAddress gateway = local_ip;
  gateway[3] = 1;
  begin(mac_address, local_ip, dns_server, gateway);
}

void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway)
{
  IPAddress subnet(255, 255, 255, 0);
  begin(mac_address, local_ip, dns_server, gateway, subnet);
}

void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
{
  W5100.init();
  W5100.setMACAddress(mac);
  W5100.setIPAddress(local_ip._address);
  W5100.setGatewayIp(gateway._address);
  W5100.setSubnetMask(subnet._address);
  _dnsServerAddress = dns_server;
}

My information came straight from the1.0 Ethernet library source

and it generally looks correct. :) I'm just making the point that the order in previous IDEs was either not important or was different (aka, old code seems to have compile problems in IDE 1.0).

I do not think the problem is Ethernet library because I can use it without problem in other sketchs. Only when i use twitter library thinks goes wrong. Thanks for you answers