I have been working with this Twitter Library modified for using it with the WiFi Shield to see if I could do a project with it.
Using the sketch provided I would like it to tweet a sensor reading every X minutes but after modifying the given sketch to publish a value (float) instead of a 'char' string like: "Hello World!" I receive some errors related to the change of variables (char & float).
Checking the code inside the library I think I´ve found the problem, it assigns to msg (The message to publish) a 'char' value and after having modified and saved it it still gives me an error.
I would like to know what is wrong with this sketch, thank for your help.
P.S. This is the sample sketch I used (modified), the unmodified one is in the given link up there.
#include <SPI.h> // needed in Arduino 0019 or later
#include <WiFi.h>
#include <Twitter.h>
char ssid[] = "Network Name";
char pass[] = "Secret Password";
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("Your Token Here!");
float temp = 21;
// Message to post
float msg[] = temp;
void setup()
{
delay(1000);
WiFi.begin(ssid, pass);
// or you can use DHCP for automatic IP address configuration.
// WiFi.begin(mac);
delay(10000);
Serial.begin(9600);
Serial.println("connecting ...");
if (twitter.post(msg)) {
// Specify &Serial to output received response to Serial.
// If no output is required, you can just omit the argument, e.g.
// int status = twitter.wait();
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}
void loop()
{
}
THE ERROR GIVEN IS: error: initializer fails to determine size of 'msg'
EDIT: ``I´ve been reding on forums that I have to convert the 'float' numbers into a string
float temp = 21;
// Message to post
float msg[] = temp;
You're taking a single float variable and trying to assign it to an array of unknown size, expecting the compiler to know how big you want the array to be.
You still need to send Twitter::post a string (array of chars). If you want to convert a float into an array of chars, you can use dtostrf()
I repeat, I have never used that, I do not how how to get it to work if I need an extra library because after reading all the info you posted and I searched I am still not able to understand its use. Thanks.
javierdemartin:
I repeat, I have never used that, I do not how how to get it to work if I need an extra library because after reading all the info you posted and I searched I am still not able to understand its use. Thanks.
So if you can't understand it, ask clarifying questions. When you only ask the "how do I do this?" and "can you give me an example?", you're not going to learn much.
I would like to tweet DHT22 (Temp&Humidity) sensor readings so this would be a Weather Station but the main problem I have is that the Twitter library only can tweet char strings or *char (this prompted me in the error console) so I do not know how to fix that, I mean, I don´t know how to convert a float (the sensor reading) to a char string so the Twitter library is able to use the sensor readings.
I can't see your code.
I can't see your IDE.
I can't see your error message.
I compiled (IDE 1.0) a simple sketch using dtostrf and a well-known irrational number.
Here is the error message I got Binary sketch size: 3614 bytes (of a 14336 byte maximum) And here's the output
DHT_TWITTER:6: error: expected constructor, destructor, or type conversion before '(' token
DHT_TWITTER:24: error: expected constructor, destructor, or type conversion before 'char'
DHT_TWITTER.ino: In function 'void setup()':
DHT_TWITTER:35: error: 'msg' was not declared in this scope
#include <SPI.h> // needed in Arduino 0019 or later
#include <WiFi.h>
#include <Twitter.h>
char ssid[] = "WIFISSID";
char pass[] = "WIFIPASSWD";
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("TOKENHERE");
float temp =3.14;
dtostrf(temp,7,2,14);
// Message to post
char msg[] = temp ;
void setup() {
delay(1000);
WiFi.begin(ssid, pass);
// or you can use DHCP for automatic IP address configuration.
// WiFi.begin(mac);
delay(10000);
Serial.begin(9600);
Serial.println("connecting ...");
if (twitter.post(msg)) {
// Specify &Serial to output received response to Serial.
// If no output is required, you can just omit the argument, e.g.
// int status = twitter.wait();
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}
void loop()
{
}