Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define VERSION 0.1
- #include <ESP8266WiFi.h>
- #include <IRremoteESP8266.h>
- IRsend irsend(0); //an IR led is connected to GPIO pin 0
- #define DEBUG true
- WiFiClient client;
- char inLine[256] ="";
- byte myindex = 0; // declare a string position pointer
- // the setup routine runs once when you press reset:
- void setup()
- {
- irsend.begin();
- delay(1000);
- WiFi.begin("CYCY", "");
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- }
- client.connect("192.168.0.16", 42001);
- }
- void loop()
- {
- if ( client.available() ) {
- // blink green is char received
- irsend.sendNEC(0xFF10EF, 36); //change to green
- irsend.sendNEC(0x00FFE01F, 36); //on
- delay(50);
- irsend.sendNEC(0x00FF609F, 36); //off
- delay(50 * myindex);
- byte byte1 = client.read();
- byte byte2 = client.read();
- byte byte3 = client.read();
- byte byte4 = client.read();
- myindex = 0;
- for (int loop = 0; loop < byte4; loop++) {
- byte inByte = client.read();
- inLine[myindex++] = inByte; // put the character in the next free slot.
- }
- }
- inLine[myindex] = '\0'; // always terminate your strings.
- String dataraw(inLine);
- // check for broadcast msg
- if (dataraw.indexOf("red") >=0) {
- irsend.sendNEC(0xFF906F, 36); // change to red
- irsend.sendNEC(0x00FFE01F, 36); // on
- delay(50);
- //dataraw = "";
- //myindex = 0; // every time we start a new string, reset the pointer
- }
- if (dataraw.indexOf("blue") >=0) {
- irsend.sendNEC(0xFF50AF, 36); // change to blue
- irsend.sendNEC(0x00FFE01F, 36); // on
- delay(50);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement