From 2044efc3a4ffd66b9822f90b549d4619fca765cd Mon Sep 17 00:00:00 2001 From: Sergio Majluf Date: Sun, 27 Oct 2013 13:29:15 -0400 Subject: [PATCH] Update Arduino to new Ethernet library syntax --- .DS_Store | Bin 6148 -> 6148 bytes .../tcp_arduino_client/tcp_arduino_client.ino | 80 ++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 socket/arduino/tcp_arduino_client/tcp_arduino_client.ino diff --git a/.DS_Store b/.DS_Store index f1e3d1135259036496f75412c32ae108155e7628..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 100644 GIT binary patch delta 70 zcmZoMXfc=|#>AjHu~2NHo+1YW5HK<@2yA9#Vq@DZz_f~SGdl-A2T%b}B`mF;Q%yo}wrd0|Nsi1A_nqLn=cFgC0XBLw-{E#Kh(GAPG)}VupN% zWQJ^H$>M^foctu9?E0jFoXp}91A}XfOw25-Z0sByTpT40ut5LCguh@ z3dWYkwK@vb<{-9-v3YGRCnpD|zyS_XB|RIDki?qWy7~s7n}C23=p8WNh0-vp3CO_W zqm<(0oFt&-Fl`X!8}t6LPBsu>+04zs%>fLqjfvlxC-aLavVy`zVX~o!@MaH@J +#include + +// Enter a MAC address of your Ethernet shield or Arduino. +byte mac[] = { + 0x90, 0xA2, 0xDA, 0x00, 0x6C, 0xFE +}; + +// Arduino's IP address, dependent on your network configuration +IPAddress ip(192,168,0,225); + +// Node.js Server IP Address +IPAddress server(192,168,0,133); + +int pin = 9; //pin on Arduino you want to toggle +int pinVal = 0; + +// Create the Ethernet client +EthernetClient client; + +void setup() { + // start the Ethernet connection: + Ethernet.begin(mac, ip); + // start the serial library: + Serial.begin(9600); + // give the Ethernet shield a second to initialize: + delay(1000); + Serial.println("connecting..."); + + // if you get a connection, report back via serial: + // The 1337 PORT is for the TCP server, not the Web Server (8090 in node.js setup) + if (client.connect(server, 1337)) { + Serial.println("connected"); + } + else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } + + pinMode(pin, OUTPUT); +} + +void loop() +{ + + //if you are connected and data is available + if (client.available()) { + char c = client.read(); + Serial.print(c); + + // '1' was received, return '1' for HIGH + if (c == '1') { + pinVal = HIGH; + client.print('1'); + } + else if (c == '0') { + pinVal = LOW; + client.print('0'); + } + + //turn led pin to new position + digitalWrite(pin, pinVal); + + } + +}