Created
August 25, 2010 09:35
-
-
Save bobtfish/549182 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Ethernet.h> | |
| //#include <stomp.h> | |
| // network configuration. gateway and subnet are optional. | |
| byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; | |
| byte ip[] = { 172, 31, 24, 233 }; | |
| byte gateway[] = { 172, 31, 24, 1 }; | |
| byte subnet[] = { 255, 255, 255, 0 }; | |
| int ledPin = 7; // LED connected to digital pin 7 | |
| int state = 0; | |
| // telnet defaults to port 23 | |
| Server server = Server(23); | |
| void setup() | |
| { | |
| // initialize the ethernet device | |
| Ethernet.begin(mac, ip, gateway, subnet); | |
| pinMode(ledPin, OUTPUT); | |
| digitalWrite(ledPin, LOW); // set the LED off | |
| // start listening for clients | |
| server.begin(); | |
| } | |
| byte send_stomp_frame (command, headers, headercount, body) { | |
| client.write(command); | |
| client.write("\n"); | |
| for (int thisHeader = 0; thisHeader <= headercount; thisHeder++) { | |
| client.write(headers[thisHeader][0]); | |
| client.write(":"); | |
| client.write(headers[thisHeader][1]); | |
| client.write("\n"); | |
| } | |
| client.write("cotent-length:"); | |
| client.write(length(body)); | |
| client.write("\n\n"); | |
| client.write(body); | |
| client.write(0); | |
| } | |
| void loop() | |
| { | |
| //my $frame = Net::Stomp::Frame->new( | |
| // { command => 'CONNECT', headers => $conf } ); | |
| Client client = server.available(); | |
| while (client) { | |
| if (client.available()) { | |
| client.read(); | |
| if (state == 0) { | |
| state = 1; | |
| digitalWrite(ledPin, HIGH); | |
| server.write("ON"); | |
| } | |
| else { | |
| state = 0; | |
| digitalWrite(ledPin, LOW); | |
| server.write("OFF"); | |
| } | |
| server.write("Waited"); | |
| while (client.available() > 0) { | |
| client.read(); | |
| server.write("READLOOP"); | |
| } | |
| server.write("END"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment