14
14
15
15
*/
16
16
17
+ #include < PortentaEthernet.h>
17
18
#include < SPI.h>
18
- #include < Ethernet.h>
19
19
20
20
// Enter a MAC address for your controller below.
21
21
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
22
- byte mac[] = { 0xDE , 0xAD , 0xBE , 0xEF , 0xFE , 0xED };
22
+ // byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
23
23
24
24
// if you don't want to use DNS (and reduce your sketch size)
25
25
// use the numeric IP instead of the name for the server:
26
26
// IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
27
- char server[] = " www.google.com" ; // name address for Google (using DNS)
27
+ char server[] = " www.google.com" ; // name address for Google (using DNS)
28
28
29
29
// Set the static IP address to use if the DHCP fails to assign
30
- IPAddress ip (192 , 168 , 0 , 177 );
31
- IPAddress myDns (192 , 168 , 0 , 1 );
30
+ IPAddress ip (192 , 168 , 2 , 177 );
31
+ IPAddress myDns (192 , 168 , 2 , 1 );
32
32
33
33
// Initialize the Ethernet client library
34
34
// with the IP address and port of the server
@@ -38,100 +38,95 @@ EthernetClient client;
38
38
// Variables to measure the speed
39
39
unsigned long beginMicros, endMicros;
40
40
unsigned long byteCount = 0 ;
41
- bool printWebData = true ; // set to false for better speed measurement
42
-
43
- void setup () {
44
- // You can use Ethernet.init(pin) to configure the CS pin
45
- // Ethernet.init(10); // Most Arduino shields
46
- // Ethernet.init(5); // MKR ETH shield
47
- // Ethernet.init(0); // Teensy 2.0
48
- // Ethernet.init(20); // Teensy++ 2.0
49
- // Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
50
- // Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
51
-
52
- // Open serial communications and wait for port to open:
53
- Serial.begin (9600 );
54
- while (!Serial) {
55
- ; // wait for serial port to connect. Needed for native USB port only
56
- }
57
-
58
- // start the Ethernet connection:
59
- Serial.println (" Initialize Ethernet with DHCP:" );
60
- if (Ethernet.begin (mac) == 0 ) {
61
- Serial.println (" Failed to configure Ethernet using DHCP" );
62
- // Check for Ethernet hardware present
63
- if (Ethernet.hardwareStatus () == EthernetNoHardware) {
64
- Serial.println (" Ethernet shield was not found. Sorry, can't run without hardware. :(" );
65
- while (true ) {
66
- delay (1 ); // do nothing, no point running without Ethernet hardware
67
- }
41
+ bool printWebData = true ; // set to false for better speed measurement
42
+
43
+ void setup ()
44
+ {
45
+
46
+ // Open serial communications and wait for port to open:
47
+ Serial.begin (9600 );
48
+ while (!Serial) {
49
+ ; // wait for serial port to connect. Needed for native USB port only
50
+ }
51
+
52
+ // start the Ethernet connection:
53
+ Serial.println (" Initialize Ethernet with DHCP:" );
54
+ if (Ethernet.begin () == 0 ) {
55
+ Serial.println (" Failed to configure Ethernet using DHCP" );
56
+ // Check for Ethernet hardware present
57
+ if (Ethernet.hardwareStatus () == EthernetNoHardware) {
58
+ Serial.println (" Ethernet shield was not found. Sorry, can't run without hardware. :(" );
59
+ while (true ) {
60
+ delay (1 ); // do nothing, no point running without Ethernet hardware
61
+ }
62
+ }
63
+ if (Ethernet.linkStatus () == LinkOFF) {
64
+ Serial.println (" Ethernet cable is not connected." );
65
+ }
66
+ // try to congifure using IP address instead of DHCP:
67
+ Ethernet.begin (ip, myDns);
68
+ } else {
69
+ Serial.print (" DHCP assigned IP " );
70
+ Serial.println (Ethernet.localIP ());
68
71
}
69
- if (Ethernet.linkStatus () == LinkOFF) {
70
- Serial.println (" Ethernet cable is not connected." );
72
+ // give the Ethernet shield a second to initialize:
73
+ delay (1000 );
74
+ Serial.print (" connecting to " );
75
+ Serial.print (server);
76
+ Serial.println (" ..." );
77
+
78
+ // if you get a connection, report back via serial:
79
+ if (client.connect (server, 80 )) {
80
+ Serial.print (" connected to " );
81
+ Serial.println (client.remoteIP ());
82
+ // Make a HTTP request:
83
+ client.println (" GET /search?q=arduino HTTP/1.1" );
84
+ client.println (" Host: www.google.com" );
85
+ client.println (" Connection: close" );
86
+ client.println ();
87
+ } else {
88
+ // if you didn't get a connection to the server:
89
+ Serial.println (" connection failed" );
71
90
}
72
- // try to congifure using IP address instead of DHCP:
73
- Ethernet.begin (mac, ip, myDns);
74
- } else {
75
- Serial.print (" DHCP assigned IP " );
76
- Serial.println (Ethernet.localIP ());
77
- }
78
- // give the Ethernet shield a second to initialize:
79
- delay (1000 );
80
- Serial.print (" connecting to " );
81
- Serial.print (server);
82
- Serial.println (" ..." );
83
-
84
- // if you get a connection, report back via serial:
85
- if (client.connect (server, 80 )) {
86
- Serial.print (" connected to " );
87
- Serial.println (client.remoteIP ());
88
- // Make a HTTP request:
89
- client.println (" GET /search?q=arduino HTTP/1.1" );
90
- client.println (" Host: www.google.com" );
91
- client.println (" Connection: close" );
92
- client.println ();
93
- } else {
94
- // if you didn't get a connection to the server:
95
- Serial.println (" connection failed" );
96
- }
97
- beginMicros = micros ();
91
+ beginMicros = micros ();
98
92
}
99
93
100
- void loop () {
101
- // if there are incoming bytes available
102
- // from the server, read them and print them:
103
- int len = client.available ();
104
- if (len > 0 ) {
105
- byte buffer[80 ];
106
- if (len > 80 ) len = 80 ;
107
- client.read (buffer, len);
108
- if (printWebData) {
109
- Serial.write (buffer, len); // show in the serial monitor (slows some boards)
94
+ void loop ()
95
+ {
96
+ // if there are incoming bytes available
97
+ // from the server, read them and print them:
98
+ int len = client.available ();
99
+ if (len > 0 ) {
100
+ byte buffer[80 ];
101
+ if (len > 80 )
102
+ len = 80 ;
103
+ client.read (buffer, len);
104
+ if (printWebData) {
105
+ Serial.write (buffer, len); // show in the serial monitor (slows some boards)
106
+ }
107
+ byteCount = byteCount + len;
110
108
}
111
- byteCount = byteCount + len;
112
- }
113
-
114
- // if the server's disconnected, stop the client:
115
- if (!client.connected ()) {
116
- endMicros = micros ();
117
- Serial.println ();
118
- Serial.println (" disconnecting." );
119
- client.stop ();
120
- Serial.print (" Received " );
121
- Serial.print (byteCount);
122
- Serial.print (" bytes in " );
123
- float seconds = (float )(endMicros - beginMicros) / 1000000.0 ;
124
- Serial.print (seconds, 4 );
125
- float rate = (float )byteCount / seconds / 1000.0 ;
126
- Serial.print (" , rate = " );
127
- Serial.print (rate);
128
- Serial.print (" kbytes/second" );
129
- Serial.println ();
130
-
131
- // do nothing forevermore:
132
- while (true ) {
133
- delay (1 );
109
+
110
+ // if the server's disconnected, stop the client:
111
+ if (!client.connected ()) {
112
+ endMicros = micros ();
113
+ Serial.println ();
114
+ Serial.println (" disconnecting." );
115
+ client.stop ();
116
+ Serial.print (" Received " );
117
+ Serial.print (byteCount);
118
+ Serial.print (" bytes in " );
119
+ float seconds = (float )(endMicros - beginMicros) / 1000000.0 ;
120
+ Serial.print (seconds, 4 );
121
+ float rate = (float )byteCount / seconds / 1000.0 ;
122
+ Serial.print (" , rate = " );
123
+ Serial.print (rate);
124
+ Serial.print (" kbytes/second" );
125
+ Serial.println ();
126
+
127
+ // do nothing forevermore:
128
+ while (true ) {
129
+ delay (1 );
130
+ }
134
131
}
135
- }
136
132
}
137
-
0 commit comments