PDA

View Full Version : Function definition


paramasivan
07-27-2009, 09:29 AM
hello all ,

Overview:
i am using EK2500 kit which uses PAN4555 module.I have a strange problem while i execute my code.Here is the following code on Remote Node which collects the adc values of various sensors,converts it in to the corresponding temperature value from the look up table.Then it sends the value to the master node.

The Code:

def send_sensor_data():
global M,digits,value,adc_value1

adc_value1 = readAdc(0)

temperature1=find_temp(adc_value1)

rpc(rpcSourceAddr(),"sensor_data",temperature1)


#This function Converts ADC value to Temperature Using Look up table"

def find_temp(adcvalue):

reading ='170,199,233,272,317,367,422,481,543,605,678,736, 790,830,891a'
tempvalue='1580,1472,1364,1256,1148,1040,932,824,7 16,608,482,374,266,176,14a'

array_size=14
array_count=0

if (adcvalue<170): # check the upper and lower limit of look up table values
acdvalue=170
if (adcvalue>891):
adcvalue=891


while (array_count!=array_size):
array_value=array(reading,array_count)
if (array_value>adcvalue):
upper_pos=array_count
break
array_count+=1

#Extracts the value of the defined position from the look up table

upperX=array(reading,upper_pos)
lowerX=array(reading,upper_pos-1)

upperY=array(tempvalue,upper_pos)
lowerY=array(tempvalue,upper_pos-1)

diff=(((lowerY-upperY)*(adcvalue-lowerX))/(upperX-lowerX)) # calculation done using slope formula

temperature=lowerY-diff

return temperature

#This function extract the value from the position pointed out by the "count" variable of "array" function on the look up table .

def array(str,count):
global value
i=0
j=0
comma=0

# counting digit by using comma position (eg:123,345,56,27)

while(str[i]!=',' or comma<count):
i=i+1
if(str[i]==','):
comma+=1 #This count increases at every value is read in the string which is separated by comma
j=i+1

if (count==0):
j=0

while(str[i]!='a'): # check until the string terminating character 'a'
i=i+1
if(str[i]==','): # check until the terminating symbol',' of the next value.
break

value=int(str[j:i]) # slice and get the postioned value
return value


The problem:
I am using Sleepy Mesh Network.The frequency of communicating with the node is 3 seconds and am using Doze mode.The logic works fine and getting the correct values.
But,In between the cycle,It looses out randomly the sleep command which gets from the master at every frequency.At the next cycle,it works fine and does the job.
I am not sure what may the problem.So i discarded the above said functions and loaded in to the remote device.It worked fine.And Remote node does not miss any cycle of command received from the master.

Can any one please explain what may be the problem.

kbanks
07-27-2009, 09:48 AM
1) Please repost with your script contained inside a
[ c o d e ]
[ / c o d e ]
block (without the extra spaces I put in of course). Or, attach your script to the post.

2) You said

But,In between the cycle,It looses out randomly the sleep command which gets from the master at every frequency.At the next cycle,it works fine and does the job.

Please restate your symptoms, I don't completely understand your question.

Also be sure that we get the entire script (including any sleep related code).

In the meantime I suggest using some LEDs to indicate what state the node is in (awake, asleep, processing). For example, maybe it is asleep when the next sleep command comes in, so it remains awake until the NEXT one.

paramasivan
07-28-2009, 02:15 AM
hi kbanks,

here i attached my slave code.

code application: (calculate the temperature value)

The sleep command call from the master node (for 3sec).When it receives from the master node ,slave go to sleep for 3 seconds .After wakeup from sleep mode, it reads the ADC value and do the calculation as per the code and send the temperature value to the master node.so the master node get the value each 3 seconds and it send the values to the frontend through COM port.

Actually i created the lookup table array using strings.you can see from my code.And i separated each values in the array and compare with the ADC value and get the position which one is greater than the read ADC value.

Problem:
The logic works fine and the master node update the temperature value each 3 seconds to the front end(PC).

But any one of the interval ,the slave node doesn't send the temperature value to the master node .so the frontend doesn't get any update from the master.After 3 seconds onwards(next cycle) slave node send the correct temperature value to the master .

so i dont know why it happens randomly?:mad:
where the loop hang inside the code ?
why it not respond the sleep mode command from the master and wakeup in between some times?

kbanks
07-28-2009, 11:22 AM
Is the master sleeping too? OR does it stay awake the whole time?

How does the master know when to put the node back to sleep? (You may just want to post your "master node" script too).

Does the "random" behavior go away if you set your Mesh routing "delete timeout" to 0 (and reboot so that the change takes effect)?

Currently I am thinking that the node is getting put back to sleep before it has had a chance for the "sensor report" to get out.

Remember, an RPC call within a SNAPpy script can require a node to have to discover a route before it can send the data.


Some things noticed while reading through your script, not necessarily related to the problem you are working on:

In your start_up_event(), you load a global variable from NV. In 2.0/2.1, you should not be "hanging on" to references to the NV region of memory (see page 74 of the 2.1 SNAP Reference Manual, under NV Parameters must be used carefully too. With SNAP 2.2 (now in open beta), what you have is actually OK, the underlying data is tracked differently.

In your initialise_variables() routine, you have two lines of "global" variables that you do not actually assign values to.

kbanks
07-30-2009, 06:18 PM
Is the master sleeping too? OR does it stay awake the whole time?

How does the master know when to put the node back to sleep? (You may just want to post your "master node" script too).

Does the "random" behavior go away if you set your Mesh routing "delete timeout" to 0 (and reboot so that the change takes effect)?

I'm still waiting to hear the answers to the above questions so that I can try to help you with your problem...

paramasivan
08-07-2009, 08:23 AM
Hi Kbanks ,
Sorry for the delay .I was out of station for past one week.

here are the answers,

also i have attached my Master code.

Is the master sleeping too? OR does it stay awake the whole time?.
No,the master is not sleep, it stay awake the whole time

How does the master know when to put the node back to sleep?
i enabled the timer for 100ms and count up to 3 sec.(interrupt loop)

Does the "random" behavior go away if you set your Mesh routing "delete timeout" to 0 (and reboot so that the change takes effect)?

I tried but still problem persist :mad:

Have you noticed any problem in the following functions in end node?

def array(str,count), def find_pos(string,adcvalue)

I am facing this problem when added above these two functions in slave code.Suppose if i read the ADC values in slave and send that values to the Master it has no issues.

do you have any idea to solve ?

kbanks
08-07-2009, 05:13 PM
I saw your post, and have loaded your two scripts into two of my nodes.

I did not have enough time today (we've been busy testing Portal 2.2.18/SNAP 2.2.12) to get very far into testing with them, but I will continue looking into your symptoms next week.

As for the subroutines you are suspicious of, you can always call them individually from Portal (that is one of the steps I will be taking).

kbanks
08-11-2009, 06:47 PM
Time constraints prevent me from exploring your scripts in depth.

I see your command line interface on my terminal (*SE, etc.)

Can you tell me the exact sequence of (your) commands to reproduce the symptoms you want investigated?

What commands do I need to input to your script through the serial port to initiate sleep cycling?

Also, what RPCs do I need to invoke within either script (from Portal) to get things set up to run the test?

paramasivan
08-12-2009, 08:32 AM
Hi,
Here I attached the images of configuration setting and output window. I set the frequency level is 3 seconds (default).


what RPCs do I need to invoke within either script (from Portal) to get things set up to run the test?

The values extracted from the reading,tempvalue variables are sent to the Master node once it wakes up from the sleep.
[Note:Master ask the nodes in the network to sleep for the defined frequency interval.After node wakes up,it sends back the values to the master using RPC]


rpc(rpcSourceAddr(),"sensor_data",temperature1,temperature2,temperature3,temperatur e4) #send the temperature value to the master node

kbanks
08-12-2009, 09:17 AM
I think the piece I am missing is how to "set the frequency to 3 seconds"

My guess was *WF3 but this gives me an error from the script.


Error 16 in extract_data @127


So something like


*WF3
*SE


is close to being correct, but please give the the exact (correct) command sequence.

Also, if there are any functions in the Master script that need to be invoked before running the test, tell me about them too.

paramasivan
08-13-2009, 07:59 AM
Hi,
Here I attached the command set file.
In which time you will be available in online? I can ask my doubts immediately.

paramasivan
08-13-2009, 08:03 AM
hi,
here i attached the command set file.
In which time you will be available in online?
because of I can ask my doubts immediately.

kbanks
08-16-2009, 04:00 PM
I'm seldom online for long.

I usually check the forum when I come in, again around lunch time, and once again before I leave for the day. On busier days (lots of meetings for example) I check it less.

So, you can always expect a lag between the posting of questions and the posting of answers. (There are other engineers monitoring the forum, but a question about "sleepy mesh" will usually be left for me to answer).

Anyway, with the details of your command set, I ran your two scripts in two of my nodes, and watched the "polling/sleep cycling".

What I saw was that your "master" script is not synchronizing itself to the slave script in any way. Every 3 seconds it sends the goto_sleep() command, regardless of whether or not the slave node has reported in, and not allowing ANY time for any over-the-air communications.

Making the problem worse, in the slave script you have code that is sleeping for the requested time, PLUS doing the sensor reporting.

You have significant processing going on in routine send_sensor_data() (which is why adding the array processing code made things worse).

So, every few cycles the slave node is STILL ASLEEP when the next goto_sleep() command comes in. So it wakes up, makes it's report, and stays awake until the NEXT goto_sleep() command comes in.

You can tell from the seven-segment display that the slave node is awake. The two digits on that display are multiplexed -the hardware is really only able to light up one digit at a time. So, when a unit is asleep you will see one digit or the other lit up, but not both.

Since the goto_sleep() command is also the trigger for the send_sensor_data() function, if the unit misses a "goto sleep" command, it also will not make a sensor report that cycle.

To see what I am talking about for yourself, go into your "bridge" script and change the line in every_second() that says


if second_counter == sleep_time:


to instead read

if second_counter == sleep_time+1:


This is just a crude work-around so you can see all the sensor reports come in. With the bridge waiting an extra second, the slave has time to do the requested sleeping(), PLUS do the sensor reporting, and thus be ready for the NEXT goto_sleep() command.

Using the 100 millisecond timer hook, you could implement something more "fine grained" than my one-second hack. Also, SNAP 2.2 adds a 10 millisecond timer hook too, so if it turns out that the needed extra time is 150 milliseconds, you don't have to choose between 100 ms and 200 ms.

Alternativly, you could look at the example Portal script in the second Sleepy Mesh app note for ideas on how a master node can wait until all slave nodes have reported in (or a timeout has occured), before commanding the nodes back to sleep.