Rev Author Line No. Line
4664 jacho 1 #!/usr/bin/python
2  
3 # Python driver for MLAB MAG01A module with HMC5888L Magnetometer sensor wrapper class
4  
5 import time
6 import datetime
7 import sys
8  
9 from pymlab import config
10  
11 #uncomment for debbug purposes
12 import logging
13 logging.basicConfig(level=logging.DEBUG)
14  
15  
16 #### Script Arguments ###############################################
17  
18 if len(sys.argv) != 2:
19 sys.stderr.write("Invalid number of arguments.\n")
20 sys.stderr.write("Usage: %s #I2CPORT\n" % (sys.argv[0], ))
21 sys.exit(1)
22  
23 port = eval(sys.argv[1])
24  
25  
26 #### Sensor Configuration ###########################################
27  
28 cfg = config.Config(
29 i2c = {
30 "port": port,
31 },
32  
33 bus = [
34 {
35 "type": "i2chub",
36 "address": 0x72,
37 "children": [
38 {
39 "type": "i2chub",
40 "address": 0x70,
41 "channel": 0,
42 "children": [
43 {"name": "barometer", "type": "altimet01" , "channel": 0, },
44 {"name": "hum_temp", "type": "sht25" , "channel": 1, },
45 # {"name": "wind_direction", "type": "mag01" , "channel": 1, },
46 # {"name": "thermometer", "type": "lts01" , "channel": 2, },
47 ],
48 },
49 # {"name": "barometer2", "type": "altimet01" , "channel": 6, },
50 ],
51 },
52 ],
53 )
54  
55 cfg.initialize()
56  
57 barometer = cfg.get_device("barometer")
58 hum_temp = cfg.get_device("hum_temp")
59 #wind_direction = cfg.get_device("wind_direction")
60 #thermometer = cfg.get_device("thermometer")
61 time.sleep(0.5)
62  
63 #### Data Logging ###################################################
64  
65 filename = datetime.datetime.now().isoformat()
66  
67  
68 try:
69 with open(filename+".log", "a") as f:
70 while True:
71 barometer.route()
72 (t1, p1) = barometer.get_tp()
73 hum_temp.route()
74 t2 = hum_temp.get_temp()
75 # t3 = thermometer.get_temp()
76 t3 = -200
77 h1 = hum_temp.get_hum()
78  
79  
80 sys.stdout.write(" Temperature: %.2f Pressure: %d TempSHT: %.2f HumSHT: %.1f TempLTS: %.2f" % (t1, p1, t2, h1, t3))
81 f.write("%d\t%.2f\t%d\t%.2f\t%.1f\t%.2f\n" % (time.time(),t1, p1, t2, h1, t3))
82 sys.stdout.flush()
83 time.sleep(10)
84 except KeyboardInterrupt:
85 sys.exit(0)
86