Skip to content

olivierbloch/iot-hub-echo-preview

Repository files navigation

services platforms author
iot-hub, functions
node
olivierbloch

Azure IoT Hub ping

Simple "ping" solution to help validate a device connectivity to Azure IoT Hub. The solution consists in an Azure IoT Hub and an Azure Function deployed at once. The Azure Function is triggered when a new message is received on the IoT Hub and will send the same message content back to the device that sent it. The project contains all the code and deployment configuration needed for the solution. It also contains a simple device sample written in JavaScript for Node.js.

Deploy the ping solution

If you are deploying from the azure-sample web page, read below. If you are deploying from the GitHub Readme.md file, skip next chapter and go directly to the "Deploying with the Deploy button on the GitHub Readme.md page" one.

Deploying from the azure-sample web page

When deploying from the azure-samples web page, you will be redirected to the Azure portal for login and the custom deployment of the ARM template will start.

  • Enter parameters for the solution in the "Parameters" blade appearing when clicking on parameters:
    • Region: pick the region you want the services to be deployed to.
    • Choose a solution name: Important, the solution name should be all lower case, only ascii caracters and no longer that 16 characters.
    • IoT Hub Sku: select the Sku you want for the IoT Hub : F1 (Free), S1 or S2. Note that you can only have 1 instance of F1 per Azure subscription.
    • Function Sku: select the Sku you wnat for the Azure Function.
  • Subscription: this is the subscription you want the services to be deployed to if you have several Azure subscriptions.
  • Resource Group: The services will be deployed and grouped under the specified resource group allowing a simpler management in the Azure portal. You can choose to create a new one, or to use an existing resource group.
  • Review Legal Terms

Once you have validated the parameters and reviewed and accepted the legal terms, the solution will be deployed to your solution. You can skip to the Message Format section below.

Deploying with the Deploy button on the GitHub Readme.md page

Click on the blue button below

Once you have clicked on the button, you will be asked to login with your Azure subscription's credentials. When you are logged in, you will be prompted for entering parameters for the solution:

  • Directory: Your Azure acount is bound to an Azure Active Directory. Usually the default one is the only one, but in some cases, you might be using several, in which case you can select the one you want your solution to be secured with.
  • Subscription: this is the subscription you want the services to be deployed to if you have several Azure subscriptions.
  • Resource Group/Resource Group Name: The services will be deployed and grouped under the specified resource group allowing a simpler management in the Azure portal. You can choose to create a new one, or to use an existing resource group.
  • Region: pick the region you want the services to be deployed to.
  • Choose a solution name: Important, the solution name should be all lower case, only ascii caracters and no longer that 16 characters.
  • IoT Hub Sku: select the Sku you want for the IoT Hub : F1 (Free), S1 or S2. Note that you can only have 1 instance of F1 per Azure subscription.
  • Function Sku: select the Sku you wnat for the Azure Function.

Hit Next The wizard checks the selected parameters and lists the services it will deploy:

  • Microsoft.Storage is the an Azure storage service required by both IoT Hub and Function
  • Microsoft.Devices is the Azure IoT Hub service
  • Website is the Azure Function service.

Hit Deploy in the wizard and wait a couple minutes for the services to be deployed and configured.

To visualize the newly deployed services in the Azure portal, you can simply click on the "Manage your resources" link displayed in the final screen of the deployment wizard.

Now that the services are deployed, you can look at how you can connect devices to Azure IoT Hub following instructions from the Azure IoT SDKs repository.

Message format

In order for a device to send a ping and receive the response from the solution, it needs to send a JSON message using the following format:

{
    "deviceId":"<deviceId>",
    "message":"Hello IoT World"
}

Where 'deviceId' is the device's ID as created in the Azure IoT Hub device registry. The message the device will receive back will contain the "message" itself.

Send a ping from the Node device sample

Now that you have your IoT Hub ping solution deployed, you can test any of your devices that you are trying to connect to Azure IoT Hub using the Azure IoT Hub SDKs.

The Azure IoT Hub SDKs are portable and can run on most types of devices out there, but if you want to get started on a device that has been certified for Azure IoT Hub, look into the list of devices certified for Azure IoT.

And if you are looking for some cool cheap device to get started fast, ckeck out the Azure IoT Starter Kits.

... Or you can test and play around with the Node.js sample provided in this repository. In order to use this one, follow the below steps: The prerequisite to run this sample is to have node.js installed on the machine you are using and that you have cloned or downloaded the current repository locally.

  1. Create a new device Id in the IoT Hub deployed previously and copy its connection string: you will find instructions on how to do this here.
  2. Open the file devicesample/simple_sample_device.js
  3. Find the below line of code and replace 'connectionstring' with the device's connection string you just copied
var connectionString = '<connectionstring>';
  1. Open a command prompt, navigate to the devicesample folder and type the following commands
npm install
node .

At this point the node sample device will establish a secure connection with Azure IoT Hub, send messages every other second and should receive the message back from IoT Hub. If you want to get started with Azure IoT Hub, visit Azure.com/iotdev.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published