Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Task 01: Start the thermostat and occupancy simulator

Introduction

To simulate real-time data ingestion, you’ll start an IoT data simulator that streams telemetry into Azure Event Hubs.

Description

In this task, you’ll retrieve Event Hub credentials and configure a simulator to generate streaming data.

Example scenario

Operations teams monitor temperature and occupancy data to detect anomalies during high-traffic events.

Success criteria

Streaming data is successfully sent to Event Hubs.

Learning resources

  • Event Hubs overview
  • Real-time analytics in Fabric

Key steps

01: Retrieve the for the Eventhouse resources that was deployed for you

  1. Open Edge and go to portal.azure.com.

  2. If prompted, sign in by using the following credentials:

    Setting Value
    Username @lab.CloudPortalCredential(User1).Username
    Temporary Access Pass (TAP) token @lab.CloudPortalCredential(User1).AccessToken
  3. Search for and then select Event Hubs.

    immappsg.jpg

  4. Select the evh-@lab.LabInstance.Id resource.

    z82jwwri.jpg

  5. In the left pane, search for and select Shared access policies.

    xadj6wls.jpg

  6. In the list of policies, select RootManageSharedAccessKey.

    h44h27hi.jpg

  7. In the SAS Policy pane, in the Primary connection string field, select Show content (the eye icon).

    c91tqdh2.jpg

  8. In the SAS Policy pane, in the Primary connection string field, select Copy.

    jdszuv7k.jpg

  9. Paste the connection string into a notepad.


02: Configure the simulator

  1. In the @lab.VirtualMachine(Win11-Pro-Base).SelectLink virtual machine, on the Windows Task Bar, in the search field, enter PowerShell.

    bumdh0o8.jpg

  2. In the list of search results, select PowerShell 7 (x64).

    d1scv204.jpg

  3. Run the following command:

     cd "C:\Lab Assets\app-adx-thermostat-realtime"
    

    kx1hoxra.jpg

    This moves you to the folder containing the simulator project.

  4. In File Explorer, in the address bar, enter PowerShell.

  5. Run the following command to install required components:

     python -m pip install --user -r requirements.txt
    

    It may take 1-3 minutes to complete the process.

    bdjr02rm.jpg

  6. Run the following command:

     $therm = '{"main_data_frequency_seconds":3,"urlStringEventhub":"@lab.Variable(EventHubCxString)","EventhubName":"thermostat","urlPowerBI":"https://httpbin.org/post","data":[{"BatteryLevel":{"minValue":0,"maxValue":100}},{"Temp":{"minValue":60.0,"maxValue":74.0}},{"Temp_UoM":{"minValue":["F"],"maxValue":["F"]}}] }'
    
     $occ = '{"main_data_frequency_seconds":3,"urlStringEventhub":"","EventhubName":"occupancy","urlPowerBI":"https://httpbin.org/post","data":[{"BatteryLevel":{"minValue":0,"maxValue":100}},{"visitors_cnt":{"minValue":20,"maxValue":30}},{"visitors_in":{"minValue":0,"maxValue":10}},{"visitors_out":{"minValue":0,"maxValue":10}},{"avg_aisle_time_spent":{"minValue":20,"maxValue":30}},{"avg_dwell_time":{"minValue":3,"maxValue":13}}] }'
    
     $env:thermostatTelemetryConfig = $therm
     $env:occupancyDataConfig = $occ
    
  7. Run the following command. This starts the simulator.

     python app.py
    
  8. Open Edge and go to http://127.0.0.1:5000/.

    If the page takes more than two minutes to load, return to the PowerShell window and press the Ctrl+C combination to stop the process. Then, repeat Steps 6 - 8.

  9. Verify that streaming has started.

    4c4fxpqe.jpg

  10. Return to the PowerShell window. Verify that you see streaming data. The output should resemble the following screenshot:

    i61y2cd8.jpg

    Do not close the PowerShell window until you complete Exercise 06.

    After completing all tasks in Exercise 6, return to the PowerShell window and stop the simulator by using the Ctrl + C key combination.