Advertisement
cymplecy

irsend3

Dec 20th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.64 KB | None | 0 0
  1. #define VERSION 0.1
  2. #include <ESP8266WiFi.h>
  3. #include <IRremoteESP8266.h>
  4.  
  5. IRsend irsend(0); //an IR led is connected to GPIO pin 0
  6.  
  7.  
  8. #define DEBUG true
  9. WiFiClient client;
  10. char inLine[256] ="";
  11. byte myindex = 0;  // declare a string position pointer
  12. // the setup routine runs once when you press reset:
  13. void setup()
  14. {                
  15.   irsend.begin();
  16.   delay(1000);
  17.  
  18.  
  19.   WiFi.begin("CYCY", "");
  20.   while (WiFi.status() != WL_CONNECTED) {
  21.     delay(500);
  22.    }
  23.   client.connect("192.168.0.16", 42001);
  24.  
  25. }
  26.  
  27. void loop()
  28. {
  29.  
  30.   if ( client.available() ) {
  31.     // blink green is char received
  32.     irsend.sendNEC(0xFF10EF, 36); //change to green
  33.     irsend.sendNEC(0x00FFE01F, 36); //on
  34.     delay(50);
  35.     irsend.sendNEC(0x00FF609F, 36); //off
  36.     delay(50 * myindex);
  37.    
  38.  
  39.     byte byte1 = client.read();
  40.     byte byte2 = client.read();
  41.     byte byte3 = client.read();
  42.     byte byte4 = client.read();
  43.     myindex = 0;
  44.     for (int loop = 0; loop < byte4; loop++) {
  45.       byte inByte = client.read();
  46.       inLine[myindex++]  = inByte; // put the character in the next free slot.  
  47.     }        
  48.   }
  49.   inLine[myindex]      = '\0';  // always terminate your strings.  
  50.   String dataraw(inLine);
  51.   // check for broadcast msg
  52.   if (dataraw.indexOf("red") >=0) {
  53.     irsend.sendNEC(0xFF906F, 36); // change to red
  54.     irsend.sendNEC(0x00FFE01F, 36); // on
  55.     delay(50);
  56.     //dataraw = "";
  57.     //myindex = 0;  // every time we start a new string, reset the pointer
  58.   }
  59.   if (dataraw.indexOf("blue") >=0) {
  60.     irsend.sendNEC(0xFF50AF, 36); // change to blue
  61.     irsend.sendNEC(0x00FFE01F, 36); // on
  62.     delay(50);
  63.   }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement