Changes between Version 3 and Version 4 of UsingSensors

Changes between Version 3 and Version 4 of UsingSensors

Please note that these Trac pages are no longer being updated. Wiki contents/documentation have moved to GitHub.

Changes between Version 3 and Version 4 of UsingSensors

Please note that these Trac pages are no longer being updated. Wiki contents/documentation have moved to GitHub.

Changes between Version 3 and Version 4 of UsingSensors

Show
Ignore:
Timestamp:
07/25/12 09:45:31 (7 years ago)
Author:
yanyan
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UsingSensors

    v3 v4  
    3030for sensorport in [63095, 63096, 63097, 63098, 63099, 63090, 63091, 63092, 63093, 63094]: 
    3131  try: 
    32     server = SimpleXMLRPCServer(("localhost", sensorport), 
    33                             requestHandler=RequestHandler) 
     32    server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", sensorport)) 
    3433    server.register_introspection_functions() 
    3534  except socket.error: 
    3635    print 'port:',sensorport,'failed.   Trying backup port...'  
    3736    continue 
     37  print "Listening on port",sensorport,"..."  
    3838  break 
    3939else: 
     
    4141  sys.exit(1) 
    4242     
    43  
    4443def isSeattleSensor(): 
    4544  return True 
    46  
    4745 
    4846def mySensorName(): 
     
    6260    raise Exception("Unsupported language") 
    6361 
    64  
    6562# NOTE: the system.* calls are defined by the !SimpleXMLRPCServer in Python by calling the following.   Your library's use may vary. 
    6663server.register_introspection_functions() 
     
    7168server.register_function(isSeattleSensor) 
    7269 
    73 server.serve_forever() 
     70try: 
     71    print 'Use Control-C to exit' 
     72    server.serve_forever() 
     73except KeyboardInterrupt: 
     74    print 'Exiting' 
    7475 
    7576}}} 
     
    8182import sys 
    8283 
    83 # I really should check multiple ports... 
    84 s = xmlrpclib.ServerProxy('http://localhost:63095') 
     84for sensorport in [63095, 63096, 63097, 63098, 63099, 63090, 63091, 63092, 63093, 63094]: 
     85  try: 
     86    s = xmlrpclib.ServerProxy('http://localhost:'+str(sensorport)) 
     87  except socket.error: 
     88    print 'port:',sensorport,'failed.   Trying backup port...'  
     89    continue 
     90  print "Connected to port",sensorport 
     91  print 
     92  break 
     93else: 
     94  print 'Could not locate a port!' 
     95  sys.exit(1) 
    8596 
    8697# should check the error status... 
     
    103114    print 'Empty call returns:',safe_eval("s."+methodname+"()") 
    104115 
     116print s.isSeattleSensor() 
     117print s.mySensorName() 
     118print s.readSensor() 
     119print s.readSensorForLanguage('English') 
     120 
    105121}}} 
    106122 
    107123 
    108 Note: I didn't test the above code!   Beware of bugs!!! 
     124Note: The above code has been tested. If you find any bugs please let us know!!!