Skip to main content

Azure AppDev Challenge

Appendix B โ€“ IOT Simulatorโ€‹

The IOT Simulator is a containerised .NET console app that will generate simulated alarm events and publish those events to an Azure Event Grid Topic (that you need to create - refer to Appendix G for help).

The IOT Simulator will by default generate an alarm event for one of 10 devices (with static latitude and longitude) every 30 seconds for 60 minutes, after which it will stop.

Each alarm event includes a randomly selected image. There are 15 images in this URL location below - but you could substitute your own location and images (name each image photoXX.png where XX is 01, 02, 03 etc.):

https://thingsstorage.blob.core.windows.net/iotphotos/

e.g. https://thingsstorage.blob.core.windows.net/iotphotos/photo01.png

The intent is for you to determine the status of the alarm (is it a false positive or not) by for example using the vision cognitive services and analysing the images to determine the threat they represent.

Running the IOT Simulator containerโ€‹

The container image can be found here: https://hub.docker.com/r/markharrison/alarms-iot-simulator

The IOT Simulator source code is here if of interest: https://github.com/markharrison/AlarmsIOTSimulator

Using Docker CLI locallyโ€‹

docker run -e AlarmTopic="YOURENDPOINT" 
-e AlarmKey="YOURKEY"
-e AlarmImageRoot="imagerooturl"
markharrison/alarms-iot-simulator

for example:

docker run -e AlarmTopic='https://thingseventgrid.northeurope-1.eventgrid.azure.net/api/events' 
-e AlarmKey='tDjRnrwV0taI7DmSAsSnmb8SamZfbyEkPAlznUpyp00='
-e AlarmImageRoot='https://thingsstorage.blob.core.windows.net/iotphotos/'
-e AlarmImageNumber='15'
markharrison/alarms-iot-simulator

Using Azure Container Instanceโ€‹

az container create --resource-group YOURRG --name YOURNAME 
--image markharrison/alarms-iot-simulator --restart-policy Never
--environment-variables AlarmTopic=YOURENDPOINT AlarmKey=YOURKEY AlarmImageRoot=imageurl

Other parameter optionsโ€‹

The readme in the GitHub repository includes more information on the required and optional parameters.

For example you can change the number of devices, the interval between alarms, how long the simulator runs for, the map area that the devices are located within and more.

Some examples of locations to override the default latitude and longitude:

ParamReadingLondonEdinburghBelfastNottinghamCardiff
AlarmMaxLat51.47018251.66232655.97474454.62804652.98143151.507668
AlarmMinLat51.42268051.31429755.90744754.56917652.91585651.462985
AlarmMaxLong-1.028539-0.492208-3.302623-5.966994-1.194147-3.241660
AlarmMinLong-0.9040840.158732-3.127528-5.866400-1.083940-3.142783

Here is an example using all the parameters to run the IOT Simulator (with docker CLI) for 20 devices, every 5 secs, for the area of Reading, with 10 images and running for 60 minutes:

docker run -e AlarmTopic='https://*myalarms.northeurope-1*.eventgrid.azure.net/api/events' 
-e AlarmKey=*'Abcdefghijklmnopqrstuvwxyz=*'
-e AlarmImageRoot=โ€™<https://alarmimages.blob.core.windows.net/alarmimages/>โ€™
-e AlarmImageNumber='10'
-e AlarmInterval='5000'
-e AlarmNumDevices='20'
-e AlarmMaxLat='51.470182' -e AlarmMinLat='51.422680'
-e AlarmMaxLong=-'-1.028539' -e AlarmMinLong='-0.904084'
-e AlarmMaxRunTime='60'
markharrison/alarms-iot-simulator