Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.15 KB | None | 0 0
  1.  
  2.  
  3. #include <ESP8266WiFi.h>
  4. #include <RCSwitch.h>
  5. #include <BlynkSimpleEsp8266.h>
  6. #include <SimpleTimer.h>
  7.  
  8. //******************************************************************
  9. // Defines
  10. //******************************************************************
  11. // 433Mhz Settings
  12. #define PACKET_LENGTH 24
  13. // Weihanchtsbaum weiß
  14. #define SWITCH_1_ON 1001110000
  15. #define SWITCH_1_OFF 1001110000
  16. // Weinachtsbaum bunt
  17. #define SWITCH_2_ON 1001101000
  18. #define SWITCH_2_OFF 1001101000
  19. // Girlande Tür
  20. #define SWITCH_3_ON 1001100100
  21. #define SWITCH_3_OFF 1001100100
  22. // Girlande Treppe
  23. #define SWITCH_4_ON 1001100010
  24. #define SWITCH_4_OFF 1001100010
  25. // Winterdorf / TV
  26. #define SWITCH_5_ON 1101101000
  27. #define SWITCH_5_OFF 1101101000
  28.  
  29. //******************************************************************
  30. // Create Class-Objects
  31. //******************************************************************
  32. RCSwitch mySwitch = RCSwitch();
  33. WidgetLED led1(V10); //register to virtual pin 1
  34. WidgetLED led2(V11); //register to virtual pin 1
  35. SimpleTimer timer;
  36.  
  37. //******************************************************************
  38. // Global Variables
  39. //******************************************************************
  40. const char* blynk_auth_token = "";
  41. const char* ssid = "";
  42. const char* password = "";
  43.  
  44. bool BlynkConExist = false;
  45.  
  46. //******************************************************************
  47. // Setup Function
  48. //******************************************************************
  49. void setup()
  50. {
  51. // work arround for a bug, to disable access point...
  52. WiFi.persistent(false);
  53.  
  54. // Initialize RCSwitch and select Pin which is used for sending the data
  55. mySwitch.enableTransmit(16);
  56. Serial.begin(115200);
  57.  
  58. // Initialize Blynk connection
  59. Blynk.begin(blynk_auth_token, ssid, password);
  60. Blynk.connect();
  61.  
  62. // waint until WiFi becomes connected
  63. while (WiFi.status() != WL_CONNECTED) {
  64. delay(500);
  65. Serial.print(".");
  66. }
  67.  
  68. // Set initial LED States
  69. led1.off();
  70. led2.off();
  71.  
  72. Serial.println("WiFi connected");
  73. Serial.println("IP address: ");
  74. Serial.println(WiFi.localIP());
  75.  
  76. // check every 10 seconds if still connected
  77. timer.setInterval(10000L, CheckConnection);
  78.  
  79. }
  80.  
  81. //******************************************************************
  82. // Check WiFi Connection and try to establish if disconnected
  83. //******************************************************************
  84. void CheckConnection(){
  85.  
  86. // Check if connected and the Flag Value, Set connected Flag is connected
  87. if (Blynk.connected() && (BlynkConExist == false) ) {
  88. BlynkConExist = true;
  89. Blynk.notify("RC433: is now online");
  90. }
  91. // Reset connected Flag if not connected
  92. if (!(Blynk.connected()) && (BlynkConExist == true) ) {
  93. BlynkConExist = false;
  94. }
  95.  
  96. if(!BlynkConExist){
  97. Blynk.connect(40000); // 40000 ~ 10Sec timeout
  98. }
  99. }
  100.  
  101. //******************************************************************
  102. // Turn once Switches ON/OFF
  103. //******************************************************************
  104. //### Action for Virtual Pin 0: Switch 1 ON
  105. BLYNK_WRITE(0) {
  106. mySwitch.send(SWITCH_1_ON, PACKET_LENGTH);
  107. }
  108.  
  109. //### Action for Virtual Pin 1: Switch 1 OFF
  110. BLYNK_WRITE(1) {
  111. mySwitch.send(SWITCH_1_OFF, PACKET_LENGTH);
  112. }
  113.  
  114. //### Action for Virtual Pin 2: Switch 2 ON
  115. BLYNK_WRITE(2) {
  116. mySwitch.send(SWITCH_2_ON, PACKET_LENGTH);
  117. }
  118.  
  119. //### Action for Virtual Pin 3: Switch 2 OFF
  120. BLYNK_WRITE(3) {
  121. mySwitch.send(SWITCH_2_OFF, PACKET_LENGTH);
  122. }
  123.  
  124. //### Action for Virtual Pin 4: Switch 3 ON
  125. BLYNK_WRITE(4) {
  126. mySwitch.send(SWITCH_3_ON, PACKET_LENGTH);
  127. }
  128.  
  129. //### Action for Virtual Pin 5: Switch 3 OFF
  130. BLYNK_WRITE(5) {
  131. mySwitch.send(SWITCH_3_OFF, PACKET_LENGTH);
  132. }
  133. //### Action for Virtual Pin 6: Switch 4 ON
  134. BLYNK_WRITE(6) {
  135. mySwitch.send(SWITCH_4_ON, PACKET_LENGTH);
  136. }
  137.  
  138. //### Action for Virtual Pin 7: Switch 4 OFF
  139. BLYNK_WRITE(7) {
  140. mySwitch.send(SWITCH_4_OFF, PACKET_LENGTH);
  141. }
  142. //### Action for Virtual Pin 8: Switch 5 ON
  143. BLYNK_WRITE(6) {
  144. mySwitch.send(SWITCH_5_ON, PACKET_LENGTH);
  145. }
  146.  
  147. //### Action for Virtual Pin 9: Switch 5 OFF
  148. BLYNK_WRITE(7) {
  149. mySwitch.send(SWITCH_5_OFF, PACKET_LENGTH);
  150. }
  151. //******************************************************************
  152. // Turn all Switches ON or OFF
  153. //******************************************************************
  154. //### Action for Virtual Pin 6: All ON
  155. //BLYNK_WRITE(6) {
  156. // mySwitch.send(SWITCH_1_ON, PACKET_LENGTH);
  157. //delay(100);
  158. //mySwitch.send(SWITCH_2_ON, PACKET_LENGTH);
  159. //delay(100);
  160. //mySwitch.send(SWITCH_3_ON, PACKET_LENGTH);
  161. //}
  162.  
  163. //### Action for Virtual Pin 7: All OFF
  164. //BLYNK_WRITE(7) {
  165. // mySwitch.send(SWITCH_1_OFF, PACKET_LENGTH);
  166. //delay(100);
  167. //mySwitch.send(SWITCH_2_OFF, PACKET_LENGTH);
  168. //delay(100);
  169. //mySwitch.send(SWITCH_3_OFF, PACKET_LENGTH);
  170. //}
  171. //******************************************************************
  172. // Timer Controlled ON/OFF Operation on Switch 1 and 3
  173. //******************************************************************
  174. //### Timer 1: Turn Switch 1 ON than OFF
  175. //BLYNK_WRITE(8)
  176. //{
  177. // if(param.asInt() == 1) {
  178. // mySwitch.send(SWITCH_1_ON, PACKET_LENGTH);
  179. // led1.on();
  180. // Blynk.notify("RC433: Timer controlled Switch 1 is now ON");
  181. // }
  182. // else {
  183. // mySwitch.send(SWITCH_1_OFF, PACKET_LENGTH);
  184. // led1.off();
  185. // Blynk.notify("RC433: Timer controlled Switch 1 is now OFF");
  186. // }
  187. //}
  188. //### Timer 2: Turn Switch 3 ON than OFF
  189. //BLYNK_WRITE(9)
  190. //{
  191. // if(param.asInt() == 1) {
  192. // mySwitch.send(SWITCH_3_ON, PACKET_LENGTH);
  193. // Blynk.notify("RC433: Timer controlled Switch 3 is now ON");
  194. // led2.on();
  195. // }
  196. // else {
  197. // mySwitch.send(SWITCH_3_OFF, PACKET_LENGTH);
  198. // Blynk.notify("RC433: Timer controlled Switch 3 is now OFF");
  199. // led2.off();
  200. // }
  201. //}
  202. //******************************************************************
  203. // Endless Loop (main() function)
  204. //******************************************************************
  205. void loop() {
  206. if(BlynkConExist){
  207. Blynk.run();
  208. }
  209. timer.run();
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement