0

I want to broadcast an array of integers using the broadcast function in the Contiki OS. However, the packetbuf_copyfrom() function does not seem to work for me, when giving an integer array as input. When monitoring the Messages over Cooja's "Radio Message Tool" the packets seem to be empty.

This is what it looks like using a char array as parameter and like that when trying to do exactly the same, just using an integer array.

According to the Contiki Documentation the function expects a void pointer and calls the memcpy function, which should not be a problem regarding integers?

int packetbuf_copyfrom(const void *from, uint16_t len)
{   
    uint16_t l; 
    packetbuf_clear();
    l = len > PACKETBUF_SIZE? PACKETBUF_SIZE: len;
    memcpy(packetbufptr, from, l);
    buflen = l;
    return l;
}

I'm using the

/contiki/examples/rime/example-broadcast.c

file on Z1 Motes in the Cooja Simulator with contiki 2.7.

Where might my mistake be?

1
  • What happen if you try memcpy(packetbufptr, from, len); ? Just a suggestion as a way to check if the prev line is good.
    – BobRun
    Nov 9, 2015 at 12:02

1 Answer 1

0

I don't know Contiki, but the code seems fine, as long as you call packetbuf_copyfrom correctly. Just note that the tool tries to decode the packet contents as ASCII and so shows Hello67890 but integers are not ASCII and so are shown as .........

Call the funtion as:

int myArray[10]= {1,2,3,4,5,6,7,8,9,0};
packetbuf_copyfrom(myArray, sizeof(myArray));
2
  • Thank You! The numbers were actually stored in the packet, just not shown by the tool, as they were no valid ASCII symbols. My other problem was, that I tried to read the incoming packets with printf("%s", (uint8_t *)packetbuf_dataptr()); which worked fine for Strings (with casting the returned void pointer to char *), but apparently there is no way to print the complete content of an integer-array at once without looping through it?
    – Drukob
    Nov 9, 2015 at 14:54
  • Seems that in your package you must precede the data with an indicator whether this is ASCII or ints, then read accordingly. No, there is no way to print an array of ints with one call to a print function - you must loop. Nov 9, 2015 at 14:58

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.