Hello all,
I'm sure this will exasperate some, but I'm at my wits end.
Hardware:
Arduino Mega2560
Arduino Ethernet Shield
Actiontec MI424WR from Verizon
I've loaded the DhcpAddressPrinter sketch on to the Arduino and I consistently get Failed to connect to DHCP server. I have factory reset the router and tried again to no avail.
My main goal is to set up Teleduino on the Arduino. When I use the Ethernet sketch from Teleduino the Arduino never connects...never shows up in my router's list of connected devices.
I've also set DHCP to false inside the Teleduino sketch and added my router configuration, making sure to pick an IP outside the DHCP in concurrence with setting up a static IP with the router using the same MAC address and IP as is in my Sketch....to no avail.
Either the router hates me...the Ethernet shield or I'm an idiot. I'm willing to accept any or all at this point.
Any help figuring this out is appreciated!
Teleduino Sketch with Static IP code:
/*
Teleduino2560EthernetClientProxy.ino - Teleduino2560EthernetClientProxy example
Version 2560-0.1.2
Nathan Kennedy 2009 - 2014
http://www.teleduino.org
This sketch is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <EEPROM.h>
#include <Servo.h>
#include <Wire.h>
#include <Teleduino2560.h>
#include <SPI.h>
#include <Ethernet.h>
// User configurable variables
byte useDhcp = false;
byte useDns = true;
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
IPAddress deviceIp(192, 168, 1, 252); // Only if useDhcp is false
IPAddress gatewayIp(192, 168, 1, 1); // Only if useDhcp is false
IPAddress dnsIp(192, 168, 1, 1); // Only if useDhcp is false
IPAddress subnet(255, 255, 255, 0); // Only if useDhcp is false
IPAddress serverIp(173, 230, 152, 173); // Only if useDns is false
char serverName[] = "us01.proxy.teleduino.org"; // Only if useDns is true
unsigned int serverPort = 5353; // Can be set to either 53 or 5353
byte statusLedPin = 8;
// User configurable key, this is used to authenticate with the proxy server
// This is checked against the EEPROM on boot and written if necessary
// The proxy server retreives the key from the EEPROM
byte key[] = { Personal KEY };
// Other required variables
byte data[257];
byte dataLength;
byte hexStage;
unsigned long lastInstruction = 0;
unsigned long lastRefresh = 0;
byte stage = 0;
// Declare client object
EthernetClient Client;
void setup()
{
// This is here purely to add a bit of padding to the sketch to fix a compiling bug
// http://arduino.cc/forum/index.php/topic,60649.0.html
EEPROM.read(0);
// Load presets
Teleduino2560.loadPresets();
// Set status LED pin
Teleduino2560.setStatusLedPin(statusLedPin);
Teleduino2560.setStatusLed(1); // Initialisation
// Check the EEPROM header and check to see if the key is correct
// This is to ensure the key is not cleared from the EEPROM
if(EEPROM.read(0) != '#')
{
EEPROM.write(0, '#');
}
if(EEPROM.read(1) != 1)
{
EEPROM.write(1, 1);
}
if(EEPROM.read(2) != '#')
{
EEPROM.write(2, '#');
}
if(EEPROM.read(395) != '#')
{
EEPROM.write(395, '#');
}
for(byte i = 0; i < 16; i++)
{
if(EEPROM.read(396 + i) != key[i])
{
EEPROM.write(396 + i, key[i]);
}
}
if(EEPROM.read(412) != '#')
{
EEPROM.write(412, '#');
}
// Start network and attempt to connect to proxy server
Teleduino2560.setStatusLed(2); // Network configuration
if(useDhcp)
{
if(!Ethernet.begin(mac))
{
Teleduino2560.setStatusLed(2, false, 10000);
Teleduino2560.reset();
}
}
else
{
Ethernet.begin(mac, deviceIp, dnsIp, gatewayIp, subnet);
}
delay(1000);
Teleduino2560.setStatusLed(3); // Connect to server
if((useDns && !Client.connect(serverName, serverPort)) || (!useDns && !Client.connect(serverIp, serverPort)))
{
Teleduino2560.setStatusLed(3, false, 10000);
Teleduino2560.reset();
}
lastInstruction = millis();
}
void loop()
{
if(Client.connected())
{
// What we need to do depends on which 'stage' we are at
switch(stage)
{
case 0: // Wait for start byte
if(Client.available())
{
char c = Client.read();
if(c == '?')
{
stage++;
}
}
break;
case 1: // Reset variables
dataLength = 0;
hexStage = 0;
stage++;
break;
case 2: // Instruction byte
if(Client.available())
{
char c = Client.read();
if(c == '?')
{
stage = 1;
break;
}
else if(c == '\r' || c == '\n' || c == '.')
{
stage = 0;
break;
}
if(!hexStage)
{
data[0] = Teleduino2560.hexDecode(c) * 16;
}
else
{
data[0] += Teleduino2560.hexDecode(c);
}
hexStage = !hexStage;
if(!hexStage)
{
stage++;
}
}
break;
case 3: // Data length byte
if(Client.available())
{
char c = Client.read();
if(c == '?')
{
stage = 1;
break;
}
else if(c == '\r' || c == '\n' || c == '.')
{
stage = 0;
break;
}
if(!hexStage)
{
data[1] = Teleduino2560.hexDecode(c) * 16;
}
else
{
data[1] += Teleduino2560.hexDecode(c);
}
hexStage = !hexStage;
if(!hexStage)
{
stage++;
}
}
break;
case 4: // Data
if(Client.available())
{
char c = Client.read();
if(c == '?')
{
stage = 1;
break;
}
else if(c == '\r' || c == '\n' || c == '.')
{
if(dataLength == data[1])
{
stage++;
break;
}
else
{
stage = 0;
break;
}
}
if(!hexStage)
{
data[2 + dataLength] = Teleduino2560.hexDecode(c) * 16;
}
else
{
data[2 + dataLength] += Teleduino2560.hexDecode(c);
}
hexStage = !hexStage;
if(!hexStage)
{
dataLength++;
}
}
break;
case 5: // Execute instruction and return result
Teleduino2560.instruction(data);
Client.write('!');
for(int i = 0; i < data[1] + 2; i++)
{
Client.write(Teleduino2560.hexEncode(data[i] / 16));
Client.write(Teleduino2560.hexEncode(data[i] % 16));
}
Client.write('\n');
lastInstruction = millis();
stage = 0;
break;
}
}
else
{
Teleduino2560.setStatusLed(10);
Teleduino2560.reset();
}
// Has the instruction timeout been reached?
if(millis() - lastInstruction > 30000)
{
Client.flush();
Client.stop();
Teleduino2560.setStatusLed(9);
Teleduino2560.reset();
}
// Process refreshes every 50ms
if(millis() - lastRefresh >= 50)
{
Teleduino2560.pinTimers();
Teleduino2560.shiftRegisterTimers();
Teleduino2560.shiftRegisters();
lastRefresh = millis();
}
// Check to see if reset has been requested
Teleduino2560.checkReset();
}



