SORACOM Developers

Getting Started

this guide is Machine Translated.

Connect with Azure IoT Hub using SORACOM Beam

Introduction

In this document, we send data to Azure IoT Hub by using SORACOM Beam (hereinafter referred to as Beam).

The premise of this guide is as follows.

What is SORACOM Beam

Beam is a proxy service for data processing on the cloud side when uploading data from SORACOM Air’s SIM device.

Beam Overview

By using Beam, the following becomes possible.

Step 1: Prepare the Azure IoT Hub

Create an IoT Hub

From the Microsoft Aure Portal, open the IoT Hub and create an IoT Hub from “Create IoT Hub”. (If you have already created one, please use that one.)

Create an IoT Device

Confirm authentication information

As authentication information, one of the following can be used.

  1. Use shared access policy
  2. Use authentication information issued for each device

Because you do not have to register credential information for each device, we recommend using “shared access policy” when the number of devices is large.

1. Use shared access policy

2. Use authentication information issued for each device

Use the Primary key or Secondary Key displayed when you select the device (it is convenient to copy it to the clipboard with the right button)

Step 2: Set up SORACOM Beam

Create a group

If you did not create a group when you registered SIM, open [MENU] → [SIM Group] in the upper left, and add a new group from + Add. Select SIM from the SIM list screen, and associate the created group with the belonging group change from the operation.

Set the Beam in the group.

Select the created group, open the [SORACOM Beam Setting] tab from the group detail screen, and select “MQTT entry point” from the [+] button.

Enter the following.

For authentication information, enter the following.

Shared access key is blank if you select “Use authentication information issued for each device” by Azure IoT Hub authentication .

Press Register, confirm that the authentication information is selected, and press Save.

Step 3: Use Beam to send data to Azure IoT Hub

Preparing the device

In this guide we will use Mosquitto’s client. If it is Raspbian, it can be installed with the following command

sudo apt-get install mosquitto-clients

Preparation for confirmation of transmitted data

The transmitted data is confirmed using the following tools.

This guide uses IoT Hub Explorer. Execute the following command to install.

npm install -g iothub-explorer

When installation is completed, execute the following command.

$ connection_string='HostName=xxxx.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=XXXXXXXXXXXXXXXXXXXXX='

$ iothub-explorer monitor-events --login $connection_string

Monitoring events from all devices...

When connecting, iothubowner privilege of IoT Hub’s shared access policies (Shared access policies) is required, so copy one of the Connection Strings to the clipboard.

Send data from device

Send data from the device to the cloud.

Data from the device devices/<deviceId>/messages/events/ should be Publish to the topic named. Also, as the client ID of MQTT, you need to specify the deviceId of the created device (-i option).

pi@raspberrypi: ~$ deviceId=myDevice
pi@raspberrypi: ~$ mosquitto_pub -d -h beam.soracom.io -i $deviceId -t "devices/$deviceId/messages/events/" -m 'Hello from SORACOM Beam!'
Client myDevice sending CONNECT
Client myDevice received CONNACK
Client myDevice sending PUBLISH (d0, q0, r0, m1, 'devices/myDevice/messages/events/', ... (24 bytes))
Client myDevice sending DISCONNECT

It can be confirmed that iothub-explorer side displays as follows.

==== From: myDevice ====
Hello from SORACOM Beam!
---- application properties ----
{
  "imsi": "440101234567890"
}
====================

In this case, since “IMSI Grant” is set to ON in Beam setting, IMSI (unique number of SIM) is also transmitted as a property as a property can be confirmed.

Step 4: Receive data from Azure IoT Hub

Next, we will send the data from the cloud to the device.

Data from the cloud devices/<deviceId>/messages/devicebound/# should subscribe to the topic that says. Also, as the client ID of MQTT, you need to specify the deviceId of the created device (-i option).

pi@raspberrypi: ~$ mosquitto_sub -d -h beam.soracom.io -i $deviceId -t "devices/$deviceId/messages/devicebound/#"
Client myDevice sending CONNECT
Client myDevice received CONNACK
Client myDevice sending SUBSCRIBE (Mid: 1, Topic: devices/myDevice/messages/devicebound/#, QoS: 0)
Client myDevice received SUBACK
Subscribed (mid: 1): 0

In this state, from the device screen of Azure Portal, click “Message To Device” and try to send data from the message transmission screen.

A message is sent to the device and it is displayed as below.

Client myDevice received PUBLISH (d0, q0, r0, m0, 'devices/myDevice/messages/devicebound/%24.to=%2Fdevices%2FmyDevice%2Fmessages%2FdeviceBound', ... (24 bytes))
Hello from Azure Portal!

Getting Started

SORACOM Air for Cellular

SORACOM Air for Sigfox

SORACOM Beam

SORACOM Canal/Direct/Door

SORACOM Endorse

SORACOM Funnel

SORACOM Gate

SORACOM Harvest

SORACOM Inventory

SORACOM Junction

SORACOM Krypton

SORACOM Lagoon

Service Detail

Developer Tools

pagetop