Advertisement
Krzyspx

brama4ESPmain

Dec 6th, 2016
3,689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.16 KB | None | 0 0
  1. /*
  2.  * v31 - terminal esp
  3.  * v32 ter on/off
  4.  * v33 serial on/off
  5.  *
  6.  * v35 setup wifi
  7.  *
  8.  */
  9.  
  10. #include "setupwifi.h"
  11. #include "transmit.h"
  12.  
  13. #define BLYNK_PRINT Serial
  14. #include <ESP8266WiFi.h>
  15. #include <BlynkSimpleEsp8266.h>
  16.  
  17.  
  18. #include <Timers.h> //  my favorite timer
  19. Timers <4> akcja; // 4  wątki
  20.  
  21. WidgetLED led1(V30); // vLED ESP indicator for test
  22. //WidgetTerminal terminal31(V31); //ESP terminal  for test
  23.  
  24.  
  25. WidgetLED led00(V0); // vLEDs for NANO   - declaration for all vLEDs
  26.  
  27. WidgetTerminal terminal29(V29); //terminal for NANO
  28.  
  29.  
  30. BLYNK_WRITE_DEFAULT() // send info form APP to NANO
  31. {
  32.   String strtosend = "";
  33.   int pin = request.pin;      // Which exactly pin is handled?
  34.   strtosend += 'V' + String(pin) + ':';
  35.   for (auto i = param.begin(); i < param.end(); ++i) { //only 1 param now
  36.     strtosend += i.asString();
  37.   }
  38.   Serial.println(strtosend);
  39. }
  40.  
  41. void Blynkwrite(String str2) {//  command from NANO to APP
  42.  
  43.   String istr = str2.substring(1, str2.indexOf(':')); // nr vPin
  44.   byte pin2 = istr.toInt();
  45.   String  strdata2 = str2.substring(str2.indexOf(':') + 1); // if nr vPin typ int
  46.   int  data2 = strdata2.toInt();
  47.   char chardata2[10];
  48.   int dl =  strdata2.length() + 1;
  49.   strdata2.toCharArray(chardata2, dl);
  50.  
  51.   if (str2.charAt(0) == 'L') led00.setVPin(pin2); led00.setValue(data2); led00.setVPin(0);  //send LEDs data to APP
  52.   if (str2.charAt(0) == 'S')  Blynk.virtualWrite(pin2, strdata2); //send str to APP
  53.   if (str2.charAt(0) == 'I')  Blynk.virtualWrite(pin2, data2); //send int to APP
  54.   if (str2.charAt(0) == 'C')  Blynk.setProperty(pin2, "color", chardata2);  // send color
  55.   if (str2.charAt(0) == 'N')  Blynk.setProperty(pin2, "onLabel", chardata2); //send button label to APP
  56.   if (str2.charAt(0) == 'F')  Blynk.setProperty(pin2, "offLabel", chardata2); //send button label to APP
  57.   if (str2.charAt(0) == 'O')  order(pin2, strdata2); //send button label to APP
  58. }
  59.  
  60. void order( byte pin4, String str4) {
  61.   int  data = str4.toInt();
  62.   if (pin4 == 1) Blynk.syncAll(); //order nr 1 - wyslać dane początkowe z APP
  63.   if (pin4 == 2) Blynk.notify(str4);
  64.   if (pin4 == 3) Blynk.email("Subject: email from BLYNK", str4);
  65.   if (pin4 == 4) terminal29.flush();
  66.   if (pin4 == 10)  akcja.updateInterval(1, data);
  67. }
  68.  
  69. void setup()
  70. {
  71.   pinMode(LED_BUILTIN, OUTPUT);
  72.   akcja.attach(0, 3000, timer1sek); //  1 sek
  73.   akcja.attach(1, 3000, blinklednano);
  74.  
  75.   Serial.begin(115200);
  76.   WifiBlynk(); //logowanie do wifi i blynk
  77.   Serial.println(F(__FILE__));  //BLYNK .3.10 Arduino IDE.cc 1.6.12
  78.  
  79. //  EEPROM.begin(512); //do wifi setup
  80. } //end setup
  81.  
  82. void loop()  //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> loop
  83. {
  84.   akcja.process(); //
  85.   Blynk.run();
  86.   myserialEvent();
  87.   recivestrfromserial();
  88. }
  89. //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  end loop
  90.  
  91. void timer1sek() {
  92.   blinkvLed();
  93.   // blinkLedNANO();
  94.   //    Serial.println("ECHO ESP");
  95. }
  96.  
  97. bool wsk3 = 0;
  98. void  blinkvLed() {
  99.   wsk3 = !wsk3;
  100.   if (wsk3)  led1.off(); else  led1.on();
  101. }
  102. bool wsk2 = 0;
  103. void  blinklednano() {
  104.   wsk2 = !wsk2;
  105.   String strtosend = 'V' + String(0) + ':' + String(wsk2);
  106.   Serial.println(strtosend);
  107.   digitalWrite(LED_BUILTIN, wsk2);
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement