How to send events from a Raspberry Pi to Microsoft Azure Event Hubs

Sending data from a Raspberry Pi to a Microsoft Azure Event Hub is remarkably easy.  Here are the steps:

1) Configure your Event Hub in Azure

This article on MSDN shows the steps to set up an Event Hub.  It’s very easy and takes just a minute.  But when you get to the part about how to send messages, come see #2 and #3 below!

2) Install the Azure SDK on your Pi

This should be pretty easy, but I had a little bit of trouble getting pip 3.2 running on my Raspberry Pi 2 B.  Once I did get pip-3.2 installed (because Python 3.2 is what comes on the Raspberry Pi), it’s easy:

pip-3.2 install azure

3) Write a little code

Once the Azure SDK is installed, you can write your “Hello Event Hub” program.  Here’s what mine looked like:

azure poc

You can download this sample on github:

Note, this sample is largely based on this article in the Azure SDK documentation.

The only things that weren’t immediately obvious to me from the official SDK documentation was what the shared_access_key_name,shared_access_key_value, service namespace, and hub names were.  Here are a couple screenshots to help you visually map the data points:

Namespace and Event Hub names:

Namespace and Event Hub Names

Shared Access:

Shared Access

4) Glory! 🙂

Once you get this set up, you’re ready to event!  The Azure portal gives you a handy dashboard to see the rate a which messages are coming through (but, there’s a bit of a delay, so don’t worry if there is a delay between when you start sending messages and there is something to see in the dashboard):

Event Hub Dashboard

5 thoughts on “How to send events from a Raspberry Pi to Microsoft Azure Event Hubs

  1. Hi, Your article was interesting, and I made it. I want to ask about do you know “how to receive events from azure event hub to raspberry pi”


    1. I haven’t tried it myself, but this article looks like what you need:

      What is your use case though? Event hubs are nice for sending large volumes of messages from your IoT device to the cloud for processing/analytics/whatever.

      On the other hand, if you are trying to send messages to your Raspberry Pi, a service bus queue or topic might be more appropriate. They can be used from your Raspberry Pi using the same ServiceBusService object we used to send above: sbs.receive_queue_message. See for more on this and other things you can do using the Azure ServiceBus python sdk.


  2. i try command pip-3.2 install azure to install in raspberry but geting error
    TypeError: unsupported operand type(s) for -=: ‘Retry’ and ‘int’
    help me to get out ot this


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s