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.
Activate Your SIMIf 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.
Setting up the Python SDKWe 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 send-cellular-message.py
You’ll then need to import the appropriate modules. In this example, let’s go ahead and import HologramCloud
like this:
from Hologram.HologramCloud import HologramCloud
Instantiating a HologramCloudAfter that, we create a HologramCloud
instance:
In order to receive messages from the Hologram cloud, we need to establish a cellular network.
hologram = HologramCloud(dict(), network='cellular')
Connect to cellular networkLet’s connect to the cell network.
result = hologram.network.connect()
if result == False:
print ' Failed to connect to cell network'
Sending a cloud messageresponse_code = hologram.sendMessage("hello, world!")
print hologram.getResultString(response_code) # Prints 'Message sent successfully'.
Go ahead and run python send-cellular-message.py
. 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 hello, world!
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'.
Disconnect from cellular networkOnce we’re done, let’s disconnect from the cellular network.
hologram.network.disconnect()
SummaryHurray, 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!
In the meantime, check out our official documentation, and feel free to post your questions in our forum.
Comments