Exporting IoT Central data to Azure SQL Database

%3CLINGO-SUB%20id%3D%22lingo-sub-1347787%22%20slang%3D%22en-US%22%3EExporting%20IoT%20Central%20data%20to%20Azure%20SQL%20Database%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1347787%22%20slang%3D%22en-US%22%3E%3CP%3EInternet%20of%20Things%20(IoT)%20has%20emerged%20as%20one%20of%20the%20most%20disruptive%20forces%20driving%20the%20digital%20transformation.%20To%20help%20organizations%20start%20rapidly%20connecting%20devices%20and%20start%20to%20consume%20information%20generated%20and%20of%20course%20manage%20these%20devices%20Microsoft%20Azure%20have%20IoT%20Central%20offer.%3C%2FP%3E%3CP%3E%3CSTRONG%3EWhat%20is%20IoT%20Central%3F%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%22IoT%20Central%20is%20an%20IoT%20application%20platform%20that%20reduces%20the%20burden%20and%20cost%20of%20developing%2C%20managing%2C%20and%20maintaining%20enterprise-grade%20IoT%20solutions.%20Choosing%20to%20build%20with%20IoT%20Central%20gives%20you%20the%20opportunity%20to%20focus%20time%2C%20money%2C%20and%20energy%20on%20transforming%20your%20business%20with%20IoT%20data%2C%20rather%20than%20just%20maintaining%20and%20updating%20a%20complex%20and%20continually%20evolving%20IoT%20infrastructure.%22%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-in%2Fazure%2Fiot-central%2Fcore%2Foverview-iot-central%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESource%3C%2FA%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22vhyrodrigues_0-1588227551540.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F187766i46242FBC7CF107D6%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22vhyrodrigues_0-1588227551540.png%22%20alt%3D%22vhyrodrigues_0-1588227551540.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EOne%20of%20many%20features%20of%20the%20IoT%20Central%20is%20the%20one%20that%20you're%20able%20to%20export%20reported%20data%20from%20the%20devices%20on%20IoT%20Central%20and%20this%20is%20a%20useful%20feature%20since%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-au%2Fservices%2Fiot-central%2F%23updates-announcements%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EIoT%20Central%20just%20keep%20your%20information%20for%2030%20days%3C%2FA%3E%20and%20another%20thing%20to%20keep%20in%20mind%20is%20once%20you%20enable%20the%20feature%20to%20export%20data%20you%20will%20only%20get%20data%20from%20the%20moment%20you%20turned%20on.%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Fsql-database-stream-analytics%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EThe%20feature%20lets%20you%20export%20your%20data%20continuously%20to%26nbsp%3BAzure%20Event%20Hubs%2C%26nbsp%3BAzure%20Service%20Bus%2C%20or%26nbsp%3BAzure%20Blob%20storage%26nbsp%3Binstances%3C%2FA%3E.%20Data%20export%20uses%20the%20JSON%20format%20and%20can%20include%20telemetry%2C%20device%20information%2C%20and%20device%20template%20information.%20Use%20the%20exported%20data%20for%3A%3C%2FP%3E%3CUL%3E%3CLI%3EWarm-path%20insights%20and%20analytics.%20This%20option%20includes%20triggering%20custom%20rules%20in%20Azure%20Stream%20Analytics%2C%20triggering%20custom%20workflows%20in%20Azure%20Logic%20Apps%2C%20or%20passing%20it%20through%20Azure%20Functions%20to%20be%20transformed.%3C%2FLI%3E%3CLI%3ECold-path%20analytics%20such%20as%20training%20models%20in%20Azure%20Machine%20Learning%20or%20long-term%20trend%20analysis%20in%20Azure%20SQL%20Database%20and%20Microsoft%20Power%20BI.%3C%2FLI%3E%3C%2FUL%3E%3CP%3EI%20used%20it%20as%20the%20base%20for%20my%20IoT%20Central%20application%20and%20then%20later%20for%20the%20data%20export%20to%20Azure%20SQL%20Database%20was%20the%20Microsoft%20Learning%20module%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Flearn%2Fmodules%2Fcreate-your-first-iot-central-app%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%22Create%20your%20first%20Azure%20IoT%20Central%22%3C%2FA%3E.%20After%20you%20complete%20the%20module%20you%20need%20to%20follow%20these%20additional%20steps%3A%3C%2FP%3E%3COL%3E%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-central%2Fcore%2Fhowto-export-data%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EExport%20your%20Azure%20IoT%20Central%20data%20to%20Azure%20Event%20Hub%3C%2FA%3E%3C%2FLI%3E%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fevent-hubs%2Fprocess-data-azure-stream-analytics%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EProcess%20data%20from%20Event%20Hubs%20using%20Stream%20Analytics%3C%2FA%3E%3C%2FLI%3E%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Fsql-database-stream-analytics%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EStream%20data%20using%20Stream%20Analytics%20to%20Azure%20SQL%20Database%3C%2FA%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%3CSTRONG%3EAdditional%20settings%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EThese%20are%20the%20lessons%20learned%20that%20I%20had%20in%20this%20scenario.%3C%2FP%3E%3CP%3E%3CSTRONG%3EAzure%20SQL%20Database%3C%2FSTRONG%3E%3C%2FP%3E%3COL%3E%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Fsql-database-networkaccess-overview%23allow-azure-services%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EConfigure%20your%20Database%20to%20accept%20connection%20from%20Azure%20services%3C%2FA%3E%3C%2FLI%3E%3CLI%3EMake%20sure%20your%20Table%20has%20the%20right%20Data%20Type%2C%20especially%20the%20Date%20Time%20Field%20that%20is%20some%20cases%20required%20the%20Type%20of%20%3CSTRONG%3Edatetime2%3C%2FSTRONG%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%3CSTRONG%3EAzure%20Stream%20Analytics%3C%2FSTRONG%3E%3C%2FP%3E%3COL%3E%3CLI%3EIf%20your%20Stream%20Analytics%20Job%20fail%20to%20check%20the%20%3CSTRONG%3EActivity%20Log%3C%2FSTRONG%3E%2C%20basically%20what%20happen%20with%20me%20was%20that%20even%20after%20I%20fix%20my%20Date%20Time%20column%20still%20throwing%20the%20same%20error%20in%20the%20Stream%20Analytics%20interface%20but%20the%20error%20was%20different%20on%20the%20Activity%20Log.%20(Cache%3F)%3C%2FLI%3E%3CLI%3E%3CSTRONG%3EGetMetadataPropertyValue%3C%2FSTRONG%3E%20is%20an%20Input%20Metadata%20function%20(Responsible%20to%20get%20information%20like%20DeviceID%20and%20others)%20it's%20not%20working%20for%20this%20specific%20scenario.%20I%20change%20my%20code%20to%20send%20DeviceID%20with%20the%20Telemetry.%3C%2FLI%3E%3CLI%3EYou%20can%20use%20the%20power%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fstream-analytics-query%2Fstream-analytics-query-language-reference%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EStream%20Analytics%20Query%20Language%3C%2FA%3E%20to%20do%20some%20nice%20things%20like%20for%20example%20extract%20the%20Latitude%20and%20Longitude%20from%20the%20field%20Location%20in%20JSON%20format%20simply%20using%20%5BLocation%5D.lat%20or%20%5BLocation%5D.lon%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%3CSTRONG%3EOther%3C%2FSTRONG%3E%3C%2FP%3E%3CUL%3E%3CLI%3EBe%20careful%20to%20not%20forget%20your%20devices%20and%20services%20running%2C%20this%20type%20of%20test%20environment%20can%20easily%20consume%20your%20free%20tier%20quota%20and%20subscription%20credits.%3C%2FLI%3E%3C%2FUL%3E%3CP%3EWith%20more%20and%20more%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fupdates%2F%3Fstatus%3Dnowavailable%2Cinpreview%2Cindevelopment%26amp%3Bquery%3DIoT%2520Central%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eupdates%20coming%3C%2FA%3E%20for%20sure%20IoT%20Central%20will%20be%20consolidated%20as%20the%20main%20Azure%20platform%20for%20IoT.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1347787%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EIoT%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eiot%20central%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

Internet of Things (IoT) has emerged as one of the most disruptive forces driving the digital transformation. To help organizations start rapidly connecting devices and start to consume information generated and of course manage these devices Microsoft Azure have IoT Central offer.

What is IoT Central?

"IoT Central is an IoT application platform that reduces the burden and cost of developing, managing, and maintaining enterprise-grade IoT solutions. Choosing to build with IoT Central gives you the opportunity to focus time, money, and energy on transforming your business with IoT data, rather than just maintaining and updating a complex and continually evolving IoT infrastructure." Source

vhyrodrigues_0-1588227551540.png

One of many features of the IoT Central is the one that you're able to export reported data from the devices on IoT Central and this is a useful feature since IoT Central just keep your information for 30 days and another thing to keep in mind is once you enable the feature to export data you will only get data from the moment you turned on. The feature lets you export your data continuously to Azure Event Hubs, Azure Service Bus, or Azure .... Data export uses the JSON format and can include telemetry, device information, and device template information. Use the exported data for:

  • Warm-path insights and analytics. This option includes triggering custom rules in Azure Stream Analytics, triggering custom workflows in Azure Logic Apps, or passing it through Azure Functions to be transformed.
  • Cold-path analytics such as training models in Azure Machine Learning or long-term trend analysis in Azure SQL Database and Microsoft Power BI.

I used it as the base for my IoT Central application and then later for the data export to Azure SQL Database was the Microsoft Learning module "Create your first Azure IoT Central". After you complete the module you need to follow these additional steps:

  1. Export your Azure IoT Central data to Azure Event Hub
  2. Process data from Event Hubs using Stream Analytics
  3. Stream data using Stream Analytics to Azure SQL Database

Additional settings

These are the lessons learned that I had in this scenario.

Azure SQL Database

  1. Configure your Database to accept connection from Azure services
  2. Make sure your Table has the right Data Type, especially the Date Time Field that is some cases required the Type of datetime2

Azure Stream Analytics

  1. If your Stream Analytics Job fail to check the Activity Log, basically what happen with me was that even after I fix my Date Time column still throwing the same error in the Stream Analytics interface but the error was different on the Activity Log. (Cache?)
  2. GetMetadataPropertyValue is an Input Metadata function (Responsible to get information like DeviceID and others) it's not working for this specific scenario. I change my code to send DeviceID with the Telemetry.
  3. You can use the power to Stream Analytics Query Language to do some nice things like for example extract the Latitude and Longitude from the field Location in JSON format simply using [Location].lat or [Location].lon

Other

  • Be careful to not forget your devices and services running, this type of test environment can easily consume your free tier quota and subscription credits.

With more and more updates coming for sure IoT Central will be consolidated as the main Azure platform for IoT.

0 Replies