summaryrefslogtreecommitdiff
path: root/Venus_Skeleton/libs/TrueRandom/examples/MacAddress/MacAddress.pde
blob: fc68ba710c4ab15952432e4f0cfa77caa3926109 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// This example modifies the Ethernet Client example to use
// a randomly generated MAC address
//
// This has the advantage that no MAC addresses will clash, even if
// every device uses exactly the same code on its Arduino.
//

// This example is identical to the Ethernet/Client example
// with three changes to utilise TrueRandom.

#include <Ethernet.h>

//
// Change 1/3: Include TrueRandom library
#include <TrueRandom.h>
//
//

//
// Change 2/3: Include TrueRandom library
// TrueRandom sets this, so no default is needed here.
byte mac[6];
//
//

byte ip[] = { 10, 0, 0, 177 };
byte server[] = { 64, 233, 187, 99 }; // Google

Client client(server, 80);

void setup()
{
  //
  // Change 3/3: Set a random MAC address using TrueRandom
  TrueRandom.mac(mac);
  //
  //
  
  
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  
  delay(1000);
  
  Serial.println("connecting...");
  
  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}