Arduinohoz van egy sketch-em (lent) de nem tudom használni, mert azt úrja ki, hogy a client osztály új neve: ethernet client. Mi lehet a probléma?
#include <Ethernet.h>
#include <WString.h>
#include <EEPROM.h>
#define UPDATE_INTERVAL 30000
int ledR = 8;
int ledG = 9;
unsigned long pubblica=0;
byte mac[] = { 0x54,0x55,0x58,0x10,0x00,0x24 };
byte ip[] = { 192, 168, 0, 5 };
byte domainaddrip[]= { 188,6,118,224 };
byte ipAddr[4];
byte domaindydns[]= { 204, 13, 248, 112 }; // members.dyndns.org
char hostname[ ] = "---.dyndns.org";
char userpwdb64[ ] = "---";
String ipadsl = String(20);
String ipadslold = String(20);
String inString = String(51);
const char* ip_to_str(const uint8_t*);
Client client(domainaddrip, 82);
Client clientdyn(domaindydns, 82);
void setup()
{
pinMode(ledR, OUTPUT);
pinMode(ledG, OUTPUT);
Ethernet.begin(mac, ip);
Serial.begin(9600);
Serial.println("*********Start*******");
delay(1000);
}
void loop()
{
if (millis() < pubblica) pubblica = millis();
if ((millis() - pubblica) > UPDATE_INTERVAL){
Serial.print("tempo trascorso dall'accensione ");
Serial.println(millis());
Serial.println(pubblica);
pubblica = millis();
acquisisciip();
}
}
void acquisisciip()
{
int timeout=0;
int skip=0;
ipadsl="";
inString="";
digitalWrite(ledG, HIGH);
Serial.print("connecting to ");
if (client.connect()) {
Serial.println("connected");
client.println("GET / HTTP/1.0");
client.print("HOST: ");
client.println("www.dyndns.com");
client.println();
} else {
Serial.println("connection failed");
}
while (!client.available() && timeout<50)
{
timeout++;
Serial.print("Time out ");
Serial.println(timeout);
delay(100);
}
while (client.available())
{
char c = client.read();
skip++;
if (skip>220)
{
if ((inString.length())<50) inString.append(c);
}
}
client.flush();
if ((inString.length())>5){
if (inString.contains("Address")){
int from=(inString.indexOf("Address")+9);
int lunghe=inString.length();
int to=(lunghe-16);
ipadsl=inString.substring(from,to);
Serial.print("IP rilevato dal sito: >");
Serial.print(ipadsl);
Serial.println("<");
}
}
if (!client.connected()){
Serial.println("disconnecting.");
client.stop();
delay (1000);
Serial.print("lunghezza IP ");
Serial.println(ipadsl.length());
if ((strlen(ipadsl))!=0){
Serial.print("IP nuovo : >");
Serial.print(ipadsl);
Serial.println("<");
for (int i=0; i<(ipadsl.length()); i++) {
//salva in memoria l'indirizzo acquisito
ipadslold[i] = EEPROM.read(i);
}
Serial.print("IP vecchio: >");
Serial.print(ipadslold);
Serial.println("<");
if (strcmp(ipadsl,ipadslold)){
Serial.println("IP diverso PUBBLICO");
digitalWrite(ledR, HIGH);
pubblicaip();
digitalWrite(ledR, LOW);
}
else
{
Serial.println("IP uguale");
}
digitalWrite(ledG, LOW);
for (int i=0; i<(ipadsl.length()); i++) {
//salva in memoria l'indirizzo acquisito
EEPROM.write(i, ipadsl[i]);
}
}
}
}
void pubblicaip()
{
int timeout=0;
Serial.print("connecting to ");
Serial.println(ip_to_str(domaindydns));
Serial.print("IP da pubblicare ");
Serial.println(ipadsl);
if (clientdyn.connect()) {
Serial.println("connected");
clientdyn.print("GET /nic/update?hostname=");
clientdyn.print(hostname);
clientdyn.print("&myip=");
clientdyn.print(ipadsl);
clientdyn.println(" HTTP/1.0 ");
clientdyn.print("Host: ");
clientdyn.println(ip_to_str(domaindydns));
clientdyn.print("Authorization: Basic ");
clientdyn.println(userpwdb64);
clientdyn.println
("User-Agent: futura - arduinodydns - 1.1");
clientdyn.println();
} else {
Serial.println("connection failed");
}
while (!clientdyn.available() && timeout<50) {
timeout++;
Serial.print("Time out ");
Serial.println(timeout);
delay(100);
}
while (clientdyn.available()) {
if (clientdyn.available())
{
char c = clientdyn.read();
Serial.print(c);
}
}
if (!clientdyn.connected()){
Serial.println();
Serial.println("disconnecting.");
clientdyn.stop();
}
}
//This is just a little utility function
//to format an IP address as a string.
const char* ip_to_str(const uint8_t* ipAddr)
{
static char buf[16];
sprintf(buf, "%d.%d.%d.%d\0", ipAddr[0],
ipAddr[1], ipAddr[2], ipAddr[3]);
return buf;
}
Te lehetsz az első, aki segít a kérdezőnek!
Kapcsolódó kérdések:
Minden jog fenntartva © 2024, www.gyakorikerdesek.hu
GYIK | Szabályzat | Jogi nyilatkozat | Adatvédelem | Cookie beállítások | WebMinute Kft. | Facebook | Kapcsolat: info(kukac)gyakorikerdesek.hu
Ha kifogással szeretne élni valamely tartalommal kapcsolatban, kérjük jelezze e-mailes elérhetőségünkön!