Clear Filters
Clear Filters

wireless sensor network code error

3 views (last 30 days)
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:
%
  2 Comments
Walter Roberson
Walter Roberson on 21 Jun 2016
This appears to refer to the third-party package TrueTime

Sign in to comment.

Accepted Answer

Walter Roberson
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.

More Answers (1)

Samah EL QASSAH
Samah EL QASSAH on 22 Jun 2016
Thank you, I understand the problem.
This is my node on Simulink
Can you help me more? I have read about "mxCreateDoubleScalar" but I didn't understand what I have to do.
  1 Comment
Walter Roberson
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.

Sign in to comment.

Categories

Find more on Data Import and Network Parameters 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!