Timestamp string will not be displayed in the 2.0 App

Currently busy with the migration of a Blynk 0.1 based project in Blynk 2.0
Most of the issues could be solved, only one is still to go:

My ESP32 will send timestamp information of an event to the Blynk App by using an String in the format “08.06.2022 14:23:03”
This string will be created in this function:

String localTime() 
{
  	static char buf[20];                                  
  	static time_t lastsec {0};
  	getLocalTime(&tm, 50);
  	if (tm.tm_sec != lastsec) 
	{
    		lastsec = tm.tm_sec;
    		strftime (buf, sizeof(buf), "%d.%m.%Y %T ", &tm);   
    		//time_t now;
    		time_t now = time(&now);
    		if (!(time(&now) % 43200)) 
    		{  getTime();               
      
    		}
	}
  return buf;
}

The string was transferred to Blinky 0.1 by using

"Blynk.virtualWrite(V9,localTime()); " 

and can be displayed correctly.
With Blynk 2.0 it will fail, and I cant find the error.
Any hint will be highly appreciated

@sc-6000 Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.

Triple backticks look like this:
```

Pete.

Hi Pete, done

Fail in what way?

What datastream type are you using for V9 ?

Pete.

no data will be displayed, only the “0”…


I tried “double” and “string” as well, same result

You answered you own question about which data type it should be.

When you’ve fixed that, you could try…

Blynk.virtualWrite(V9,String(localTime()));

Pete.

Done, but does not work …


in the marked area there should be the timestamp of the 10ml of agent applied … (Sorry for the lables in german)
Datastream is defined as

ESP32 Codes is …

void dose_PH_Minus()
{
    
    Serial.println("Dose Ph- started");
    current_dose_Millis = millis();
    if ( (enable_dose==HIGH)&& (pump_flow==LOW)&&(((unsigned long)(current_dose_Millis - previous_dose_Millis) >= interval_previous_dose)))
    {
      Serial.print("calculate Dose time");
      calculate_doseingtime();
            
      if (Dose_Time >0)
      {
        Blynk.virtualWrite(V9," ");
        digitalWrite(D23, LOW);
        status_relais_1 = HIGH;
        Serial.println("Relais EIN");
        //digitalWrite(LED, HIGH); // nur für tests, sonst auskommentieren
        last_time_dose=localTime();
        PH_Minus_Dosed=PH_Minus_Dosed+Dose_Menge_Single;
        write_int_eeprom("PHMinusDosed",PH_Minus_Dosed);
        Blynk.virtualWrite(V14,PH_Minus_Storage-PH_Minus_Dosed);
        Blynk.virtualWrite(V9,String(localTime()));
        Blynk.virtualWrite(V11,Dose_Menge_Single);
        previous_single_dose_Millis = current_single_dose_Millis;
      } 
      
      previous_dose_Millis = current_dose_Millis;  
    }
} 

Solved!

I used

......
last_time_dose=localTime();
Blynk.virtualWrite(V9,last_time_dose); 
....

last_time_dose is declared as “String”…

Thanks, Pete, for your support!

1 Like