- THE CODE:
- #include <ESP8266WiFi.h>
- #include <BlynkSimpleEsp8266.h>
- #include <RCSwitch.h>
- BlynkTimer clocktime;
- #define relayfan 5
- #define relaylight 6
- #define relaylightb 7
- #define relayrandom 2
- #define VPIN_BUTTON_1 V12
- #define VPIN_BUTTON_2 V13
- #define VPIN_BUTTON_3 V14
- #define VPIN_BUTTON_4 V15
- RCSwitch mySwitch = RCSwitch();
- int relayfanstate = HIGH;
- int relaylightstate = HIGH;
- int relaylightbstate = HIGH;
- int relayrandomstate = HIGH;
- int mainstate = HIGH;
- long code;
- char auth[] = "rJUG7fhgXk9Y7OlowTontA1C2irfpgs2";
- const char *ssid = "Nag";
- const char *pass = "87654321";
- BLYNK_CONNECTED()
- {
- Serial.println("blynk connected first function");
- Blynk.syncVirtual(VPIN_BUTTON_1);
- Blynk.syncVirtual(VPIN_BUTTON_2);
- Blynk.syncVirtual(VPIN_BUTTON_3);
- Blynk.syncVirtual(VPIN_BUTTON_4);
- }
- BLYNK_WRITE(VPIN_BUTTON_1)
- {
- Serial.println("blynk write");
- relayfanstate = param.asInt();
- digitalWrite(relayfan, relayfanstate);
- }
- BLYNK_WRITE(VPIN_BUTTON_2)
- {
- Serial.println("blynk write");
- relaylightstate = param.asInt();
- digitalWrite(relaylight, relaylightstate);
- }
- BLYNK_WRITE(VPIN_BUTTON_3)
- {
- Serial.println("blynk write");
- relaylightbstate = param.asInt();
- digitalWrite(relaylightb, relaylightbstate);
- }
- BLYNK_WRITE(VPIN_BUTTON_4)
- {
- Serial.println("blynk write");
- relayrandomstate = param.asInt();
- digitalWrite(relayrandom, relayrandomstate);
- }
- void setup()
- {
- Serial.begin(9600);
- mySwitch.enableReceive(0);
- pinMode(relayfan, OUTPUT);
- pinMode(relaylight, OUTPUT);
- pinMode(relaylightb, OUTPUT);
- pinMode(relayrandom, OUTPUT);
- digitalWrite(relayfan, HIGH);
- digitalWrite(relaylight, HIGH);
- digitalWrite(relaylightb, HIGH);
- digitalWrite(relayrandom, HIGH);
- Serial.println("Start");
- WiFi.begin(ssid, pass);
- Serial.println("wifi config done");
- Blynk.config(auth);//, ssid, pass);
- Serial.println("Blynk config done");
- }
- void loop()
- {
- if (WiFi.status() != WL_CONNECTED)
- {
- Serial.println("Not Connected");
- Serial.println("Without internet rf code recieving started");
- delay(500);
- if (mySwitch.available())
- {
- Serial.println("Switch available");
- code = mySwitch.getReceivedValue();
- if (mySwitch.getReceivedValue() == 8594433)
- {
- Serial.println("code matched without internet");
- mainstate = !mainstate;
- digitalWrite(relayfan, mainstate);
- digitalWrite(relaylight, mainstate);
- digitalWrite(relaylightb, mainstate);
- digitalWrite(relayrandom, mainstate);
- delay(1000);
- mySwitch.resetAvailable();
- }
- else if(mySwitch.getReceivedValue() == 8594447)
- {
- digitalWrite(relayfan, LOW);
- delay(1000);
- mySwitch.resetAvailable();
- }
- else if(mySwitch.getReceivedValue() == 8594445)
- {
- digitalWrite(relayfan, HIGH);
- delay(1000);
- mySwitch.resetAvailable();
- }
- else if(mySwitch.getReceivedValue() == 8594436)
- {
- relaylightstate = !relaylightstate;
- digitalWrite(relaylight, relaylightstate);
- delay(1000);
- mySwitch.resetAvailable();
- }
- else if(mySwitch.getReceivedValue() == 8594437)
- {
- relaylightbstate = !relaylightbstate;
- digitalWrite(relaylightb, relaylightbstate);
- delay(1000);
- mySwitch.resetAvailable();
- }
- else if(mySwitch.getReceivedValue() == 8594439)
- {
- relayrandomstate = !relayrandomstate;
- digitalWrite(relayrandom, relayrandomstate);
- delay(1000);
- mySwitch.resetAvailable();
- }
- }
- }
- else
- {
- Serial.println(" Connected");
- Blynk.run();
- with_internet();
- }
- clocktime.run();
- }
- void with_internet()
- {
- Serial.println("With internet rf code recieving started");
- delay(500);
- if (mySwitch.available())
- {
- Serial.println("Switch available");
- code = mySwitch.getReceivedValue();
- if (mySwitch.getReceivedValue() == 8594433)
- {
- Serial.println("code matched without internet");
- mainstate = !mainstate;
- digitalWrite(relayfan, mainstate);
- digitalWrite(relaylight, mainstate);
- digitalWrite(relaylightb, mainstate);
- digitalWrite(relayrandom, mainstate);
- Blynk.virtualWrite(VPIN_BUTTON_1, mainstate);
- Blynk.virtualWrite(VPIN_BUTTON_2, mainstate);
- Blynk.virtualWrite(VPIN_BUTTON_3, mainstate);
- Blynk.virtualWrite(VPIN_BUTTON_4, mainstate);
- delay(1000);
- mySwitch.resetAvailable();
- }
- else if(mySwitch.getReceivedValue() == 8594447)
- {
- digitalWrite(relayfan, LOW);
- Blynk.virtualWrite(VPIN_BUTTON_1, LOW);
- delay(1000);
- mySwitch.resetAvailable();
- }
- else if(mySwitch.getReceivedValue() == 8594445)
- {
- digitalWrite(relayfan, HIGH);
- Blynk.virtualWrite(VPIN_BUTTON_1, HIGH);
- delay(1000);
- mySwitch.resetAvailable();
- }
- else if(mySwitch.getReceivedValue() == 8594436)
- {
- relaylightstate = !relaylightstate;
- digitalWrite(relaylight, relaylightstate);
- Blynk.virtualWrite(VPIN_BUTTON_2, relaylightstate);
- delay(1000);
- mySwitch.resetAvailable();
- }
- else if(mySwitch.getReceivedValue() == 8594437)
- {
- relaylightbstate = !relaylightbstate;
- digitalWrite(relaylightb, relaylightbstate);
- Blynk.virtualWrite(VPIN_BUTTON_3, relaylightbstate);
- delay(1000);
- mySwitch.resetAvailable();
- }
- else if(mySwitch.getReceivedValue() == 8594439)
- {
- relayrandomstate = !relayrandomstate;
- digitalWrite(relayrandom, relayrandomstate);
- Blynk.virtualWrite(VPIN_BUTTON_4, relayrandomstate);
- delay(1000);
- mySwitch.resetAvailable();
- }
- }
- }
⸮L⸮⸮⸮ՋR(⸮⸮^⸮̓#⸮⸮;'⸮⸮(Zs"⸮⸮Z|⸮⸮⸮'⸮⸮⸮'⸮⸮⸮!#⸮⸮⸮G⸮⸮⸮⸮⸮h⸮y⸮⸮⸮⸮'⸮⸮LD⸮⸮J⸮*J⸮⸮⸮⸮⸮⸮⸮LD⸮⸮⸮⸮F(⸮y⸮⸮'1⸮L⸮⸮⸮
This only specific to this code maybe something wrong in my code but
When I upload a default basic scetch from the Blynk website
- #define BLYNK_PRINT Serial
- #include <ESP8266WiFi.h>
- #include <BlynkSimpleEsp8266.h>
- // You should get Auth Token in the Blynk App.
- // Go to the Project Settings (nut icon).
- char auth[] = "YourAuthToken";
- // Your WiFi credentials.
- // Set password to "" for open networks.
- char ssid[] = "YourNetworkName";
- char pass[] = "YourPassword";
- void setup()
- {
- // Debug console
- Serial.begin(9600);
- Blynk.begin(auth, ssid, pass);
- // You can also specify server:
- //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
- //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
- }
- void loop()
- {
- Blynk.run();
- // You can inject your own code or combine it with other sketches.
- // Check other examples on how to communicate with Blynk. Remember
- // to avoid delay() function!
- }
From my little research this is something called blocking code which prevents nodemcu from running it's services maybe I'm wron someone please correct me .