This is why I don't like it when people don't use the natural types of C
This is why I'm excited for my first C++ class this semester. I've only had LabVIEW so I'm completely floundering with all of the "real" programming languages.
Jack_Strop:
cast from 'uint8_t*' to 'char' loses precision
Ok... loses precision on integer values. You are sending strings.
either way, postToTwitter is a function created by you, so you can always change it's definition and instead of char, use unsigned char.
int postToTwitter(unsigned char * buffer) {
Ethernet.begin(mac, ip);
delay(1000);
Serial.println("sending to Twitter");
if (twitter.post((char)buffer)) {
// 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);
return status;
}
}
After making the change you suggested in your last comment, I'm getting:
cast from 'unsigned char*' to 'char' loses precision
On this line:
if (twitter.post((char)buffer)) {
Full code:
#include <VirtualWire.h>
#include <Ethernet.h>
#include <EthernetDNS.h>
#include <Twitter.h>
#if defined(ARDUINO) && ARDUINO > 18 // Arduino 0019 or later
#include <SPI.h>
#endif
#undef int
#undef abs
#undef double
#undef float
#undef round
// Ethernet Shield Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// substitute an address on your own network here
byte ip[] = { 192, 168, 2, 199 };
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("YOUR-TOKEN-HERE");
//Buffers for wireless
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
int postToTwitter(unsigned char * buffer) {
Ethernet.begin(mac, ip);
delay(1000);
Serial.println("sending to Twitter");
if (twitter.post((char)buffer)) {
// 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);
return status;
}
}
void setup()
{
Serial.begin(9600);
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for RX Link Module
vw_setup(2000); // Bits per sec
vw_set_rx_pin(3); // receive on pin 3
vw_rx_start(); // Start the receiver
Serial.println("connecting ...");
}
void loop()
{
if (vw_get_message(buf, &buflen-1)) // check to see if anything has been received
{
Serial.println("Eureka");// just to see if we managed to get inside here
buf[buflen-1] = '\0';
Serial.println(*buf);
int statusTwo = postToTwitter((char) buf);
if (statusTwo == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}
Hmm. I guess I don't really know the difference. I'm guessing a warning will get caught by the compiler but will be ignored when I actually flash it to the MCU? I'll go try it.
#include <VirtualWire.h>
#include <Ethernet.h>
#include <EthernetDNS.h>
#include <Twitter.h>
#if defined(ARDUINO) && ARDUINO > 18 // Arduino 0019 or later
#include <SPI.h>
#endif
#undef int
#undef abs
#undef double
#undef float
#undef round
// Ethernet Shield Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// substitute an address on your own network here
byte ip[] = { 192, 168, 2, 199 };
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("YOUR-TOKEN-HERE");
//Buffers for wireless
char buf[VW_MAX_MESSAGE_LEN];
char buflen = VW_MAX_MESSAGE_LEN;
int postToTwitter(char * buffer) {
Ethernet.begin(mac, ip);
delay(1000);
Serial.println("sending to Twitter");
if (twitter.post(buffer)) {
// 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);
return status;
}
}
void setup()
{
Serial.begin(9600);
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for RX Link Module
vw_setup(2000); // Bits per sec
vw_set_rx_pin(3); // receive on pin 3
vw_rx_start(); // Start the receiver
Serial.println("connecting ...");
}
void loop()
{
if (vw_get_message((uint8_t)buf, &buflen-1)) // check to see if anything has been received
{
Serial.println("Eureka");// just to see if we managed to get inside here
buf[buflen-1] = '\0';
Serial.println(*buf);
int statusTwo = postToTwitter((char) buf);
if (statusTwo == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}
#include <VirtualWire.h>
#include <Ethernet.h>
#include <EthernetDNS.h>
#include <Twitter.h>
#if defined(ARDUINO) && ARDUINO > 18 // Arduino 0019 or later
#include <SPI.h>
#endif
#undef int
#undef abs
#undef double
#undef float
#undef round
// Ethernet Shield Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// substitute an address on your own network here
byte ip[] = { 192, 168, 2, 199 };
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("YOUR-TOKEN-HERE");
//Buffers for wireless
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
char * ptr;
int postToTwitter(uint8_t * buffer) {
Ethernet.begin(mac, ip);
delay(1000);
Serial.println("sending to Twitter");
ptr = buffer;
if (twitter.post(*ptr) {
// 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);
return status;
}
}
void setup()
{
Serial.begin(9600);
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for RX Link Module
vw_setup(2000); // Bits per sec
vw_set_rx_pin(3); // receive on pin 3
vw_rx_start(); // Start the receiver
Serial.println("connecting ...");
}
void loop()
{
if (vw_get_message(buf, &buflen-1)) // check to see if anything has been received
{
Serial.println("Eureka");// just to see if we managed to get inside here
buf[buflen-1] = '\0';
Serial.println(*buf);
int statusTwo = postToTwitter( buf);
if (statusTwo == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}
What does this do to you? I have to leave now, but I'm still wondering why wouldn't a cast work. :\
I still think this behavior is strange. Can you open the virtual wire library and see if they use some compiler directive there that will screw this up? Also, if you're up to it, change all references from uint8_t to char or unsigned char and save the library.
if you're up to it, change all references from uint8_t to char or unsigned char and save the library
I was thinking of doing something like this. Would this mean that I wouldn't have to coerce any data types in my sketch? I'm not too confident in what I'm doing but if I screw something up, I could just download the library again.
if you're up to it, change all references from uint8_t to char or unsigned char and save the library
I was thinking of doing something like this. Would this mean that I wouldn't have to coerce any data types in my sketch? I'm not too confident in what I'm doing but if I screw something up, I could just download the library again.
Thank you for your help and patience.
You can save a copy of your library beforehand.
Then open the library files in a text editor (not the Arduino IDE), and look for the uint8_t and change them. I normally use the Find + Replace function to be sure I take out all of them.