Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BLYNK_PRINT Serial // Comment this out to disable prints and save space
- #include <ESP8266WiFi.h>
- #include <BlynkSimpleEsp8266.h>
- char ssid[] = "xxx";
- char pass[] = "yyyyyyyyyyyyyy";
- char auth[] = "sssssssssssssssssssssssss";
- WidgetLED led1(V30); // vLED indikator ESP for test
- WidgetTerminal terminal31(V31); //terminal ESP for test
- WidgetLED led00(V0); // vLEDs for NANO
- WidgetLED led01(V1); //
- WidgetLED led02(V2); //
- WidgetLED led03(V3); //
- WidgetLED led04(V4); //
- #include <WidgetRTC.h>
- WidgetRTC rtc;
- BLYNK_ATTACH_WIDGET(rtc, V25); //rtc for NANO
- WidgetTerminal terminal29(V29); //terminal for NANO
- BLYNK_WRITE_DEFAULT() // send info form APP to NANO
- {
- String strtosend = "";
- int pin = request.pin; // Which exactly pin is handled?
- strtosend += 'V' + String(pin) + ':';
- for (auto i = param.begin(); i < param.end(); ++i) { //only 1 param now
- strtosend += i.asString();
- }
- Serial.println(strtosend);
- }
- void Blynkwrite(String str2) {// command from NANO to APP
- byte pin2;
- String strdata2;
- int data2;
- if (str2.charAt(0) != 'v') pin2 = 199; else {
- String istr = str2.substring(1, str2.indexOf(':')); // nr vPin
- pin2 = istr.toInt();
- strdata2 = str2.substring(str2.indexOf(':') + 1); // if nr vPin typ int
- data2 = strdata2.toInt();
- }
- switch (pin2 + 1) { // Switch to progrma for recived vPin
- case 1: if (data2) led00.on(); else led00.off(); break; //V0 to V4 - vLEDs
- case 2: ; break;
- case 3: ; break;
- case 4: ; break;
- case 5: ; break;
- case 6: ESP_BlynkvirtualWrite_int(pin2, data2); break; //V5 to V24 /data int
- //etc.. // V25 rtc
- case 26: ESP_BlynkvirtualWrite_str(pin2, strdata2); break; // V26 to V 28 data str
- case 30: ; break; // V29 terminal
- // case 200: Serial.println("ERROR - Brak char V"); break; //Program for error
- default: ;
- }
- }
- void ESP_BlynkvirtualWrite_int(byte vPin, int intdata)
- {
- Blynk.virtualWrite(vPin, intdata);
- }
- void ESP_BlynkvirtualWrite_str(byte vPin, String strdata)
- {
- Blynk.virtualWrite(vPin, strdata);
- }
- // ....................................... recive string from serial
- bool stringComplete = false;
- String inputString = "";
- byte licznikodbioru = 0;
- void recivestrfromserial () {
- if (stringComplete) {
- Serial.println("odebralem " + String(inputString)); //test
- Blynkwrite(inputString);
- inputString = "";
- stringComplete = false;
- licznikodbioru = 0;
- }
- }
- void myserialEvent() { // string z Serial
- while (Serial.available()) {
- // Serial.println("odbior");
- licznikodbioru++;
- char inChar = (char)Serial.read();
- inputString += inChar;
- if (inChar == '\n') {
- stringComplete = true;
- }
- if (licznikodbioru > 50) inputString = "";
- }
- }
- void setup()
- {
- Serial.begin(115200);
- WifiBlynk(); //logowanie do wifi i blynk
- } //end setup
- void loop() //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> loop
- {
- Blynk.run();
- myserialEvent();
- recivestrfromserial();
- }
- //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> end loop
- void WifiBlynk() { //logowanie do wifi i blynk nie wstrzymujące wejścia do pętli głównej
- WiFi.begin(ssid, pass);
- Blynk.config(auth);
- WiFi.status();
- Blynk.connect();
- }
- bool isFirstConnect = true;
- BLYNK_CONNECTED() {
- if (isFirstConnect) {
- Blynk.syncAll(); //ważna procedura - po starcie arduino synchronizuje wszystkiw wirtualne piny ze zmiennymi programu
- isFirstConnect = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement