Skip to content
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ With `pip` via PyPi:
pip install note-python
```

or
or


```bash
Expand Down Expand Up @@ -102,11 +102,11 @@ The documentation for this library can be found

The [examples](examples/) directory contains examples for using this library with:

- [Serial](examples/serial-example.py)
- [I2C](examples/i2c-example.py)
- [RaspberryPi](examples/rpi-example.py)
- [CircuitPython](examples/cpy-example.py)
- [MicroPython](examples/mpy-example.py)
- [Serial](examples/notecard-basics/serial-example.py)
- [I2C](examples/notecard-basics/i2c-example.py)
- [RaspberryPi](examples/notecard-basics/rpi-example.py)
- [CircuitPython](examples/notecard-basics/cpy-example.py)
- [MicroPython](examples/notecard-basics/mpy-example.py)

## Contributing

Expand Down
56 changes: 46 additions & 10 deletions examples/cpy-example.py → examples/notecard-basics/cpy-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import time
import notecard

productUID = "com.your-company.your-project"

# Choose either UART or I2C for Notecard
use_uart = True

Expand All @@ -31,22 +33,48 @@ def NotecardExceptionInfo(exception):
+ ": " + ' '.join(map(str, exception.args))


def transactionTest(card):
def configure_notecard(card):
"""Submit a simple JSON-based request to the Notecard.

Args:
card (object): An instance of the Notecard class

"""
req = {"req": "card.status"}
req = {"req": "hub.set"}
req["product"] = productUID
req["mode"] = "continuous"

try:
card.Transaction(req)
except Exception as exception:
print("Transaction error: " + NotecardExceptionInfo(exception))
time.sleep(5)


def get_temp_and_voltage(card):
"""Submit a simple JSON-based request to the Notecard.

Args:
card (object): An instance of the Notecard class

"""
temp = 0
voltage = 0

try:
req = {"req": "card.temp"}
rsp = card.Transaction(req)
temp = rsp["value"]

req = {"req": "card.voltage"}
rsp = card.Transaction(req)
print(rsp)
voltage = rsp["value"]
except Exception as exception:
print("Transaction error: " + NotecardExceptionInfo(exception))
time.sleep(5)

return temp, voltage


def main():
"""Connect to Notcard and run a transaction test."""
Expand All @@ -63,18 +91,26 @@ def main():
print("Opening Notecard...")
try:
if use_uart:
card = notecard.OpenSerial(port)
card = notecard.OpenSerial(port, debug=True)
else:
card = notecard.OpenI2C(port, 0, 0)
card = notecard.OpenI2C(port, 0, 0, debug=True)
except Exception as exception:
raise Exception("error opening notecard: "
+ NotecardExceptionInfo(exception))

# If success, do a transaction loop
print("Performing Transactions...")
while True:
time.sleep(2)
transactionTest(card)
# If success, configure the Notecard and send some data
configure_notecard(card)
temp, voltage = get_temp_and_voltage(card)

req = {"req": "note.add"}
req["sync"] = True
req["body"] = {"temp": temp, "voltage": voltage}

try:
card.Transaction(req)
except Exception as exception:
print("Transaction error: " + NotecardExceptionInfo(exception))
time.sleep(5)


main()
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import notecard # noqa: E402

productUID = "com.your-company.your-project"

if sys.implementation.name != 'cpython':
raise Exception("Please run this example in a CPython environment.")

Expand All @@ -33,22 +35,48 @@ def NotecardExceptionInfo(exception):
return "line " + s1 + ": " + s2 + ": " + ' '.join(map(str, exception.args))


def transactionTest(card):
def configure_notecard(card):
"""Submit a simple JSON-based request to the Notecard.

Args:
card (object): An instance of the Notecard class

"""
req = {"req": "card.status"}
req = {"req": "hub.set"}
req["product"] = productUID
req["mode"] = "continuous"

try:
card.Transaction(req)
except Exception as exception:
print("Transaction error: " + NotecardExceptionInfo(exception))
time.sleep(5)


def get_temp_and_voltage(card):
"""Submit a simple JSON-based request to the Notecard.

Args:
card (object): An instance of the Notecard class

"""
temp = 0
voltage = 0

try:
req = {"req": "card.temp"}
rsp = card.Transaction(req)
temp = rsp["value"]

req = {"req": "card.voltage"}
rsp = card.Transaction(req)
print(rsp)
voltage = rsp["value"]
except Exception as exception:
print("Transaction error: " + NotecardExceptionInfo(exception))
time.sleep(5)

return temp, voltage


def main():
"""Connect to Notcard and run a transaction test."""
Expand All @@ -61,16 +89,24 @@ def main():

print("Opening Notecard...")
try:
card = notecard.OpenI2C(port, 0, 0)
card = notecard.OpenI2C(port, 0, 0, debug=True)
except Exception as exception:
raise Exception("error opening notecard: "
+ NotecardExceptionInfo(exception))

# If success, do a transaction loop
print("Performing Transactions...")
while True:
time.sleep(2)
transactionTest(card)
# If success, configure the Notecard and send some data
configure_notecard(card)
temp, voltage = get_temp_and_voltage(card)

req = {"req": "note.add"}
req["sync"] = True
req["body"] = {"temp": temp, "voltage": voltage}

try:
card.Transaction(req)
except Exception as exception:
print("Transaction error: " + NotecardExceptionInfo(exception))
time.sleep(5)


main()
56 changes: 46 additions & 10 deletions examples/mpy-example.py → examples/notecard-basics/mpy-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import time
import notecard

productUID = "com.your-company.your-project"

# Choose either UART or I2C for Notecard
use_uart = True

Expand All @@ -31,22 +33,48 @@ def NotecardExceptionInfo(exception):
+ ' '.join(map(str, exception.args))


def transactionTest(card):
def configure_notecard(card):
"""Submit a simple JSON-based request to the Notecard.

Args:
card (object): An instance of the Notecard class

"""
req = {"req": "card.status"}
req = {"req": "hub.set"}
req["product"] = productUID
req["mode"] = "continuous"

try:
card.Transaction(req)
except Exception as exception:
print("Transaction error: " + NotecardExceptionInfo(exception))
time.sleep(5)


def get_temp_and_voltage(card):
"""Submit a simple JSON-based request to the Notecard.

Args:
card (object): An instance of the Notecard class

"""
temp = 0
voltage = 0

try:
req = {"req": "card.temp"}
rsp = card.Transaction(req)
temp = rsp["value"]

req = {"req": "card.voltage"}
rsp = card.Transaction(req)
print(rsp)
voltage = rsp["value"]
except Exception as exception:
print("Transaction error: " + NotecardExceptionInfo(exception))
time.sleep(5)

return temp, voltage


def main():
"""Connect to Notcard and run a transaction test."""
Expand All @@ -65,18 +93,26 @@ def main():
print("Opening Notecard...")
try:
if use_uart:
card = notecard.OpenSerial(port)
card = notecard.OpenSerial(port, debug=True)
else:
card = notecard.OpenI2C(port, 0, 0)
card = notecard.OpenI2C(port, 0, 0, debug=True)
except Exception as exception:
raise Exception("error opening notecard: "
+ NotecardExceptionInfo(exception))

# If success, do a transaction loop
print("Performing Transactions...")
while True:
time.sleep(2)
transactionTest(card)
# If success, configure the Notecard and send some data
configure_notecard(card)
temp, voltage = get_temp_and_voltage(card)

req = {"req": "note.add"}
req["sync"] = True
req["body"] = {"temp": temp, "voltage": voltage}

try:
card.Transaction(req)
except Exception as exception:
print("Transaction error: " + NotecardExceptionInfo(exception))
time.sleep(5)


main()
Loading