-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from FEEprojects/improve-test
Improve test
- Loading branch information
Showing
5 changed files
with
87 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
from .plantower import PlantowerReading, Plantower, PlantowerException | ||
from .plantower import ( | ||
PlantowerReading, | ||
Plantower, | ||
PlantowerException, | ||
PMS_PASSIVE_MODE, | ||
PMS_ACTIVE_MODE | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setuptools.setup( | ||
name="plantower", | ||
version="0.0.10", | ||
version="0.0.11", | ||
author="Philip Basford", | ||
author_email="[email protected]", | ||
description="An interface for plantower particulate matter sensors", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,28 @@ | ||
# test code for sleep wakeup with passive mode | ||
pt = plantower.Plantower(port='COM3') | ||
#!/usr/bin/env python3 | ||
""" | ||
Basic test script to demonstrate active mode of the plantower | ||
""" | ||
|
||
pt.set_to_sleep() | ||
time.sleep(5) | ||
from argparse import ArgumentParser | ||
import time | ||
import plantower | ||
|
||
pt.set_to_wakeup() | ||
pt.mode_change(0) | ||
time.sleep(10) | ||
|
||
result = pt.read_in_passive() | ||
pt.set_to_sleep() | ||
print(result) | ||
exit(0) | ||
|
||
|
||
# test code for passive mode | ||
pt = plantower.Plantower(port='COM3') | ||
pt.mode_change(0) | ||
time.sleep(5) | ||
result = pt.read_in_passive() | ||
print(result) | ||
exit(0) | ||
|
||
PARSER = ArgumentParser( | ||
description="Test plantower code in active mode") | ||
PARSER.add_argument( | ||
"port", | ||
action="store", | ||
help="The serial port to use") | ||
ARGS = PARSER.parse_args() | ||
|
||
# test code for active mode | ||
pt = plantower.Plantower(port='COM3') | ||
print(pt.read()) | ||
|
||
PLANTOWER = plantower.Plantower(port=ARGS.port) | ||
print("Making sure it's correctly setup for active mode. Please wait") | ||
#make sure it's in the correct mode if it's been used for passive beforehand | ||
#Not needed if freshly plugged in | ||
PLANTOWER.mode_change(plantower.PMS_ACTIVE_MODE) #change back into active mode | ||
PLANTOWER.set_to_wakeup() #ensure fan is spinning | ||
time.sleep(30) # give it a chance to stabilise | ||
#actually do the reading | ||
print(PLANTOWER.read()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Basic test script to demonstrate passive mode of the plantower | ||
""" | ||
from argparse import ArgumentParser | ||
import time | ||
import plantower | ||
|
||
|
||
PARSER = ArgumentParser( | ||
description="Test plantower code in passive mode") | ||
PARSER.add_argument( | ||
"port", | ||
action="store", | ||
help="The serial port to use") | ||
ARGS = PARSER.parse_args() | ||
|
||
|
||
PLANTOWER = plantower.Plantower(port=ARGS.port) # create the object | ||
print("Setting sensor into passive mode. Please wait.") | ||
PLANTOWER.mode_change(plantower.PMS_PASSIVE_MODE) #change into passive mode | ||
PLANTOWER.set_to_wakeup() #spin up the fan | ||
time.sleep(30) #give the sensor a chance to settle | ||
RESULT = PLANTOWER.read_in_passive() # request data in passive mode | ||
print(RESULT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Basic test script to demonstrate passive mode with fan turn off for the plantower | ||
""" | ||
import time | ||
from argparse import ArgumentParser | ||
import plantower | ||
|
||
|
||
PARSER = ArgumentParser( | ||
description="Test plantower code in passive mode with fan turn off") | ||
PARSER.add_argument( | ||
"port", | ||
action="store", | ||
help="The serial port to use") | ||
ARGS = PARSER.parse_args() | ||
|
||
|
||
PLANTOWER = plantower.Plantower(port=ARGS.port) | ||
print("Turning off the fan for 15s") | ||
PLANTOWER.set_to_sleep() #Stop the fan in the sensor | ||
time.sleep(15) | ||
print("Waking back up. Please wait") | ||
PLANTOWER.set_to_wakeup() # Start the fan in the sensor | ||
PLANTOWER.mode_change(plantower.PMS_PASSIVE_MODE) | ||
time.sleep(30) # Give the readings a chance to settle after fan spin up | ||
#30s is suggested in the datasheet | ||
|
||
RESULT = PLANTOWER.read_in_passive() # request data in passive mode | ||
PLANTOWER.set_to_sleep() # turn fan off again | ||
print(RESULT) |