Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- #include <BlynkSimpleEthernet.h>
- #include <IRremote.h>
- // You should get Auth Token in the Blynk App.
- // Go to the Project Settings (nut icon).
- char auth[] = "PUTYOURAUTHTOKENHERE";
- byte mac[] = {
- 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
- };
- // fill in an available IP address on your network here,
- // for manual configuration:
- IPAddress ip(192, 168, 0, 13);
- // fill in your Domain Name Server address here:
- IPAddress myDns(8, 8, 8, 8);
- // initialize the library instance:
- EthernetClient client;
- char server[] = "blynk-cloud.com";
- //IPAddress server(64,131,82,241);
- unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
- const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
- // the "L" is needed to use long type numbers
- #define W5100_CS 10
- #define SDCARD_CS 4
- const int switchPin = 7;
- int delayPeriod = 500;
- IRsend irsend;
- void setup()
- {
- Serial.begin(9600);
- Ethernet.begin(mac, ip);
- while (!Serial) {
- ; // wait for serial port to connect. Needed for native USB port only
- }
- // give the ethernet module time to boot up:
- delay(1000);
- // start the Ethernet connection using a fixed IP address and DNS server:
- Ethernet.begin(mac, ip, myDns);
- // print the Ethernet board/shield's IP address:
- Serial.print("My IP address: ");
- Serial.println(Ethernet.localIP());
- pinMode(SDCARD_CS, OUTPUT);
- digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
- Blynk.begin(auth);
- // You can also specify server:
- //Blynk.begin(auth, "blynk-cloud.com", 8442);
- //Blynk.begin(auth, IPAddress(192,168,1,100), 8442);
- // Set Switch pin as Input
- pinMode(switchPin, INPUT);
- }
- void loop()
- {
- // if there's incoming data from the net connection.
- // send it out the serial port. This is for debugging
- // purposes only:
- if (client.available()) {
- char c = client.read();
- Serial.write(c);
- }
- // if ten seconds have passed since your last connection,
- // then connect again and send data:
- if (millis() - lastConnectionTime > postingInterval) {
- httpRequest();
- }
- int buttonState = 0;
- Blynk.run();
- // You can inject your own code or combine it with other sketches.
- // Check other examples on how to communicate with Blynk. Remember
- // to avoid delay() function!
- // Set button state depending upon switch position
- buttonState = digitalRead(switchPin);
- // If button is pressed send power code command
- if (buttonState == HIGH) {
- // NB: Not all protocols are supported by IRremote or IRLib. You may need to edit the code below manually
- // Automatically Generated by AnalysIR for xxxxxxxx, visit http://www.AnalysIR.com or email info@....... for further details
- int khz = 38; //NB Change this default value as neccessary to the correct modulation frequency
- unsigned int Signal_0_0[] = {4550, 4400, 600, 1650, 550, 1650, 600, 1650, 550, 550, 600, 500, 600, 550, 550, 550, 600, 500, 600, 1650, 600, 1600, 600, 1650, 550, 550, 600, 500, 600, 550, 600, 500, 600, 500, 650, 450, 650, 1600, 600, 500, 650, 450, 650, 500, 600, 500, 600, 500, 600, 550, 600, 1600, 600, 500, 650, 1600, 650, 1550, 650, 1600, 650, 1550, 650, 1600, 650, 1600, 600}; //AnalysIR Batch Export - RAW
- irsend.sendRaw(Signal_0_0, sizeof(Signal_0_0) / sizeof(int), khz); //AnalysIR Batch Export - RAW
- // AnalysIR IR Protocol: RAW, Key:
- }
- }
- // this method makes a HTTP connection to the server:
- void httpRequest() {
- // close any connection before send a new request.
- // This will free the socket on the WiFi shield
- client.stop();
- // if there's a successful connection:
- if (client.connect(server, 80)) {
- Serial.println("connecting...");
- // send the HTTP GET request:
- client.println("GET /dd718b2f62c54cc487a6c40a3f2cded7/update/D7?value=0 HTTP/1.1");
- client.println("Host: blynk-cloud.com");
- client.println("User-Agent: arduino-ethernet");
- client.println("Connection: close");
- client.println();
- // note the time that the connection was made:
- lastConnectionTime = millis();
- } else {
- // if you couldn't make a connection:
- Serial.println("connection failed");
- }
- delay(500);
- }
Add Comment
Please, Sign In to add comment