Compile stalls when using virtualWrite on a String variable

Problems again with my PID.
Im using ESP8266, Arduino IDE 1.6.4, windows 8.
I haven’t been able to try on other setups.

I’m reading a DS18B20 sensor and gets a value as double variable.
I’m converting it to a string for sending it to ThingSpeak.

Now i want it sent to a Value widget in the app. I found out that sending the double just gave an error value on the widget. I can successfully send it as an int, but i would like 1 decimals precision. So i tried sending the String value since i read it supported strings. But when i do that, the IDE stalls at compiling. (the Program still responds fully, just tries to compile forever)

As soon as i comment out the Blynk.virtualWrite(9, stringVariable); it compiles nicely.
I stripped the code for everything else. Still does it.

Can someone tell me why? or test it for me, to see if its on my side that somethings wrong.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "auth";

double Input;
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "ssid", "pass");
}

void loop()
{
  Blynk.run();
}

void writeData() {
  //set temp string for Thingspeak
  char t_buffer[10];
  String temp = dtostrf(Input, 0, 1, t_buffer);
  Blynk.virtualWrite(7, temp);   // this line gives the error for me.
  Serial.println(temp);
}

Thx for your report, I will check it soon!

UPD: Looks like Arduino String object can’t be cast to regular char buffers, unfortunately.
Actually this is bad, cause now you would have to write something like this:

char charBuf[50];
temp.toCharArray(charBuf, 50);
Blynk.virtualWrite(7, charBuf);

And this comes from Arduino documentation… Well that’s odd, as for me :smile:
Anyway looking at you particular example, it would be different a bit (this should work):

void writeData() {
  char t_buffer[10];
  dtostrf(Input, 0, 1, t_buffer);
  Blynk.virtualWrite(7, t_buffer);
  Serial.println(t_buffer);
}

@vhymanskyy

Sorry for late reply. But thx a lot. It works perfect. The way you wrote the code seems more simple than my version. I don’t understand the reason for writing it the way i did. i just followed some examples i found. But this way i think it even makes sense to me ;).

Again thanks

Hi
I write some codes for my ESP8266_DHT22 Project.It will display temperature Celsius string and Read humidity percent string in the virtualWrite function.

BLYNK_READ(1) 
{ 
temp_f = dht.readTemperature(false);// Read temperature as Celsius
int value=temp_f*10;
String str;
char result[5];
result[0]=(value/100)+'0';
result[1]=((value/10)%10)+'0';
result[2]='.';
result[3]=(value%10)+'0';
result[4]='\0';
str +=result;
str +="℃";
//char buf[str.length()+1];
char buf[8];
str.toCharArray(buf,sizeof(buf));
Blynk.virtualWrite(1,buf); 
}

BLYNK_READ(2) 
{ 
humidity = dht.readHumidity();          // Read humidity (percent)
int value=humidity*10;
String str;
char result[5];
result[0]=(value/100)+'0';
result[1]=((value/10)%10)+'0';
result[2]='.';
result[3]=(value%10)+'0';
result[4]='\0';
str +=result;
str +="%";
//char buf[str.length()+1];
char buf[8];
str.toCharArray(buf,sizeof(buf));
Blynk.virtualWrite(2,buf); 
}