This quick start tutorial walks through sending a message from a Raspberry Pi to the Hologram Cloud via our Python SDK.
This tutorial also assumes that the Python SDK doesn't handle the network interfaces. This is automatically done by your operating system. We will go more in depth on how to send messages by establishing a cellular connection in a separate tutorial.Setup InstructionsSetting up the Python SDK
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
Instantiating a HologramCloud
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.
Connect to cellular network
hologram = HologramCloud(dict(), network='cellular')
Let’s connect to the cell network.
Sending a cloud message
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.
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!") print hologram.getResultString(response_code) # Prints 'Message sent successfully'. hologram.network.disconnect()
Want to learn about more Hologram Python SDK features? Stay tuned for more tutorials!