wireless sensor network code error
1 view (last 30 days)
Show older comments
Samah EL QASSAH
on 21 Jun 2016
Commented: Walter Roberson
on 22 Jun 2016
I wrote a code to create a WSN with 7 nodes that communicate with each others and where node 7 receive a message from node 1. I have an error that I can't fixed. Help please!
code to initialize node 1:
function node1_init true
ttInitKernel('prioFP');% number of A/D inputs,number of D/A outputs,priority
% init parameters of task
data.a = 0;
data.K = 2;
offset = 0; % time offset is 0
data.exectime = 0.5;
period = 0.0010; % 10 ms, sets period for execution
prio = 1; % basic priority, lower numbers = higher priorities
ttCreatePeriodicTask('sens1_task', offset, period, prio, 'node1code', data);
ttSetPriority(prio, 'sens1_task');
Code node 1:
function [exectime, data] = node1code(seg, data)
switch seg,
case 1,
y = ttAnalogIn(1); % read analog input no 1,
data.a = -data.K * y;
exectime = rand*data.exectime; % we set executing time of read operation
case 2,
ttSendMsg(7, data.a, 80); % send 80 bits to node 3
exectime = 0.5; % we also set delay of this operations
case 3,
exectime = -1; % we are finished, don’t do delay
end
code to nitialize node 7:
function node7_init()
% Init kernel
ttInitKernel('prioFP')
codefcn = 'node7code';
data.u = 0;
prio = 1;
deadline = 10.0;
ttCreateTask('recv_task', deadline, prio, codefcn, data);
ttSetPriority(prio, 'recv_task');
ttAttachNetworkHandler('recv_task')
code node 7:
function [exectime, data] = node7code(seg, data)
switch seg,
case 1,
data.u = ttGetMsg; % read values from node
disp('I got a message');
exectime = 0.0005;
case 2,
ttAnalogOut(1, data.u);
exectime = -1;
end
I get this error:
%
Accepted Answer
Walter Roberson
on 21 Jun 2016
According to the source code that error is generated when the value to be written is not a scalar double. I suggest you put in some simple code to display the size and class of data.u to see what you are getting instead.
0 Comments
More Answers (1)
Samah EL QASSAH
on 22 Jun 2016
1 Comment
Walter Roberson
on 22 Jun 2016
What you need to do is to add the code
disp(size(data.u))
disp(class(data.u))
before the ttAnalogOut call, and tell us what output was produced.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!