3

Is there an emulator or any suggestions for setting up developer environments with IoT Hub. Having a single IoT Hub in our dev environment shared by all our developers is problematic because messages from each developer are handled by all developers. Setting up unique IoT Hub instances for each developer is also problematic because of the local configuration changes required to connect to each IoT Hub.

An Emulator would be AWESOME! but if that's not available some other way to segregate traffic per developer would be extremely useful.

Regards, Eli

Eli Pulsifer
  • 713
  • 9
  • 25
  • Its not about the individual devices, a developer will be running a instance of our service fabric application on a local cluster and the service listening to IoT Hub will either received traffic from everyone else connected to the IoT Hub or it will fail to connect because the consumer group has to many clients. Developer specific user groups would be fine but its difficult to manage that with service fabric since the configuration is in SCM. – Eli Pulsifer Nov 18 '16 at 16:31
  • [Bryan Campos](https://stackoverflow.com/users/7460425) posted an [Answer](https://stackoverflow.com/a/66269914) with a link to https://github.com/Azure/iotedgehubdev – Scratte Feb 19 '21 at 09:37

3 Answers3

2

I'm afraid there's no Azure IoT Hub emulator yet.

If by emulator, you're talking about something like a local server and keeps all the storage in the local RAM or HDD, this might sound like a good idea.

However, when you think about it, it's no easy task for such emulator. Under the hood, we're talking about multiple communication protocol support(http, mqtt, ampq, etc), custom gateway support and seamless integration with other Azure offerings like Stream Analytics, etc...

Not saying it's impossible, but it's complicated.

Anyway, if you want to keep away from receiving unwanted messages from IoT Hub, there's some workaround you can try for now. For example, with mqtt protocol, you can subscribe to some so-called "topic", identified by unique "device id".

If you look forward to having a minimum IoT Hub emulator, go ahead an open up a request in the Azure IoT Hub user voices.

Jackie
  • 2,032
  • 1
  • 12
  • 14
  • 1
    IoT Hub Emulator will be of huge help for dev and testing purposes, because our environment is used by multiple teams and we have already made use of the free one, so its challenging for other development teams to spin up paid ones for each and every development projects. I understand its difficult to develop Emulator identical to Iot hub of cloud, but however MSFt can offer a slim down version of iothub with limited support for protocols and features. – Ilyas F Aug 16 '17 at 10:15
0

There are few solutions to ease contention when using a single hub. Here are two suggestions:

  1. (Recommended) Unit testing - instead of relying on live data and connecting to a real hub structure your code in a way that you can debug and test it using test input. It usually requires only one layer or separation. For example: http_trigger_azure_function calling a piece of code that can be called from a unit test. If you structure your code this way the Iot Hub specific code should be minimal.

  2. When using a shared hub you could use custom routes so that only telemetry from developer A's devices goes to developer A's consumer.

tymtam
  • 31,798
  • 8
  • 86
  • 126
-2

Official Azure IoT EdgeHub Dev Tool

The Azure IoT EdgeHub Dev Tool provides a local development experience with a simulator for creating, developing, testing, running, and debugging Azure IoT Edge modules and solutions.

The simulator allows you to run, test and debug your own custom IoT Edge modules locally, without the IoT Edge Runtime, and with the following benefits:

  • Your custom Edge module code is the same whether running on the simulator or the full IoT Edge Runtime.
  • Your Edge solution can be run locally without the need to push new images or create IoT Edge deployment manifests.
  • The only credential required to run your Edge solution on the simulator is the IoT Edge Device Connection String. The IoT Hub Connection String is not needed.
  • It helps you debug your custom Edge modules on the host and not just in the container.

The following table compares the requirements to run your solution on the IoT Edge Runtime and iotedgehubdev tool:

IoT Edge Runtime iotedgehubdev
Device Credential Needed YES YES
IoT Hub Credential Needed YES NO
Build Image YES YES
Push Image YES NO
Create Deployment YES NO
Support native debug scenario NO YES

Installing

  1. Install Docker CE (18.02.0+) on Windows, macOS or Linux

  2. Install Docker Compose (1.20.0+) (Linux only. Compose has already been included in Windows/macOS Docker CE installation)

  3. Install Python (2.7/3.5/3.6/3.7/3.8) and Pip

  4. Install iotedgehubdev by running the following command in your terminal:

    pip install --upgrade iotedgehubdev
    

    Note: Please install iotedgehubdev to root on Linux/macOS (Don't use '--user' option in the 'pip install' command).

Please make sure there is no Azure IoT Edge runtime running on the same machine as iotedgehubdev since they require the same ports.

Quickstart

1. Setup

Windows
iotedgehubdev setup -c "<edge-device-connection-string>"
Linux/macOS
sudo iotedgehubdev setup -c "<edge-device-connection-string>"

2. Start/Stop an IoT Edge solution in simulator

Windows
iotedgehubdev start -d <path/to/deployment-manifest>
iotedgehubdev stop
Linux/macOS
sudo iotedgehubdev start -d <path/to/deployment-manifest>
sudo iotedgehubdev stop

3. Start and debug a single module natively

  1. Start the module with specific input(s) and/or environment variable(s)

    Windows
    iotedgehubdev start -i "<module-inputs>"
    
    // OR
    
    iotedgehubdev start -i "<module-inputs>" -e "<environment-variable>"
    
    Linux/macOS
    sudo iotedgehubdev start -i "<module-inputs>"
    
    // OR
    
    sudo iotedgehubdev start -i "<module-inputs>" -e "<environment-variable>"
    

    For example:
    iotedgehubdev start -i "input1,input2" -e "TestEnv1=Value1" -e "TestEnv2=Value2"

  2. Output the module credential environment variables

    iotedgehubdev modulecred
    
  3. Start your module natively with the environment variables from the previous step

  4. Send a message to your module through the RESTful API

    For example:
    curl --header "Content-Type: application/json" --request POST --data '{"inputName": "input1","data": "hello world"}' http://localhost:53000/api/v1/messages

  5. Stop the simulator

    Windows
    iotedgehubdev stop
    
    Linux/macOS
    sudo iotedgehubdev stop
    

Other resources

Data/Telemetry

This project collects usage data and sends it to Microsoft to help improve our products and services. Read our privacy statement to learn more. If you don’t wish to send usage data to Microsoft, you can change your telemetry settings by updating collect_telemetry to no in the ini file.

Concerns

While our friend commented he is worried the official link changes, I am hoping the official Microsoft's repo link on GitHub never changes (unless while it still useful). At least, I dont know how other way I can post binary files here. Here is the repo https://github.com/Azure/iotedgehubdev

Cheers To everyone