|
-
-
- #include <SPI.h>
- #include <NativeEthernet.h>
-
-
-
- byte mac[] = {
- 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
- };
- IPAddress ip(192, 168, 1, 177);
-
-
- IPAddress server(1, 1, 1, 1);
-
-
-
-
-
- EthernetClient client;
-
- void setup() {
-
-
-
-
-
-
-
-
-
- Ethernet.begin(mac, ip);
-
-
- Serial.begin(9600);
- while (!Serial) {
- ;
- }
-
-
- if (Ethernet.hardwareStatus() == EthernetNoHardware) {
- Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
- while (true) {
- delay(1);
- }
- }
- while (Ethernet.linkStatus() == LinkOFF) {
- Serial.println("Ethernet cable is not connected.");
- delay(500);
- }
-
-
- delay(1000);
- Serial.println("connecting...");
-
-
- if (client.connect(server, 10002)) {
- Serial.println("connected");
- } else {
-
- Serial.println("connection failed");
- }
- }
-
- void loop() {
-
-
- if (client.available()) {
- char c = client.read();
- Serial.print(c);
- }
-
-
-
- while (Serial.available() > 0) {
- char inChar = Serial.read();
- if (client.connected()) {
- client.print(inChar);
- }
- }
-
-
- if (!client.connected()) {
- Serial.println();
- Serial.println("disconnecting.");
- client.stop();
-
- while (true) {
- delay(1);
- }
- }
- }
-
-
-
|