Guest User

Untitled

a guest
Mar 18th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include <BlynkSimpleEthernet.h>
  4. #include <IRremote.h>
  5.  
  6. // You should get Auth Token in the Blynk App.
  7. // Go to the Project Settings (nut icon).
  8. char auth[] = "PUTYOURAUTHTOKENHERE";
  9. byte mac[] = {
  10. 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
  11. };
  12. // fill in an available IP address on your network here,
  13. // for manual configuration:
  14. IPAddress ip(192, 168, 0, 13);
  15.  
  16. // fill in your Domain Name Server address here:
  17. IPAddress myDns(8, 8, 8, 8);
  18.  
  19. // initialize the library instance:
  20. EthernetClient client;
  21.  
  22. char server[] = "blynk-cloud.com";
  23. //IPAddress server(64,131,82,241);
  24.  
  25. unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
  26. const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
  27. // the "L" is needed to use long type numbers
  28.  
  29. #define W5100_CS 10
  30. #define SDCARD_CS 4
  31.  
  32. const int switchPin = 7;
  33.  
  34. int delayPeriod = 500;
  35. IRsend irsend;
  36.  
  37. void setup()
  38. {
  39.  
  40. Serial.begin(9600);
  41. Ethernet.begin(mac, ip);
  42. while (!Serial) {
  43. ; // wait for serial port to connect. Needed for native USB port only
  44. }
  45. // give the ethernet module time to boot up:
  46. delay(1000);
  47. // start the Ethernet connection using a fixed IP address and DNS server:
  48. Ethernet.begin(mac, ip, myDns);
  49. // print the Ethernet board/shield's IP address:
  50. Serial.print("My IP address: ");
  51. Serial.println(Ethernet.localIP());
  52.  
  53. pinMode(SDCARD_CS, OUTPUT);
  54. digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
  55.  
  56. Blynk.begin(auth);
  57. // You can also specify server:
  58. //Blynk.begin(auth, "blynk-cloud.com", 8442);
  59. //Blynk.begin(auth, IPAddress(192,168,1,100), 8442);
  60.  
  61. // Set Switch pin as Input
  62. pinMode(switchPin, INPUT);
  63. }
  64.  
  65. void loop()
  66. {
  67. // if there's incoming data from the net connection.
  68. // send it out the serial port. This is for debugging
  69. // purposes only:
  70. if (client.available()) {
  71. char c = client.read();
  72. Serial.write(c);
  73. }
  74.  
  75. // if ten seconds have passed since your last connection,
  76. // then connect again and send data:
  77. if (millis() - lastConnectionTime > postingInterval) {
  78. httpRequest();
  79. }
  80.  
  81. int buttonState = 0;
  82.  
  83. Blynk.run();
  84. // You can inject your own code or combine it with other sketches.
  85. // Check other examples on how to communicate with Blynk. Remember
  86. // to avoid delay() function!
  87.  
  88. // Set button state depending upon switch position
  89. buttonState = digitalRead(switchPin);
  90.  
  91. // If button is pressed send power code command
  92.  
  93. if (buttonState == HIGH) {
  94.  
  95. // NB: Not all protocols are supported by IRremote or IRLib. You may need to edit the code below manually
  96. // Automatically Generated by AnalysIR for xxxxxxxx, visit http://www.AnalysIR.com or email info@....... for further details
  97. int khz = 38; //NB Change this default value as neccessary to the correct modulation frequency
  98.  
  99. 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
  100.  
  101. irsend.sendRaw(Signal_0_0, sizeof(Signal_0_0) / sizeof(int), khz); //AnalysIR Batch Export - RAW
  102. // AnalysIR IR Protocol: RAW, Key:
  103.  
  104. }
  105. }
  106.  
  107. // this method makes a HTTP connection to the server:
  108. void httpRequest() {
  109. // close any connection before send a new request.
  110. // This will free the socket on the WiFi shield
  111. client.stop();
  112.  
  113. // if there's a successful connection:
  114. if (client.connect(server, 80)) {
  115. Serial.println("connecting...");
  116. // send the HTTP GET request:
  117. client.println("GET /dd718b2f62c54cc487a6c40a3f2cded7/update/D7?value=0 HTTP/1.1");
  118. client.println("Host: blynk-cloud.com");
  119. client.println("User-Agent: arduino-ethernet");
  120. client.println("Connection: close");
  121. client.println();
  122.  
  123. // note the time that the connection was made:
  124. lastConnectionTime = millis();
  125. } else {
  126. // if you couldn't make a connection:
  127. Serial.println("connection failed");
  128. }
  129. delay(500);
  130. }
Add Comment
Please, Sign In to add comment