Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 207 lines (187 sloc) 5.104 kb
24982225 » Todd Treece
2011-02-27 first commit
1 #include <SPI.h>
2 #include <Ethernet.h>
80403db2 » Todd Treece
2011-02-28 added dchp and dammitrob.com support
3 #include <EthernetDHCP.h>
d6f49ef0 »
2011-05-03 Updated MP3 Trigger related code
4 #include <NewSoftSerial.h>
5
6 int relay_pin = 7;
7 int rx_pin = 8;
8 int tx_pin = 9;
9 int last_song = 47;
24982225 » Todd Treece
2011-02-27 first commit
10
11 byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
80403db2 » Todd Treece
2011-02-28 added dchp and dammitrob.com support
12 byte server[] = { 192,168,0,59 };
d6f49ef0 »
2011-05-03 Updated MP3 Trigger related code
13 //byte server[] = { 10,0,1,3 } ;
24982225 » Todd Treece
2011-02-27 first commit
14 int port = 6667;
d6f49ef0 »
2011-05-03 Updated MP3 Trigger related code
15
16 unsigned long lastmillis = 0;
17
2ba015f8 »
2011-05-09 Something is broke...
18 String channel = "#test";
24982225 » Todd Treece
2011-02-27 first commit
19 String nickname = "deployBot";
e0e93d14 » Todd Treece
2011-03-09 added relay and HALbot support
20 String hal = "HALbot";
24982225 » Todd Treece
2011-02-27 first commit
21 String default_action = "alerts meatbags";
f5ce2bea »
2011-05-09 Added notices for #sparkfun
22 String default_message = "robacarp, stilldavid, mike, ross, randy, erik, brennen, ben, caseyd, todd, christoph: ready for deploy?";
80403db2 » Todd Treece
2011-02-28 added dchp and dammitrob.com support
23 String dammit_rob = "http://dammitrob.com";
e0e93d14 » Todd Treece
2011-03-09 added relay and HALbot support
24 String hal_action = "looks at stilldavid";
25 String hal_reply = "I'm sorry, Dave. I'm afraid I can't do that.";
d6f49ef0 »
2011-05-03 Updated MP3 Trigger related code
26
24982225 » Todd Treece
2011-02-27 first commit
27 Client client(server, port);
d6f49ef0 »
2011-05-03 Updated MP3 Trigger related code
28 NewSoftSerial mp3 = NewSoftSerial(rx_pin, tx_pin);
24982225 » Todd Treece
2011-02-27 first commit
29
30 void setup() {
80403db2 » Todd Treece
2011-02-28 added dchp and dammitrob.com support
31 EthernetDHCP.begin(mac, 1);
d6f49ef0 »
2011-05-03 Updated MP3 Trigger related code
32 pinMode(relay_pin, OUTPUT);
33 digitalWrite(relay_pin, LOW);
24982225 » Todd Treece
2011-02-27 first commit
34 Serial.begin(9600);
35 delay(1000);
80403db2 » Todd Treece
2011-02-28 added dchp and dammitrob.com support
36 check_dhcp();
24982225 » Todd Treece
2011-02-27 first commit
37 connect();
38 }
39
40 void loop() {
d6f49ef0 »
2011-05-03 Updated MP3 Trigger related code
41 mp3.begin(38400);
2ba015f8 »
2011-05-09 Something is broke...
42 //check_dhcp();
24982225 » Todd Treece
2011-02-27 first commit
43 if(client.available()) {
44 String data;
45 data = "";
46 while(true) {
47 char c = client.read();
2ba015f8 »
2011-05-09 Something is broke...
48 //Serial.print(c);
24982225 » Todd Treece
2011-02-27 first commit
49 if (c == '\n'){ break; }
50 data.concat(c);
51 }
52 parse_data(data);
53 }
54 if (!client.connected()) {
55 Serial.println();
56 Serial.println("Disconnecting...");
57 client.stop();
58 while(true);
59 }
60 }
61
e0e93d14 » Todd Treece
2011-03-09 added relay and HALbot support
62 void check_dhcp(){
63 if (EthernetDHCP.poll() < DhcpStateLeased){
64 Serial.println("Seeking DHCP.");
65 while(EthernetDHCP.poll() < DhcpStateLeased){
66 if (millis() - lastmillis > 100){
67 lastmillis = millis();
68 Serial.print(".");
69 }
70 }
71 Serial.println("DHCP Leased.");
72 }
73 }
74
24982225 » Todd Treece
2011-02-27 first commit
75 void connect() {
76 Serial.println("Connecting to the SparkFun IRC server...");
77 if(client.connect()) {
78 Serial.println("deployBot connected");
79 client.print("NICK ");
80 client.println(nickname);
81 client.print("USER ");
82 client.print(nickname);
83 client.print(" ");
84 client.print(nickname);
85 client.print(" ");
86 client.print(nickname);
87 client.print(" ");
88 client.println(":deployBot - sparkfun.com");
89 client.println();
80403db2 » Todd Treece
2011-02-28 added dchp and dammitrob.com support
90 client.print("JOIN ");
24982225 » Todd Treece
2011-02-27 first commit
91 client.println(channel);
2ba015f8 »
2011-05-09 Something is broke...
92
24982225 » Todd Treece
2011-02-27 first commit
93 } else {
94 Serial.println("Connection Failed");
95 }
96 }
97
98 void parse_data(String &data) {
99 if(data.startsWith("PING")) {
100 send_pong(data);
80403db2 » Todd Treece
2011-02-28 added dchp and dammitrob.com support
101 } else if(data.indexOf("PRIVMSG deployBot") != -1) {
e0e93d14 » Todd Treece
2011-03-09 added relay and HALbot support
102 if(data.startsWith(":stilldavid!") != false) {
103 client.print("NICK ");
104 client.println(hal);
105 send_action(hal_action);
106 send_message(hal_reply);
107 delay(5000);
108 client.print("NICK ");
109 client.println(nickname);
110 } else {
111 if(data.indexOf("test on") != -1) {
d6f49ef0 »
2011-05-03 Updated MP3 Trigger related code
112 deploy(false);
e0e93d14 » Todd Treece
2011-03-09 added relay and HALbot support
113 } else if(data.indexOf("test off") != -1) {
f5ce2bea »
2011-05-09 Added notices for #sparkfun
114 deployed(false);
80403db2 » Todd Treece
2011-02-28 added dchp and dammitrob.com support
115 }
116 }
24982225 » Todd Treece
2011-02-27 first commit
117 } else if(data.indexOf("PRIVMSG") != -1) {
118 if(data.indexOf("meatbags") != -1) {
119 if(data.indexOf("deploy?") != -1) {
d6f49ef0 »
2011-05-03 Updated MP3 Trigger related code
120 deploy(true);
e0e93d14 » Todd Treece
2011-03-09 added relay and HALbot support
121 } else if(data.indexOf("deployed") != -1) {
f5ce2bea »
2011-05-09 Added notices for #sparkfun
122 deployed(true);
24982225 » Todd Treece
2011-02-27 first commit
123 }
124 }
125 }
126 }
127
d6f49ef0 »
2011-05-03 Updated MP3 Trigger related code
128 void deploy(boolean alert) {
129 mp3.print("t");
130 mp3.println(random(1,last_song),BYTE);
131
132 if(alert == true) {
133 send_action(default_action);
134 send_message(default_message);
f5ce2bea »
2011-05-09 Added notices for #sparkfun
135 send_haiku(random(1,4), "#sparkfun");
d6f49ef0 »
2011-05-03 Updated MP3 Trigger related code
136 }
f5ce2bea »
2011-05-09 Added notices for #sparkfun
137
d6f49ef0 »
2011-05-03 Updated MP3 Trigger related code
138 delay(1000);
139 digitalWrite(relay_pin, HIGH);
140 }
141
f5ce2bea »
2011-05-09 Added notices for #sparkfun
142 void deployed(boolean alert) {
143 if(alert == true) {
144 send_haiku(random(4,6), "#sparkfun");
145 }
d6f49ef0 »
2011-05-03 Updated MP3 Trigger related code
146 mp3.println("O");
147 digitalWrite(relay_pin, LOW);
148 }
149
24982225 » Todd Treece
2011-02-27 first commit
150 void send_pong(String &response) {
151 client.print("PONG ");
152 client.println(response.substring(6));
153 }
154
f5ce2bea »
2011-05-09 Added notices for #sparkfun
155 void send_haiku(long number, String chan) {
156 switch(number) {
157 case 1:
158 send_notice("it's time to deploy", chan);
159 send_notice("if that does not work for you", chan);
160 send_notice("let IT know soon!", chan);
161 break;
162 case 2:
163 send_notice("when software goes live", chan);
164 send_notice("sometimes it causes problems", chan);
165 send_notice("be wise, cross fingers", chan);
166 break;
167 case 3:
168 send_notice("hold on to your butts", chan);
169 send_notice("there are many lines of code", chan);
170 send_notice("about two million", chan);
171 break;
172 case 4:
173 send_notice("the code has been pushed", chan);
174 send_notice("we hope you like new features", chan);
175 send_notice("cause damn there's a ton", chan);
176 break;
177 case 5:
178 send_notice("i hope you weren't scared", chan);
179 send_notice("everything went really well", chan);
180 send_notice("you can work again", chan);
181 break;
182 }
183 }
184
185 void send_notice(String notice, String chan) {
186 client.print("NOTICE ");
187 client.print(chan);
188 client.print(" :");
189 client.println(notice);
190 }
191
24982225 » Todd Treece
2011-02-27 first commit
192 void send_action(String &action) {
193 client.print("PRIVMSG ");
194 client.print(channel);
195 client.print(" :");
196 client.print(1,BYTE);
197 client.print("ACTION ");
198 client.print(action);
199 client.println(1,BYTE);
200 }
201
202 void send_message(String &message) {
203 client.print("PRIVMSG ");
204 client.print(channel);
205 client.print(" :");
206 client.println(message);
207 }
Something went wrong with that request. Please try again.