Last active
January 22, 2018 17:32
-
-
Save lewisrodgers/f53dc32abdb88431e67dc7d1dd159cf4 to your computer and use it in GitHub Desktop.
Send sensor data to Cloud Pub/Sub from a BeagleBone
This file contains hidden or 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
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