Skip to content

Instantly share code, notes, and snippets.

@lewisrodgers
Last active January 22, 2018 17:32
Show Gist options
  • Save lewisrodgers/f53dc32abdb88431e67dc7d1dd159cf4 to your computer and use it in GitHub Desktop.
Save lewisrodgers/f53dc32abdb88431e67dc7d1dd159cf4 to your computer and use it in GitHub Desktop.
Send sensor data to Cloud Pub/Sub from a BeagleBone
import time
# Cloud Pub/Sub ###########################
from google.cloud import pubsub
client = pubsub.PublisherClient()
topic = client.topic_path(PROJECT_ID, TOPIC_NAME)
def send_to_pubsub(message, data):
client.publish(topic, message, userdata=data)
print(message) # just so we can see something happen in the terminal
# BeagleBone ###########################
import mraa
button = mraa.Gpio(71)
button.dir(mraa.DIR_IN)
def callback(userdata):
data = bytes(userdata.read()) # convert to bytes for pubsub
message = "interrupt triggered with userdata = {0}".format(data)
send_to_pubsub(message, data)
while True:
button.isr(mraa.EDGE_BOTH, callback, button)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment