This tutorial walks through sending a message with the Hologram Cloud via our Python SDK. You will be using a modem to establish a cellular connection and send messages to the Hologram Cloud.
Before starting, make sure you have the following items:
- Active device (SIM) listed on your dashboard.
- A supported cellular modem (Hologram Nova, Huawei E303/MS2131 modem).
- Raspberry Pi 3 running Raspbian Jessie/Stretch.
The SIM card is available from the Hologram store.
If you haven’t already, create a Hologram account to manage your devices and billing.
From the Hologram Dashboard, click the Activate SIM button in the top-right corner.
Every SIM card has an 18-22 digit unique ID printed on it. Enter your SIM’s ID in the activation form.
Then, choose your data plan and zone according to your needs. If you aren’t sure which plan is right for you, start with pay-as-you-go. See our pricing page for more details on plans and zones.
Once your device is active, you’re ready to start sending messages to the cloud.
We wrote and tested this tutorial by installing and using the Hologram SDK on Raspbian Stretch. Please ensure that you have Python 2.7 installed on your Raspberry Pi.
You’ll need to install the Python SDK. Please refer to this doc for SDK installation instructions.
After installing the Python SDK, let’s start by creating an empty Python script named
You’ll then need to import the appropriate modules. In this example, let’s go ahead and import
from Hologram.HologramCloud import HologramCloud
After that, we create a
In order to receive messages from the Hologram cloud, we need to establish a cellular network.
hologram = HologramCloud(dict(), network='cellular')
Let’s connect to the cell network.
result = hologram.network.connect() if result == False: print ' Failed to connect to cell network'
response_code = hologram.sendMessage("hello, world!") print hologram.getResultString(response_code) # Prints 'Message sent successfully'.
Go ahead and run
. You should receive a logged message that says:
Message sent successfully
Go back to your dashboard and click on the Logs section and you should be able to see the
message that you just sent.
We also give you an option to attach topics to a particular message that you’re sending. You could do this instead:
response_code = hologram.sendMessage("hello, world!", topics = ["example-topic"]) print hologram.getResultString(response_code) # Prints 'Message sent successfully'.
Once we’re done, let’s disconnect from the cellular network.
Hurray, you’re now sending data messages from your Raspberry Pi to the Hologram Cloud! Your final Python script should look something like this:
from Hologram.HologramCloud import HologramCloud hologram = HologramCloud(dict(), network='cellular') result = hologram.network.connect() if result == False: print ' Failed to connect to cell network' response_code = hologram.sendMessage("hello, world 1!") print hologram.getResultString(response_code) # Prints 'Message sent successfully'. response_code = hologram.sendMessage("hello, world 2!", topics=["example-topic"]) hologram.network.disconnect()
Want to learn about more Hologram Python SDK features? Stay tuned for more tutorials!
Love this project? Think it could be improved? Tell us what you think!