# Demo for polling an etherNode and extracting received packets from it # jcw, 2010-08-16 # save the directory location of this script variable appDir [file dir [info script]] # called once by JeeMon proc start {} { variable appDir # we need a config file to define all the radio node ID's Config setup $appDir/config.txt JeeSketch register ./sketches # poll an etherNode, calling the specified command for each packet EtherNodePull 192.168.178.203 [namespace which GotPacket] # keep running vwait forever } proc GotPacket {msg} { Log got {$msg} } # utility code to handle periodic fetching of a page from an etherNode proc EtherNodePull {ipaddr cmd} { # set up to re-run this code in 5 seconds after 5000 [namespace which EtherNodePull] $ipaddr $cmd # get a page and extract the relevant data from it set page [readHttp http://$ipaddr/] #puts $page if {[regexp {
(.+)} $page - packets]} { # decode each line of the form "0123: OK ..." foreach item [split $packets \n] { if {[scan $item {%d: OK } itemIndex] == 1} { # extra logic to skip over all the items we've seen before # careful: the reported indices can wrap from 9999 to 0000, # so a simple {$itemIndex > $lastIndex} test is not enough! variable lastIndex if {![info exists lastIndex] || ($lastIndex - $itemIndex) % 10000 >= 10} { set lastIndex $itemIndex #puts $lastIndex # now we can call cmd arg with newly received packet data $cmd [string range $item 6 end] } } } } }