arduino passing struct as argument to function -


i'm using arduino library radio.

arduino radio

if crtl+f , "transmission without ack" see example code.

there function called sendpackettimeout(). function takes destination , payload packet of type char, example this.

char message1 [] = "hello";  void setup() {  } void loop(void) { e = sx1272.sendpackettimeout(8, message1); }   

i've copied sendpackettimeout() function declaration header file below.

questions

  1. can pass char function?
  2. could create struct information , pass function example this.

//

struct messagepacket { char boardid[3];        char temperature[3]; char humidity[3]; };  struct messagepacket mypacket;  void setup() { struct messagepacket mypacket; serial.begin(9600); strcpy(mypacket.boardid, "01"); strcpy(mypacket.temperature, "75"); strcpy(mypacket.humidity, "90");  e = sx1272.sendpackettimeout(8, mypacket; 

this function declaration library

uint8_t sendpackettimeout(uint8_t dest, char *payload);  //! sends packet wich payload parameter before ending max_timeout. /*! \param uint8_t dest : packet destination. \param uint8_t *payload: packet payload. \param uint16_t length : payload buffer length. \return '0' on success, '1' otherwise */ uint8_t sendpackettimeout(uint8_t dest, uint8_t *payload, uint16_t length);  //! sends packet wich payload parameter before ending 'wait' time. /*! \param uint8_t dest : packet destination. \param char *payload : packet payload. \param uint16_t wait : time wait. \return '0' on success, '1' otherwise */ 

this should work:

struct messagepacket mypacket; ... e = sx1272.sendpackettimeout(8, (uint8_t*)&mypacket, sizeof(struct messagepacket)); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -