BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Deep Sleep Voltage monitor with TWO virtualWrites at the same time?

I have the voltage monitor working good and the deep sleep working good, but when I try and add the
"Blynk.virtualWrite(V0, map(WiFi.RSSI(),-110,-30,45,90)); "
for the wifi signal on V0 only one or the other works…voltage reading on V1 OR the wifi signal on V0 for some reason…any help would be greatly appreciated, trying to get both V1 and V0 to send while its awake… ?
wemos d1 mini

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
BlynkTimer timer;




char auth[] = "AuthCode";
char ssid[] = "USER";     
char pass[] = "Pass";
 
 
const int SleepTime = 1000;

int analogInput = A0;    
float correctionfactor = 0; 
float vout = 0.0;
float vin = 0.0;
float R1 = 30000.0; 
float R2 = 7900.0;   //<-------------Adjust this value for fine tuning Voltage Readout  
int value = 0;



void wifi()  {
Blynk.virtualWrite(V0, map(WiFi.RSSI(),-110,-30,45,90));//<------------------Wifi Signal % on V0
}



void voltageRead() {
  value = analogRead(analogInput);
  vout = (value * 3.3) / 1023.0;
  vin = vout / (R2 / (R1 + R2));
  vin = vin - correctionfactor;
  Serial.print("INPUT V= ");
  Serial.println(vin, 4);
  //timer.setTimeout(3000L, []() {   
    Blynk.virtualWrite(V1, vin);
    
    
    
     Serial.println("WEMOS going to sleep for 15 min....");
    system_deep_sleep(SleepTime * 900000);  
  delay(1000);
  }

void setup() {
  pinMode(analogInput, INPUT);
  Blynk.begin(auth, ssid, pass);
  Serial.begin(115200);
    Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  timer.setInterval(1000L, wifi);
  timer.setInterval(1000L, voltageRead);   
  
   }
  
//-----------------------------------------------------------------------------------------------------------------
void loop(){
  Blynk.run();
  timer.run();
 }

Your code structure is all wrong for deep sleep.
You shouldn’t be using timers, it should all be a “run once” operation either all in your void setup with an empty void loop, in a void loop that will run once and then go to sleep.
When you do it this way, you need to ensure that there is a Blynk.run() before sleeping so that your virtualWrites are executed.

Al;so, using Blynk.begin isn’t a great solution for a battery operated device, as it’s a blocking function and the code won’t progress beyond that point if the device can’t connect to either WiFi or Blynk. This means that your device could stay awake until the battery goes flat.

It’s also better (quicker) to re-connect to your router using a static IP address rather than one assigned by DHCP. When you do tests using short sleep times, your router will hold the assigned IP address in its routing table, but this will be flushed after as little as 20 seconds (depending on your router) and the next time it connects it will have to go through the DHCP negotiation handshake process again - which is slower that connecting with a static IP.

Take a look at @christophebl’s Beehive Connected project for more info…

Pete.

Why not put the WiFi signal code with the Voltage Monitor code?

Also, based on what I have read -80 dBm is a very poor signal, and what I would consider 0%; -30 dBm IMO would be considered 100%.

void voltageRead() {
   
  Blynk.virtualWrite(V0, map(WiFi.RSSI(),-90,-30,0,100));//<------------------Wifi Signal % on V0

  value = analogRead(analogInput);
  vout = (value * 3.3) / 1023.0;
  vin = vout / (R2 / (R1 + R2));
  vin = vin - correctionfactor;
  Serial.print("INPUT V= ");
  Serial.println(vin, 4);
  //timer.setTimeout(3000L, []() {   
    Blynk.virtualWrite(V1, vin);
    
    
    
     Serial.println("WEMOS going to sleep for 15 min....");
    system_deep_sleep(SleepTime * 900000);  
  delay(1000);
  }

Thank you very ,much PeteKnight, that was a great example for what im doing, that did the trick,works great now THANK YOU VERY MUCH

one question what is the delay(4000); for right after the void loop?
I seemed my project didnt work right without it…just wundering why that is…

Now to figure out the static ip settings, I tryed it once before and couldnt get it to work, think it was a problem with the dns settings…routers dns settings say 0.0.0.0 …thinking that may be the problem ??? that’ll be the next part of the puzzle

And about the Blynk.begin what is an alternative for that as you suggested?

Couldnt do it without everybodys help
Thanks Again
Scott V.

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>


char auth[] = "AuthCode";
char ssid[] = "SSID";     
char pass[] = "PASSWORD";
 
int analogInput = A0;    
float correctionfactor = 0; 
float vout = 0.0;
float vin = 0.0;
float R1 = 30000.0; 
float R2 = 7900.0;   //<-------------Adjust this value for fine tuning Voltage Readout  
int value = 0;


void voltageRead() {
  value = analogRead(analogInput);
  vout = (value * 3.3) / 1023.0;
  vin = vout / (R2 / (R1 + R2));
  vin = vin - correctionfactor;
  Serial.print("INPUT V= ");
  Serial.println(vin, 4);
}

void setup() {
 Serial.begin(115200);
  pinMode(analogInput, INPUT);
  Blynk.begin(auth, ssid, pass);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  
   }
  
//-----------------------------------------------------------------------------------------------------------------
void loop(){
delay(4000);
voltageRead();

  Blynk.virtualWrite(V1, vin);
  Blynk.virtualWrite(V0, map(WiFi.RSSI(),-110,-30,45,90));//<------------------Wifi Signal % on V0
  
Blynk.run();
delay(100);
Serial.println("WEMOS going to sleep for 15 min....");
ESP.deepSleep(1000 * 900000);  // Deep Sleep        //<------ 10 min./600000, 15min./900000, 30min./1800000    "Update Delay"
  delay(1000);
 
 }

I agree with your signal strength #'s, that was just code i copied and pasted…Ill give your #'s a try…

So i take it the first 2 #'s are max and min. -90,-30 and second 2 #'s are percent ???
is that how that bit of code works?

Thanks for the advice
Much appreciated
Scott V.