I use this code to create sensor nodes in static WSN .... Is it Right?

5 views (last 30 days)
set(gca,'XLim',[0 100]);
set(gca,'YLim',[0 100]);
hold on;
BS=plot(50,90,'^','LineWidth',1,...
'MarkerEdgeColor','g',...
'MarkerFaceColor','Y',...
'MarkerSize',30) ;
hold on;
text(49,90,'BS','FontSize',8);
hold on;
CH1= plot(25,60,'^','LineWidth',1,...
'MarkerEdgeColor','g',...
'MarkerFaceColor','Y',...
'MarkerSize',30) ;
hold on;
text(24,60,'CH1','FontSize',8);
CH2= plot(75,60,'^','LineWidth',1,...
'MarkerEdgeColor','g',...
'MarkerFaceColor','Y',...
'MarkerSize',30) ;
hold on;
text(74,60,'CH2','FontSize',8);
SN1= plot(15,30,'^','LineWidth',1,...
'MarkerEdgeColor','g',...
'MarkerFaceColor','Y',...
'MarkerSize',30) ;
hold on;
text(14,30,'SN1','FontSize',8);
SN2=plot(25,30,'^','LineWidth',1,...
'MarkerEdgeColor','g',...
'MarkerFaceColor','Y',...
'MarkerSize',30) ;
hold on;
text(24,30,'SN2','FontSize',8);
SN3=plot(35,30,'^','LineWidth',1,...
'MarkerEdgeColor','g',...
'MarkerFaceColor','Y',...
'MarkerSize',30) ;
hold on;
text(34,30,'SN3','FontSize',8);
SN4=plot(65,30,'^','LineWidth',1,...
'MarkerEdgeColor','g',...
'MarkerFaceColor','Y',...
'MarkerSize',30) ;
hold on;
text(64,30,'SN4','FontSize',8);
SN5=plot(75,30,'^','LineWidth',1,...
'MarkerEdgeColor','g',...
'MarkerFaceColor','Y',...
'MarkerSize',30) ;
hold on;
text(74,30,'SN5','FontSize',8);
SN6= plot(85,30,'^','LineWidth',1,...
'MarkerEdgeColor','g',...
'MarkerFaceColor','Y',...
'MarkerSize',30) ;
hold on;
text(84,30,'SN6','FontSize',8);

Accepted Answer

Walter Roberson
Walter Roberson on 17 Jan 2018
The code draws a diagram. The code does not make any attempt to create a WSN.
You need to create a data structure that represents each node of the WSN. The data structure will need at least the following entries:
  • coordinates of each node, with at least X and Y (or in polar coordinates) and possibly Z as well
  • some kind of unique identifier for each node
  • queue of outgoing messages
  • queue of incoming messages
  • An array of data about other nodes. The array will need, at the very least, entries containing unique node identifier, and current cost to reach the node
It is fairly likely that you would need additional entries in practice.
To send a message from one node to another would involve, at the very least, examining the queue of outgoing messages from the node, selecting one, determining where it is to be sent, adding it on to the queue of incoming messages for the location it is being sent to, and removing it from the queue of outgoing messages for the node it is being sent from. It is fairly likely that you would need additional steps in practice.
  8 Comments
Walter Roberson
Walter Roberson on 6 Feb 2021
by examining the queue of outgoing messages from a node, selecting one, determining where it is to be sent, adding it on to the queue of incoming messages for the location it is being sent to, and removing it from the queue of outgoing messages for the node it is being sent from.
The data to be sent can be arranged with whatever error detection code or error correction code you want. Including, for example, taking the sum of the bytes (with wrapping instead of overflow) and putting the ones's complement of the sum at the end of the buffer. On the receiving side, sum all the bytes (with wrapping). If the sum is 255 then you probably did not have corruption (do not use two's complement because if the buffer got zapped to all zero, two's complement would give 0, same as if the entire buffer with checksum was overwritten.)
Walter Roberson
Walter Roberson on 6 Feb 2021
There are different ways you can impliment a WSN:
  • Using Simulink blocks
  • Using the facilities provided by the WLAN and 5G Toolbox; I do not know anything about those
  • Using interfaces to external hardware such as USRP or Zigbee or even arduino with some kind of wireless transmission, and command the hardware to send some physical signal, and somehow arrange to have the signal undergo the exact kinds of scattering and corruption you want, and be received by physical hardware
  • Everything else is done by simulating wireless sensor networks.
When you simulate wireless sensor networks, there are no pre-built functions available like connect_two_nodes() or transmit_packet_to_destination() -- they do not exist. Instead, you have to write any functions like that yourself, and what the functions have to is manipulate data structures.
What should the datastructures contain? Well, I described a simple minimal representation in my Answer above, and in my comment just below the Answer. You might find that for your purposes you need more detail, or you need additional data structures. You can get as detailed as you like.
Along the way you will need to figure out matters such as "If node A wants to send packet P1 to node B, at what point in the sequence can node A delete its copy of the packet?" or "What happens if node A is reset right in the middle of doing this?"

Sign in to comment.

More Answers (0)

Categories

Find more on WSNs in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!