Advertisement
Krzyspx

Test komunikacji w BLYNK

Sep 10th, 2017
885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. char ssid[] = "xxxxxx";
  2. char pass[] = "yyyyyyyyyyyyy";
  3. #define BLYNK_PRINT Serial
  4. #include <ESP8266WiFi.h>
  5. #include <BlynkSimpleEsp8266.h>
  6.  
  7. #include "dallas.h"
  8. #include <OneWire.h>
  9. #include <DallasTemperature.h>
  10. #include <Timers.h> //  my favorite timer
  11. Timers <2> akcja; //
  12.  
  13. char auth[] = "f845be3b89e74d28b164bd8a9c1d38ba"; //konto na local server konto blynk.pl@gmail.com
  14.  
  15. #define led_blue 14
  16. #define led_bialy 12
  17. #define klaw1 4
  18. #define klaw2 5
  19.  
  20. #define BLYNK_GREEN     "#23C48E"
  21. #define BLYNK_YELLOW    "#ED9D00"
  22. #define BLYNK_RED       "#D3435C"
  23. #define _RED            "#FF0000"
  24. #define _GREEN          "#00FF00"
  25.  
  26. WidgetLED led1(V0);
  27.  
  28. int button1 = 0;
  29. int wskrunAr = 0; //vLED miga co sek wskaznik aktywności procesora
  30.  
  31. void setup()
  32. {
  33.   pinMode(led_blue, OUTPUT); //LED niebieski
  34.   pinMode(led_bialy, OUTPUT); //LED bialy
  35.   pinMode(klaw1, INPUT);
  36.   pinMode(klaw2, INPUT);
  37.  
  38.   Serial.begin(115200);
  39.   delay(100);
  40.   Serial.println();
  41.   Serial.println(F(__FILE__));  //BLYNK .4.8 Arduino IDE.cc 1.8.3
  42.  
  43.   akcja.attach(0, 1000, timer1sek); //  1 sek
  44.   setdallas(); //setup for ds18b20
  45.  
  46.   Blynk.begin(auth, ssid, pass, IPAddress(192, 168, 2, 19));
  47. }
  48.  
  49. void loop()
  50. {
  51.   akcja.process(); // timer
  52.   Blynk.run();
  53. }
  54.  
  55. void miganievLED()
  56. {
  57.   wskrunAr = !wskrunAr ;
  58.   if (wskrunAr == 0) {
  59.     led1.off(); //miganie vLED dla kontroli połączenia
  60.   }
  61.   else {
  62.     led1.on();
  63.   }
  64. }
  65. void timer1sek() { //różne rzeczy wykonywane cyklicznie
  66.   sensorT();    //czytanie i wysyłanie temp dallas
  67.   testbutton(); //symulacja sprzężenia zwrotnego
  68.   miganievLED(); //wskaźnik vLED działania komunikacji
  69. }
  70.  
  71. void testbutton()
  72. {
  73.   if (button1 == 1) {
  74.     Blynk.setProperty(V1, "color", _RED);
  75.   } else {
  76.     Blynk.setProperty(V1, "color", BLYNK_GREEN);
  77.   }
  78. }
  79. BLYNK_WRITE(V1) //odczyt przycisku niebieskiego z aplikacji
  80. {
  81.   button1 = param.asInt();
  82.   if (button1 == 0) {
  83.     digitalWrite(led_bialy, HIGH);  //wyłączenie LEDa na płytce testowej
  84.     Blynk.setProperty(V1, "onLabel", "on");
  85.     Serial.println("Button z potwierdzeniem OFF");
  86.   };
  87.   if (button1 == 1) {
  88.     digitalWrite(led_bialy, LOW);
  89.     Serial.println("Button z potwierdzeniem ON");
  90.   };
  91. }
  92. BLYNK_WRITE(V5)
  93. {
  94.  int button2 = param.asInt();
  95.   if (button2 == 0) {
  96.     digitalWrite(led_blue, HIGH);
  97.     Serial.println("Button BLUE OFF");
  98.   };
  99.   if (button2 == 1) {
  100.     digitalWrite(led_blue, LOW);
  101.     Serial.println("Button BLUE ON");
  102.   };
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement