Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New release dated 14-Jan-2019 #6

Merged
merged 2 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,14 @@ Let us know how it went! If you want contribute, you can do so by posting issues

# Release notes

Release dated 14-Jan-2019

* [bug] Fixed issue ([#4][i4])

Release dated 14-Dec-2018

* Added SAMPLE-PERIOD as an input argument.

Initial release 12-Dec-2018
Initial release 12-Dec-2018

[i4]: https://github.com/Airthings/waveplus-reader/issues/4
59 changes: 37 additions & 22 deletions read_waveplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,42 @@ class WavePlus():
def __init__(self, SerialNumber):
self.periph = None
self.curr_val_char = None
self.MacAddr = None
self.SN = SerialNumber
self.uuid = UUID("b42e2a68-ade7-11e4-89d3-123b93f75cba")

def connect(self):
scanner = Scanner().withDelegate(DefaultDelegate())
deviceFound = False
searchCount = 0
while deviceFound is False and searchCount < 50:
devices = scanner.scan(0.1) # 0.1 seconds scan period
searchCount += 1
for dev in devices:
ManuData = dev.getValueText(255)
SN = parseSerialNumber(ManuData)
if (SN == SerialNumber):
MacAddr = dev.addr
deviceFound = True # exits the while loop on next conditional check
break # exit for loop
# Auto-discover device on first connection
if (self.MacAddr is None):
scanner = Scanner().withDelegate(DefaultDelegate())
searchCount = 0
while self.MacAddr is None and searchCount < 50:
devices = scanner.scan(0.1) # 0.1 seconds scan period
searchCount += 1
for dev in devices:
ManuData = dev.getValueText(255)
SN = parseSerialNumber(ManuData)
if (SN == self.SN):
self.MacAddr = dev.addr # exits the while loop on next conditional check
break # exit for loop

if (self.MacAddr is None):
print "ERROR: Could not find device."
print "GUIDE: (1) Please verify the serial number."
print " (2) Ensure that the device is advertising."
print " (3) Retry connection."
sys.exit(1)

if (deviceFound is not True):
print "ERROR: Could not find device."
print "GUIDE: (1) Please verify the serial number. (2) Ensure that the device is advertising. (3) Retry connection."
sys.exit(1)
else:
self.periph = Peripheral(MacAddr)
# Connect to device
if (self.periph is None):
self.periph = Peripheral(self.MacAddr)
if (self.curr_val_char is None):
self.curr_val_char = self.periph.getCharacteristics(uuid=self.uuid)[0]

def read(self):
if (self.curr_val_char is None):
print "ERROR: Devices are not connected."
sys.exit(1)
rawdata = self.curr_val_char.read()
rawdata = struct.unpack('BBBBHHHHHHHH', rawdata)
sensors = Sensors()
Expand All @@ -141,6 +151,8 @@ def read(self):
def disconnect(self):
if self.periph is not None:
self.periph.disconnect()
self.periph = None
self.curr_val_char = None

# ===================================
# Class Sensor and sensor definitions
Expand Down Expand Up @@ -189,9 +201,8 @@ def getUnit(self, sensor_index):
return self.sensor_units[sensor_index]

try:
#---- Connect to device ----#
#---- Initialize ----#
waveplus = WavePlus(SerialNumber)
waveplus.connect()

if (Mode=='terminal'):
print "\nPress ctrl+C to exit program\n"
Expand All @@ -207,6 +218,8 @@ def getUnit(self, sensor_index):

while True:

waveplus.connect()

# read values
sensors = waveplus.read()

Expand All @@ -226,7 +239,9 @@ def getUnit(self, sensor_index):
print tableprint.row(data, width=12)
elif (Mode=='pipe'):
print data


waveplus.disconnect()

time.sleep(SamplePeriod)

finally:
Expand Down