This tutorial walks through receiving a message from the Hologram Cloud via our Python SDK. You will be using a modem to establish a cellular connection to receive inbound messages from 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 or Huawei E303/MS2131 modem).
- Raspberry Pi 3 running Raspbian Jessie.
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 Jessie. 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
hologram = HologramCloud(dict(), network='cellular')
Let’s connect to the cell network and initialize the receive socket.
result = hologram.network.connect() if result == False: print ' Failed to connect to cell network' hologram.openReceiveSocket()
This will listen to inbound data asynchronously. You might want to stick in a delay here to keep listening for inbound connections. This is how I would do it:
time.sleep(20) # sleep for 20 seconds
We are now ready to start sending messages to the Pi running the Python SDK. Navigate to your dashboard and select the device that you’re using in the cellular modem.
Under Messaging, type a couple words into the input field (I typed “Hi there!”), set the port to
and set the protocol to
Send data message
You should be able to see your received message logged shortly after you send it. We also give you an option to manipulate the received message itself by calling
# Sending "first message" # Sending "second message" # Sending "third message" receivedMsg = hologram.popReceivedMessage() # pops/returns "first message"
The Hologram receive buffer acts like a queue of received messages, and you can pop the earliest message sent.
Once we’re done, let’s close the receive socket and disconnect from the cellular network.
Hurray, you’re now receiving inbound data messages to your Pi! 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' hologram.openReceiveSocket() time.sleep(20) # sleep for 20 seconds hologram.closeReceiveSocket() recv = hologram.popReceivedMessage() print 'Receive buffer: ' + str(recv) hologram.network.disconnect()