ok thanks
sir how to update physical relay status to blynk app, when wifi connected.
#include "FastLED.h"
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define LED_PIN 6
#define NUM_LEDS 33 // Number of LEDs connected.
#define BRIGHTNESS 64 // Default LED brightness.
#define LED_TYPE WS2812B
#define COLOR_ORDER GBR
CRGB leds[NUM_LEDS];
char auth[] = "";
char ssid[] = "";
char pass[] = "";
char server[] = "blynk-cloud.com";
int port = 8080;
int ReCnctFlag;
int ReCnctCount = 0;
BlynkTimer timer;
int r = 0;
int g = 0;
int b = 0;
int autoMode = 0;
uint8_t gHue = 0;
bool rele;
void setup()
{
//********** CHANGE PIN FUNCTION TO GPIO **********
//GPIO 1 (TX) swap the pin to a GPIO.
pinMode(1, FUNCTION_3);
//GPIO 3 (RX) swap the pin to a GPIO.
pinMode(3, FUNCTION_3);
//**************************************************
WiFi.begin(ssid, pass);
Blynk.config(auth, server, port);
if (WiFi.status() == WL_CONNECTED) {
Blynk.connect(2000);
}
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
FastLED.setBrightness(BRIGHTNESS);
#define FRAMES_PER_SECOND 120
pinMode(D0, INPUT);
pinMode(D1, INPUT);
pinMode(D2, INPUT);
pinMode(D5, INPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);
pinMode(D8, OUTPUT);
}
BLYNK_WRITE(V0)
{
rele = param.asInt();
digitalWrite(D3, rele);
}
BLYNK_WRITE(V1)
{
rele = param.asInt();
digitalWrite(D4, rele);
}
BLYNK_WRITE(V2)
{
rele = param.asInt();
digitalWrite(D7, rele);
}
BLYNK_WRITE(V3)
{
rele = param.asInt();
digitalWrite(D8, rele);
}
//--- Toggle Auto/Manual Mode ---
BLYNK_WRITE(V4) {
autoMode = param.asInt();
}
//--- Red slider value---
BLYNK_WRITE(V6){
r = param.asInt();
}
BLYNK_WRITE(V7) {
g = param.asInt();
}
//--- Blue slider value---
BLYNK_WRITE(V8) {
b = param.asInt();
}
void loop()
{
timer.run();
if (WiFi.status() == WL_CONNECTED) {
if (Blynk.connected() == true) {
Blynk.run();
}
else {
Blynk.connect(3000);
}
}
if(autoMode == 0) {
for (int i = 0; i < NUM_LEDS; i++){
leds[i] = CRGB(r, g, b);
FastLED.show();
}
}
if(autoMode == 1 ) {
fill_rainbow( leds, NUM_LEDS, gHue, 7);
// send the 'leds' array out to the actual LED strip
FastLED.show();
// insert a delay to keep the framerate modest
FastLED.delay(100/FRAMES_PER_SECOND);
EVERY_N_MILLISECONDS(20) {
gHue++; // slowly cycle the "base color" through the rainbow
}
}
if (digitalRead(D0))
{
rele = !rele;
digitalWrite(D3, rele);
Blynk.virtualWrite(V0, rele);
delay (450);
}
if (digitalRead(D1))
{
rele = !rele;
digitalWrite(D4, rele);
Blynk.virtualWrite(V1, rele);
delay (450);
}
if (digitalRead(D2))
{
rele = !rele;
digitalWrite(D7, rele);
Blynk.virtualWrite(V2, rele);
delay (450);
}
if (digitalRead(D5))
{
rele = !rele;
digitalWrite(D8, rele);
Blynk.virtualWrite(V3, rele);
delay (450);
}
}
how to update relay state to server.
Blynk has a callback function called BLYNK_CONNECTED()
Whenever the device goes from a disconnected to connected status the BLYNK_CONNECTED() callback will fire.
Put some code in the BLYNK_CONNECTED() function that will update the server with the values that you want to synchronise, using Blynk.virtualWrite commands.
But, your void loop is a mess and you need to change it urgently, otherwise you will suffer disconnections from the Blynk server.
Read this:
Pete.
Sir i donβt know to add code to my code. Can u help me
I donβt have your hardware, so there is no way that I could test any changes to the code.
Iβd suggest that you start learning.
Pete.
Am tried i cant any suggestions.
// Every time we connect to the cloud...
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(V2);
// Alternatively, you could override server state using:
//Blynk.virtualWrite(V2, ledState);
}
Is it work. This cord
βββ
Blynk.syncVirtual(V2, d2State)
βββ