Arduino IRC Idler


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2.   Basic IRC Client
  3.  
  4.  This sketch connects to an IRC Server and Idles in a
  5.  specified Channel
  6.  
  7.  Circuit:
  8.  * Ethernet shield attached to pins 10, 11, 12, 13
  9.  
  10.  Credits :
  11.  * Arduino Web Client by David A. Mellis
  12.  
  13.  created 18 Jan 2011
  14.  by Keiran "Affix" Smith <[email protected]>
  15.  
  16.  */
  17.  
  18. #include <SPI.h>
  19. #include <Ethernet.h>
  20.  
  21. // Enter a MAC address and IP address for your controller below.
  22. // The IP address will be dependent on your local network:
  23. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  24. byte ip[] = { 192,168,1,28 };
  25. byte server[] = { 38,229,70,20 }; // Freenode
  26. int port = 6667;
  27. String chan = "#arduino";
  28. String nick = "arduBot";
  29. String join = "JOIN ";
  30. String nickcmd = "NICK ";
  31. String user = "USER ";
  32. String pong = "PONG ";
  33.  
  34.  
  35. Client client(server, port);
  36.  
  37. void setup() {
  38. Ethernet.begin(mac, ip);
  39. Serial.begin(9600);
  40. delay(1000);
  41. Serial.println("connecting to IRC Server...");
  42.  
  43. if (client.connect()) {
  44. Serial.println("connected");
  45. client.println(nickcmd.concat(nick));
  46. client.println(user.concat(nick));
  47. client.println();
  48. }
  49. else {
  50. Serial.println("connection failed");
  51. }
  52. }
  53.  
  54. void loop()
  55. {
  56. if (client.available()) {
  57. client.println(join.concat(chan));
  58. while(true)
  59. {
  60. String data;
  61. data = client.read();
  62.  
  63. if(data.startsWith("PING"))
  64. {
  65. client.println(pong.concat(data.substring(5)));
  66. }
  67. }
  68. }
  69.  
  70. if (!client.connected()) {
  71. Serial.println();
  72. Serial.println("disconnecting.");
  73. client.stop();
  74. for(;;)
  75. ;
  76. }
  77. }

URL: http://affix.me

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.