Using Soracom Beam to send data to ClearBlade IoT Core

Before getting started, you will need the following:

  • A Soracom account and a registered IoT SIM
  • A device with a network connection, such as a Raspberry Pi and a Soracom Onyx LTE USB dongle
  • A ClearBlade account and a ClearBlade project

Step 1: Prepare ClearBlade IoT Core

Create a Registry

  1. Create a registry.

    Image showing the steps

You can also use an existing registry.

For more details on how to operate ClearBlade IoT Core, refer to Creating registries and devices.

  1. Access the ClearBlade IoT Core console and click +ADD REGISTRYCreate Registry.

    Image showing the steps

    The "Create a registry" screen will appear.

Actions Description
Registry propertiesRegistry ID Enter any Registry ID. From here onwards, it will be represented as ${registry_id} (e.g., sample). (*1)
Registry propertiesRegion Select a region. From here onwards, it will be represented as ${region} (e.g., asia-east1). (*1)
Cloud Pub/Sub topicsSelect a Cloud Pub/Sub topic Select a Google Cloud Pub/Sub topic. To create a topic, use the Google Cloud Pub/Sub Topic screen.

(*1) Cannot be changed after creation.

  1. Click SHOW ADVANCED OPTIONS.

  2. Set the following items.
Actions Description
Protocols → MQTT Check this option.
Protocols → HTTP Uncheck this option.

Image showing MQTT and HTTP settings

  1. Click CREATE.

Create a Secret/Public Key Pair

To connect a device on ClearBlade IoT Core, you will need to create a secret/public key pair. For Beam, it supports RS256 and ES256 as encryption algorithms for the keys. Below is an example of creating a secret/public key pair using the openssl command for RS256. In the following steps, the public key (e.g., rsa_public.pem) will be uploaded to ClearBlade IoT Core, and the private key (e.g., rsa_private.pem) will be uploaded to Soracom.

  1. Create the secret key.

    $ openssl genpkey -algorithm RSA -out rsa_private.pem -pkeyopt rsa_keygen_bits:2048

    A secret key (e.g., rsa_private.pem) will be created.

  2. Create the public key.
    $ openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem

    A public key corresponding to the secret key (e.g., rsa_public.pem) will be created.

Upload the public key to ClearBlade IoT Core and register a device

  1. Access the ClearBlade IoT Core console, then click + ADD REGISTRY to create a device.

  2. Click Devices+ in order.

    Image showing Devices tab and add button

  3. Enter any Device ID.

    The device will be represented as ${device_id} (e.g., beam-device-01) from here onwards.

  4. Click COMMUNICATION, LOGGING, AUTHENTICATION.

  5. Set the following items in Authentication (optional).

    Item Actions
    Input method Select "Enter manually".
    Public key format Select the public key algorithm created from the pair of secret/public keys (RS256).
    Public key value Paste the content of the public key (e.g., rsa_public.pem) created from the secret/public key pair.

Image showing the Registry selection

  1. Click SUBMIT.

Step 2: Set up Soracom Beam

Set the MQTT entry point for Beam.

Register Authentication Information to Google Cloud IoT Core

To connect Beam with ClearBlade IoT Core, you need to register the authentication information you created earlier (secret key) in the User Console. Click on your username, Security, then CREDENTIALS. For more details on how to use authentication information storage, please refer to this guide.

Enter the following information:

Item Actions
CONFIGURATION NAME Enter any authentication ID. For example, Google-Cloud-IoT-Core-credential.
PROJECT ID Enter project ID (e.g., sample-project).
REGION Enter the region ID (e.g., asia-east1).
REGISTRY ID Enter the registry ID (e.g., sample).
DEVICE ID Enter the device ID (e.g., beam-device-01).
ALGORITHM Select the encryption algorithm corresponding to the secret/public key pair you created (e.g., RS256).
PRIVATE KEY Paste the content of the private key file (e.g., rsa_private.pem).

Set up the MQTT entry point for Beam

  1. In the SIM group settings, select Soracom Beam Settings.
    For more details on how to configure a group in Beam, refer to Group Settings.

  2. Click MQTT entry point.

  3. Set the following.

    Item Directions
    CONFIGURATION NAME Insert a name of your choice
    PORT NUMBER 1883
    HOST NAME Enter the FQDN (Fully Qualified Domain Name) of the host, e.g., asia-east1-mqtt.clearblade.com. For details on the MQTT host in ClearBlade IoT Core, refer to Retargeting devices
    PORT NUMBER Enter port number 8883
    CREDENTIALS SET Select the authentication information you registered earlier
    Append IMSI to topic Disable the IMSI option
    PLATFORM VERSION Select the platform version 201912

    Image showing MQTT settings

  4. Click Save.

You can now configure Beam settings for your IoT SIMs.

Step 3: Send data to ClearBlade IoT Core using Beam

Here, we will use mosquitto_pub, an MQTT message broker provided as open-source software, to publish data.

  1. Install mosquitto-clients

Download and install mosquitto-clients here.

For Raspberry Pi, you can install it with the following command:

sudo apt install mosquitto-clients
Run the following command on a device that belongs to the IoT SIM in the group settings to send data.
For example, if the Device ID is beam-device-01, the command is:
mosquitto_pub -h beam.soracom.io -t /devices/beam-device-01/events -m "Hello, World"

Example output:

Client (null) sending CONNECT
Client (null) received CONNACK (0)
Client (null) sending PUBLISH (d0, q0, r0, m1, '/devices/beam-device-01/events', ... (12 bytes)
Client (null) sending DISCONNECT

The data will be sent via Beam, and it will be forwarded to ClearBlade IoT Core. Next, confirm that the data was successfully transmitted.

  1. Access ClearBlade Cloud Console
    Go to the console and click RegistryTelemetry Pub/Sub Topics to check the data transmission.

    ClearBlade Cloud Console showing Registry

  2. Google Cloud Pub/Sub will display the topic.
    Click on Subscription.

  3. Click on Message → PULL to retrieve the sent data.

    The data you sent will appear, for example:

    • Device ID: device01
    • Message: "Hello, World"

Step 4: Receive data from ClearBlade IoT Core on your device

  1. Run the following command on the device that belongs to the IoT SIM in the group settings.
    For example, if the Device ID is beam-device-01, the command is:
    mosquitto_sub -d -h beam.soracom.io -t /devices/beam-device-01/commands/#

Example output:

Client (null) sending CONNECT
Client (null) received CONNACK (0)
Client (null) sending SUBSCRIBE (Mid: 1, Topic: /devices/beam-device-01/commands/#, QoS: 0)
Client (null) received SUBACK
Subscribed (mid: 1): 0
  1. Access ClearBlade Cloud console
    Go to the console, and click Registry to view the device.

  2. Click Devices → beam-device-01 and view the device details.

    Send command button in ClearBlade Console

  3. Click the ⋮ → Send command button.

    Send command button in ClearBlade Console

  4. In the Send command dialog:

    • Set Format to Text.
    • Enter the command in Command data, for example: Hello!.
    • Click SEND COMMAND.

    Send command dialog

The device receives the message:

Client (null) received PUBLISH (d0, q0, r0, m0, '/devices/beam-device-01/commands', ... (6 bytes))
Hello!

If the device is not receiving messages, the following feedback will be displayed repeatedly:

Client (null) sending PINGREQ
Client (null) received PINGRESP
Client (null) sending PINGREQ
Client (null) received PINGRESP
...