Problems stitching a few pieces of code together.

cast from 'uint8_t*' to 'char' loses precision

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; 
    }

}

Ok, in my last comment I was getting:

cast from 'uint8_t*' to 'char' loses precision

On this line:

int statusTwo = postToTwitter((char) buf);

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.");
    }
	
}

but is it an error, or warning?

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.

Nope. Won't compile or upload to board.

Stops at the same point when I try to upload.

#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.");
    }
	
}

And how about this one?

Got further into the code this time!

Error:

cast from 'char*' to 'uint8_t' loses precision

on this line:

if (vw_get_message((uint8_t)buf, &buflen-1))
#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. :\

invalid conversion from 'uint8_t*' to 'char*'

On line:

    ptr = buffer;

I don't understand either. :frowning:

I suppose casting it won't work either.

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.

There's nothing else I can think of really. :S

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.

Jack_Strop:

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.

Can I just confirm that you're still talking about these two functions:

int postToTwitter(char * buf)

and
extern uint8_t vw_get_message(uint8_t* buf, uint8_t* len);?

and that you've got

uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

declared?
and you want to do something like

if (vw_get_message(buf, &buflen-1)) {
  (void)postToTwitter ((char*)buf); 
}

?

Everything looks correct except for:

extern uint8_t vw_get_message(uint8_t* buf, uint8_t* len);

I don't remember using this in anything previously. Thanks for having another look.

AWOL:
and you want to do something like

if (vw_get_message(buf, &buflen-1)) {

(void)postToTwitter ((char*)buf);
}



?

In the words of Homer Simpson: "DOOOOOOOOOOOHHHHHHHHHHHH". LOL

Everything looks correct except for:
Code:

extern uint8_t vw_get_message(uint8_t* buf, uint8_t* len);

That's the prototype in the header file.