Routing to Google Cloud

Hi Everyone,

Newbie question:

My Hologram Nova is attached to a Raspberry Pi, and the goal is to send the sensor data to a Firebase database, specifically Cloud Firestore.

I’ve read through the main Routing article, https://support.hologram.io/hc/en-us/articles/360035696573 but without concrete examples, I don’t know where to go.

Here’s my current Python code…

Send a message from the Raspberry Pi to the Hologram Cloud:

import sys
from Hologram.HologramCloud import HologramCloud

if __name__ == '__main__':
    hologram = HologramCloud(dict(), network='cellular')
    print(f'Cloud type: {str(hologram)}')

    recv = hologram.sendMessage('{temperature: 75, humidity:60}',
                                topics = ['TOPIC1','TOPIC2'],
                                timeout = 3)

    print('RESPONSE MESSAGE: ' + hologram.getResultString(recv))

And if I was just on WiFi, not using my Nova, the code to POST sensor data to Firebase is:

import requests
import json

project_id = 'MY-PROJECT-ID'
web_api_key = 'MY-WEB-KEY'
collection_name = 'SensorData'
url = f'https://firestore.googleapis.com/v1/projects/{project_id}/databases/(default)/documents/{collection_name}/?key={web_api_key}'

payload = {
    'fields': {
        'temperature': { 'doubleValue': 75},
        'humidity': {'doubleValue': 60}
    }
}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
response = requests.post(url, data=json.dumps(payload), headers=headers)

print(f'response = {response}')

Ideally, I’d like to understand how to make a Route in my Hologram Dashboard that POSTs the data to Firebase.

Any help is appreciated!

Thanks,
Ryan

@Dom @Reuben

Hi guys, do either of you know of a tutorial / how-to / guide where I can learn how to redirect my JSON data to a database of my choosing?

Thanks,
Ryan

Hi, so good news: since you already have some working code, this should actually be pretty simple for you.
Take a look at the advanced webhook builder route. For the URL you would put that same URL you’re using.
You can then send JSON in your payload which can be parsed and then reformatted in the route.
So like your device would send to our cloud something like this:

{"temp":75,"hum":60}

(You can keep it pretty compact to save on cellular data)
And then in the payload for the route you can do something like this:

{  "fields": {  "temperature" : { "doubleValue" : <<decdata.temp>> },
                    "humidity" : { "doubleValue" : <<decdata.hum>> }
}

Here’s some docs with more information:


https://www.hologram.io/references/data-router#c-references__itemheader-webhook-formats

And I should mention, you can always bypass our cloud entirely and send right from the device to firebase over cellular if that’s easier for you.

Thank you thank you thank you!

Can you give me an example to bypass your cloud? I’d love to try both of your suggestions, and when I get them working, I’ll post both for others to learn too.

Run sudo hologram network connect
That’ll bring up a ppp0 network interface and then you can run the script you already have. If you have wifi and cellular up at the same time, it may use either one. There are some ways to get the requests library to bind to a specific interface.

1 Like