Either way, your Blynk code is expecting values between 0 and 1023, so unless you say “1023 percent” then you either have to change the data in IFTTT before it’s sent, or adjust your Blynk code and remove the re-mapping of the incoming values.
In the below esp32 light dimmer code how can i save the slider Value of blynk virtual pin V0 even after esp32 reboot. Because after reboot my ac light start flickering until i change the slider position in blynk app.
i want to save the dimmer state using eeprom plz guide me in this regards.
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <RBDdimmer.h> // header file for robodyn dimmer
char auth[] = "xxxxxxxxx";
char ssid[] = "xxxxxxx"; // Your WiFi credentials.
char pass[] = "xxxxxxxxx"; // Set password to "" for open networks.
#define outputPin D26 // PWM pin for dimmer
#define zerocross D25 // for boards with CHANGEBLE input pins
dimmerLamp dimmer(outputPin, zerocross); //initialase port for dimmer for ESP8266, ESP32, Arduino due boards
int outVal = 0; // Intialisation value for dimmer
int dim_val; // dimmer value to dim the appliance
void setup()
{
Serial.begin(9600); // begin serial communication
dimmer.begin(NORMAL_MODE, ON); //dimmer initialisation: name.begin(MODE, STATE)
Blynk.begin(auth, ssid, pass); // begin blynk server
}
void loop()
{
Blynk.run(); // Run blynk server
}
BLYNK_WRITE(V0) { // Set to your virtual pin
outVal = param.asInt(); // Get State of Virtual Button
dim_val = map(outVal, 0, 100, 0, 100); // mapped the value for dimmer
dimmer.setPower(dim_val); // Set dimmer power
Blynk.virtualWrite(V1, dim_val); //sending to Blynk
} ```
You do t need to save to EEPROM (which is outdated anyway, you should be UI sh SPIFFS or LittleFS anyway), you simply need to get Blynk to send you the latest value from the slider on startup.
Well, putting that in the void loop would mean that the brightness would be reset to 50% every time the void loop was processed (which is hundreds of time per second) so you’d lose all control of the dimmer from the app.
Putting it into void setup would be a more sensible approach, but again somewhat flawed. You may not want a light to turn on at 50% brightness whenever the MCU chooses to reboot, and this could be annoying in some situations, such as a light in a bedroom which would suddenly go to 50% brightness in the middle of the night. It could also result in considerable unwanted energy usage if the ESP32 starts while you’re away and goes undetected for some time. As there is no synchronisation to reflect the 50% setting back to the app, checking the app would not alert the user to the issue.
As the sketch uses the blocking Blynk.begin command, the light would turn on to 50% brightness and remain there until a WiFi connection is established and then a connection to the Blynk server is established. If this is impossible then the light would be on at 50% brightness permanently, until this issue is resolved. Given that the Blynk cloud servers used for Blynk 0.1 (which this sketch uses) will be decommissioned fairly soon (maybe as early as 5-6 months time), it will soon be impossible to contact the Blynk server and the light will be stuck at 50% brightness permanently.
I suspect that @Rizwan_Saeed’s desire to store the last brightness setting in NVR is because he thinks that this will give some additional usability in offline mode, but the use of the blocking Blynk.begin function makes it unlikely that this will work as anticipated, although it depends on how its implemented.
The symptom of
would be solved by my BLYNK_CONNECTED / Blynk.syncVirtual solution.
If he’s trying to solve a different or additional issue then explaining that in detail would be a good starting point.
The first issue is that my dimmer light bulb start flickering when the MCU is reboot unless i change the value from blynk, If i use this line
dimmer.setPower(50)
then as Pete Sir said this could be annoying in some situations, such as a light in a bedroom which would suddenly go to 50% brightness in the middle of the night
First i want to stop dimmer light flickering when MCU reboot before BLYNK_CONNECTED / Blynk.syncVirtual.
Can we store its state using writing EEPROM/SPIFFS memory and after reboot restore state using reading EEPROM/SPIFFS memory.