Adesso dovrebbe funzionare. Attenzione solo che la scheda arduino deve collegata tramite wifi o cavo "diretta" alla rete.
Soprattutto via cavo, collegata ad una presa rj45 a muro oppure ad uno switch.
Arduino non si connette (client.connect non funz.)
16 messaggi
• Pagina 2 di 2 • 1, 2
0
voti
speedyant ha scritto:Adesso dovrebbe funzionare. Attenzione solo che la scheda arduino deve collegata tramite wifi o cavo "diretta" alla rete.
Soprattutto via cavo, collegata ad una presa rj45 a muro oppure ad uno switch.
io collego Arduino USB e lan al mio PC, credendo che se la prenda dal PC internet.
Questo non lo può fare (prendersi internet dal PC via Ethernet)?
Altrimenti potrei collegare Arduino alla RJ45 del Fritz in mansarda

0
voti
Bene sto provvando questo sketch:
Il monitor seriale mi dice che il DHCP, assegna al mio arduino un IP diverso da quello dello sketch (192.168.1.141).
A questo punto dovrei essere connesso al sito di Arduino. Provo a digitare il precedente indirizzo nella barra del Browser e Arduino non mi risponde.
Non capisco cosa dovrebbe fare e e soprattutto la funzione client.println() cosa dovrebbe fare... dovrebbe apire lei su Browser il sito www.arduino.cc??
- Codice: Seleziona tutto
#include <SPI.h>
#include <Ethernet.h>
// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 1, 2);
IPAddress myDns(192, 168, 1, 50);
// initialize the library instance:
EthernetClient client;
char server[] = "www.arduino.cc"; // also change the Host line in httpRequest()
//IPAddress server(64,131,82,241);
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10*1000; // delay between updates, in milliseconds
void setup() {
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
// start serial port:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection:
Serial.println("Initialize Ethernet with DHCP:");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip, myDns);
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
} else {
Serial.print(" DHCP assigned IP ");
Serial.println(Ethernet.localIP());
}
// give the Ethernet shield a second to initialize:
delay(1000);
}
void loop() {
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
char c = client.read();
Serial.write(c);
}
// if ten seconds have passed since your last connection,
// then connect again and send data:
if (millis() - lastConnectionTime > postingInterval) {
httpRequest();
}
}
// this method makes a HTTP connection to the server:
void httpRequest() {
// close any connection before send a new request.
// This will free the socket on the WiFi shield
client.stop();
// if there's a successful connection:
if (client.connect(server, 80)) {
Serial.println("connecting...");
// send the HTTP GET request:
client.println("GET /latest.txt HTTP/1.1");
client.println("Host: www.arduino.cc");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
// note the time that the connection was made:
lastConnectionTime = millis();
} else {
// if you couldn't make a connection:
Serial.println("connection failed");
}
Il monitor seriale mi dice che il DHCP, assegna al mio arduino un IP diverso da quello dello sketch (192.168.1.141).
A questo punto dovrei essere connesso al sito di Arduino. Provo a digitare il precedente indirizzo nella barra del Browser e Arduino non mi risponde.
Non capisco cosa dovrebbe fare e e soprattutto la funzione client.println() cosa dovrebbe fare... dovrebbe apire lei su Browser il sito www.arduino.cc??
0
voti
Se vuoi "accedere" alla scheda dovresti caricare uno sketch "server". Se provi a caricare lo scketch originario forse funziona.
Son quello delle domande strane!
0
voti
speedyant ha scritto:Se vuoi "accedere" alla scheda dovresti caricare uno sketch "server". Se provi a caricare lo scketch originario forse funziona.
giusto: in questo sketch Arduino è un client.
l'istruzione serial.client("Host www.arduino.cc") cosa fa?
16 messaggi
• Pagina 2 di 2 • 1, 2
Chi c’è in linea
Visitano il forum: Nessuno e 1 ospite

Elettrotecnica e non solo (admin)
Un gatto tra gli elettroni (IsidoroKZ)
Esperienza e simulazioni (g.schgor)
Moleskine di un idraulico (RenzoDF)
Il Blog di ElectroYou (webmaster)
Idee microcontrollate (TardoFreak)
PICcoli grandi PICMicro (Paolino)
Il blog elettrico di carloc (carloc)
DirtEYblooog (dirtydeeds)
Di tutto... un po' (jordan20)
AK47 (lillo)
Esperienze elettroniche (marco438)
Telecomunicazioni musicali (clavicordo)
Automazione ed Elettronica (gustavo)
Direttive per la sicurezza (ErnestoCappelletti)
EYnfo dall'Alaska (mir)
Apriamo il quadro! (attilio)
H7-25 (asdf)
Passione Elettrica (massimob)
Elettroni a spasso (guidob)
Bloguerra (guerra)


