I want to get the position (x and y coordinates) of each node in the Cooja simulator. There are 30 nodes in total, of type 'sky mote'. The goal is to build a table consisting of (ID_node x_coordinate y_coordinate) for each node.
First I tried to get the x coordinate for each node by writing in script simulation editor this code:
array = new Array();
for (i = 1; i < 4; i++) {
array[i] = mote.getInterfaces().getPosition().getXCoordinate();
log.log(array[i] + "\n");
}
but I got this result:
59.09635997249024
59.09635997249024
59.09635997249024
All these numbers are the x coordinate for a particular node with ID 2. Please, can you help me to get the x and y coordinates for all nodes in Cooja?
You should iterate over all nodes in the simulation and save the X and Y coordinates in the array. The following code saves the coordinates in an array and prints them: