How to share data between nodes

66 views Asked by At

I have created a network with one sink & five sender nodes. I wanted to share one single data (an integer value) with all the nodes. I wanted the nodes to be able to update as well as read the shared integer value. I used a pointer and tried to share the memory between the nodes. However, since contiki uses protothreads, the data contained in the referenced memory is not saved for the other nodes rather it is only update in a single node. Here is what I tried.

code for the sender nodes 

 int *ptr;
 void share(int *val){
 ptr=val;
 printf(" the number after call is %d ",*ptr);
 }
 void display(){
   printf(" the number is %d ",*ptr);
 }
    code for the sink node

    void sendNumber(){
     int *val;
     *val = 12;
     share(val);
     }

when share(val) is called by the sink, the print result is

    the number after call is 12

if display() is called by another node, the print result is

    the number is 1

both the codes for the sender & sink are in different files.

I want the number assigned in *val to be displayed in both the prints. That is once sink node calls node A's share(val), the received value should be saved in the memory to be accessed by all the remaining 4 nodes. However, my code updates the memory for all the 5 nodes separately.

I would really & truly appreciate your help. Thank you

0

There are 0 answers