I am a total newbie to Arduino coding and just trying to piece two sketches together for the first time: one that takes a reading from a temp sensor, and a second that tweets from Arduino via the wifi shield.
I am running into problems on line 26 with the error: 'class String' has no member named 'c_str'
Any guidance on how to make it work? Code is below.
char ssid[] = "X"; // your network SSID (name)
char pass[] = "X"; // your network password
char temp[6];
String msg = "It is this many degrees Kelvin at my house: ";
Twitter twitter("X");
void setup()
{
Serial.begin(9600);
delay(1000);
WiFi.begin(ssid, pass);
delay(10000);
int rawvoltage= analogRead(outputpin);
float kelvin;
float millivolts= (rawvoltage/1024.0) * 5000;
kelvin= (millivolts/10);
dtostrf(kelvin, 3, 3, temp); //4 is mininum width, 3 is precision; float value is copied onto buff
msg.concat(temp);
Serial.println("connecting ...");
if (twitter.post(msg.c_str)) {
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}
char ssid[] = "XXX"; // your network SSID (name)
char pass[] = "XXX"; // your network password
char temp[6];
char msg[50] = "It is this many degrees Kelvin at my house: ";
Twitter twitter("XXX);
void setup()
{
Serial.begin(9600);
delay(1000);
WiFi.begin(ssid, pass);
delay(10000);
int rawvoltage= analogRead(outputpin);
float kelvin;
float millivolts= (rawvoltage/1024.0) * 5000;
kelvin= (millivolts/10);
dtostrf(kelvin, 3, 3, temp); //4 is mininum width, 3 is precision; float value is copied onto buff
strcat(msg, temp);
Serial.println("connecting ...");
if (twitter.post(msg)) {
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}
dtostrf(kelvin, 3, 3, temp); //4 is mininum width, 3 is precision; float value is copied onto buff
Why are you expecting to get some digits before the decimal point, a decimal point, and three digits after the decimal point in a 3 character wide output?
I suspect that your 6 character array is not wide enough, unless it is a very cold day where you are.
Welcome to the Forum. Before your next post, please read Nick Gammon's two posts at the top of this Forum for guidelines on posting here, especially about the use of code tags when listing programs. It will help us help you. Also, if you look at the code size with String (i.e., the C++ class) versus string (i.e., using a char array), I'll bet the latter is considerably smaller. The String class may seem convenient, but it is very costly in terms of resource use.