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
9 changes: 7 additions & 2 deletions adafruit_rockblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

"""

import time
import struct

__version__ = "0.0.0-auto.0"
Expand Down Expand Up @@ -107,15 +108,19 @@ def data_out(self, buf):
resp = int(line)
if resp != 0:
raise RuntimeError("Write error", resp)
# seems to want some time to digest
time.sleep(0.1)
self._buf_out = buf

@property
def text_out(self):
"""The text in the outbound buffer."""
text = None
# TODO: add better check for non-text in buffer
# pylint: disable=broad-except
try:
text = self._buf_out.decode()
except UnicodeDecodeError:
except Exception:
pass
return text

Expand Down Expand Up @@ -170,7 +175,7 @@ def satellite_transfer(self, location=None):
else:
resp = self._uart_xfer("+SBDIX")
if resp[-1].strip().decode() == "OK":
status = resp[1].strip().decode().split(":")[1]
status = resp[-3].strip().decode().split(":")[1]
status = [int(s) for s in status.split(",")]
if status[0] <= 8:
# outgoing message sent successfully
Expand Down
41 changes: 41 additions & 0 deletions examples/feather_sense_sensors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import time
import struct
import board
import adafruit_lsm6ds
import adafruit_lis3mdl
import adafruit_apds9960.apds9960
import adafruit_sht31d
import adafruit_bmp280
import adafruit_rockblock

# RockBlock setup
uart = board.UART()
uart.baudrate = 19200
rb = adafruit_rockblock.RockBlock(uart)

# all the sensors
accelo = adafruit_lsm6ds.LSM6DS33(board.I2C())
magno = adafruit_lis3mdl.LIS3MDL(board.I2C())
prox = adafruit_apds9960.apds9960.APDS9960(board.I2C())
sht = adafruit_sht31d.SHT31D(board.I2C())
bmp = adafruit_bmp280.Adafruit_BMP280_I2C(board.I2C())

# build data
# can decode on other end with struct.unpack("<6fB5f", data)
data = struct.pack("3f", *accelo.acceleration)
data += struct.pack("3f", *magno.magnetic)
data += struct.pack("B", prox.proximity())
data += struct.pack("2f", sht.relative_humidity, sht.temperature)
data += struct.pack("3f", bmp.pressure, bmp.altitude, bmp.temperature)

# send data
rb.data_out = data
print("Talking to satellite...")
retry = 0
status = rb.satellite_transfer()
while status[0] > 8:
time.sleep(10)
status = rb.satellite_transfer()
print(retry, status)
retry += 1
print("\nDONE.")