Hallo,
Habe folgendes Problem:
Ich habe einen A1 Router technicolor TG588v,
welcher einen DynDns update auf DtDns.net macht,
er kann eben nur bestimmte voreingestellte DynDns und da auch nur einen DNS.
Nun habe ich im Internet gesucht nach einer Arduino Lösung und bin auch auf diese gestoßen:
How to update IP with Arduino using service like DynDns DtDns.net
How to update IP with Arduino using service like DynDns DtDns.net - Programming Questions - Arduino Forum
Leider hat es bei mir nicht funktioniert, so habe ich es ein wenig bearbeitet.
Ich hoffe ich kann damit jemand helfen.
//Mit Arduino version 1.0.6 getestet
// Arduino MEGA Ramverbrauch min 2152
#include <Ethernet.h>
#include <SPI.h>
/*
byte ip[] = {
10, 0, 0, 100 }; //Manual setup only
byte gateway[] = {
10, 0, 0, 138 }; //Manual setup only
byte subnet[] = {
255, 255, 255, 0 }; //Manual setup only
*/
// if need to change the MAC address (Very Rare)
byte mac[] = {
//0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
0xDE, 0x19, 0x8A, 0xEF, 0xFE, 0x07 };
EthernetClient client;
String lastip="";
String newip="";
unsigned long previousMillis = 15000;
const long interval = 15000;
void setup()
{
// http://stackoverflow.com/questions/33892704/ethernet-shield-does-not-supplying-the-correct-ip
// Maybe try letting your router provide an IP address via DHCP. To do that, just change the line in your setup routine to Ethernet.begin(mac);
Ethernet.begin(mac);
//Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(115200);
delay(1000);
//Serial.println("connecting...");
//ram_info();
//send_ip(client);
}
void loop()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) { // alle 15 Sekunden aufrufen
Serial.println("connecting...");
send_ip(client);
currentMillis = millis();
previousMillis = currentMillis;
}
delay(1000);
Serial.println((currentMillis - previousMillis)/1000); // Zeit
}
void send_ip(EthernetClient client) // https://forum.arduino.cc/index.php?topic=369600.0
{
if (client.connect("checkip.dyndns.org", 80)) { //starts client connection, checks for connection
Serial.println(F("connected"));
client.println(F("GET /api/p/realip.php HTTP/1.1")); //download text
client.println(F("Host: checkip.dyndns.org"));
client.println(F("Connection: close")); //close 1.1 persistent connection
client.println(); //end of get request
}
else {
Serial.println(F("\tconnection failed")); //error message if no client connect
client.stop();
return;
}
byte reed = 0; // umschalten von IP suchen auf IP einlesen
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
if (reed == 0 && client.find("IP Address: ")) { //alle Zeichen löschen bis "IP Address: " gefunden wurde im Antworttext der Webseite
reed = 1;
delay(1);
}
if (reed == 1) {
char c = client.read(); //gets byte from ethernet buffer
if (c == '<') { break; reed = 0; } //Erstes Zeichen nach der IP adresse
Serial.write(c);
newip += c; //places captured byte in readString
}
}
Serial.println("");
client.stop(); //stop client
if (newip == "") { //Abbrechen wenn keine IP gelesen wurde
Serial.println(F("\tIP nicht gefunden\n"));
//Serial.println(F("!!!")); // Upload nicht möglich wegen "!!!"
return;
}
if (lastip != newip ) // wenn lastip verschieden von newip ist
{
Serial.print(F("\tlastip= "));
Serial.println(lastip);
lastip="";
lastip = newip;
update_dtdns(client);
}
newip=""; //leert die Variable Readstring
}
void update_dtdns(EthernetClient client) //dtdns erneuern
{
client.connect("www.dtdns.com", 80) ;
//client.print(F("POST /api/autodns.cfm?id=yourdnsname.dtdns.net&pw=yourpassword&ip="));
client.print(F("POST /api/autodns.cfm?id=beispiel1234.b0ne.com&pw=123456789123&ip="));
client.println(lastip);
client.println();
client.stop();
Serial.println(F("client.stop"));
}
(Vielleicht kann mir noch jemand erklären wieso die Arduino DIE 1.0.6 den Upload auf den Mega verweigert wenn im code „Serial.println(F("!!!"));“ steht?)