Counting the current number of IoT Hub messages and devices

Sander van de Velde | Microsoft MVP Azure IoT | Principal IoT Architect | Speaker | Advisor's avatarSander van de Velde

Microsoft provides SDKs for both building IoT devices and accessing the IoT Hub (based on several programming languages).

Regarding the IoT Hub, with the SDK you are able to eg. register and control devices.

Still, some actions are possible with the IoT Hub which is not supported by the SDK.

For those actions, Microsoft supports an IoTHub Rest API which extends the capabilities of the SDK.

In the past, I demonstrated how to work with C2D messages using the REST API.

A few days back, I came along with this MS Learn question about IoT Hub message counts. This also has to be tackled by the REST API.

Let’s see how.


View original post 507 more words

Send Telemetry data to your Azure IOT Hub…using Device Client SDK’s…

In the earlier blog post, we have seen how to connect to your Azure IOT Hub using Raspberry PI Online Simulator and send telemetry data…

In this post, we will be using Azure IOT Device Client SDK’s for sending the Telemetry data to IOT Hub…

This approach uses .NET Core SDK libraries using a Console application….

Creating a C# Console Application

  1. Open Visual Studio, go to File -> New -> and select Project.
  2. In Templates, select Visual C#, select Console App (.NET Framework) and give an appropriate name in the ‘Name’ textbox and then click the OK button.

3. Installing Microsoft Azure IOT Device Client SDK…Go to Project -> Manage NuGet Packages.

4. Click Browse tab and search for Microsoft.Azure.Devices.Client. You will see the Microsoft.Azure.Devices.Client device SDK will have listed in the search result and click Install button

5. Now, click the I Accept button to accept the license agreement.

6. It will take a few minutes to install the SDK in our project

7. Get IoT device connect string from Azure IoT Hub…navigate to Azure Portal –> IOT Hub –> IOT Devices –> Select respective device to be connected.

  1. Using Microsoft.Azure.Devices.Client library we can create device client. The device client has CreateFromConnectionString method which requires device connection string as parameter. Create a read only static string s_connectionString01 and assign the connection string that we copy from Azure Portal.
  2. Here you can create a random temperature and humidity values using Random() method.
  3. Copy the code in the Program.cs from the GitHub repository

That’s it. Now, run the web application, go to Debug menu, and click on “Start without Debugging” or press F5. This will display the below result 

How To Send Telemetry From An IoT Device To The Azure IoT Hub Using C#

Hope you had learned a new approach to send telemetry data to Azure IOT Hub…stay tuned…for more on Azure IOT….

Hope this helps….

Cheers,

PMDY

Using Client script to connect your device Azure IOT Hub

This post is to understand the Node.js code used to connect to Azure IOT Hub…the complete code can be found This post is just to explain in detail for beginners to understand this quickly.

Navigate to this link…https://azure-samples.github.io/raspberry-pi-web-simulator/

Now we will understand the code in the integrated console window as highlighted below…

So let’s understand each piece of it…

Firstly we need to understand about controlling the GPIO pins of the Raspberry PI…for high performance C language should be preferred language used but most developers are more comfortable with JS/Node…node.js is used.

So in order to read the pins, we should be using package require(‘wiring-pi’);

Next we will be requiring Azure IOT Device Client SDK’s to create a client for interaction with the Raspberry PI and to send messages

require(‘azure-iot-device’)

Based on the protocol being used, we need to import the respective package..

The following table provides the high-level recommendations for your choice of protocol:

ProtocolWhen you should choose this protocol
MQTT
MQTT over WebSocket
Use on all devices that do not require to connect multiple devices (each with its own per-device credentials) over the same TLS connection.
AMQP
AMQP over WebSocket
Use on field and cloud gateways to take advantage of connection multiplexing across devices.
HTTPSUse for devices that cannot support other protocols.

MQTT and AMQP are binary protocols, which result in more compact payloads than HTTPS, this sample uses MQTT Protocol for communication, hence below package is used

require(‘azure-iot-device-mqtt’).Mqtt;

For bme280-sensor, a Node.js I2C module for the Bosch BME280 Humidity, Barometric Pressure, Temperature Sensor, used below

require(‘bme280-sensor’);

Regarding the connection string, you can follow my previous post on getting this from Azure Portal, however there is also an alternative to use SDK’s

There is a function in azure-iot-device npm (IoT Hub Device SDK for Node.js) to generate device connection string:

import { ConnectionString as DeviceConnectionString } from "azure-iot-device";
const deviceConnectionString = DeviceConnectionString.createWithSharedAccessKey(hostName, device.deviceId, device.authentication.SymmetricKey.primaryKey);

You could also refer to full code here to see how Azure IoT Toolkit generates the device connection string.

The next part is the custom logic on sending messages based on the temperature sensor to Azure IOT Hub and switching on the LED based conditions which is completely based on the needs…

Hope this helps…

Cheers,

PMDY

Invalid subscription key error when connecting Azure cognitive services Face API

saurabh nijhawan's avatarSaurabh nijhawan's weblog

Recently during an integration scenario with D365 Field services in order to identify if the person making a change to the Customer asset is an employee or not we spinned up an Azure Face API service and on trying to connect it from an Azure function we were getting Invalid key exception.

We were using the Face API client library which defaults to west US endpoint of the service but our service was in EastUS.

Default endpoint:https://westus.api.cognitive.microsoft.com/face/v1.0/

The solution is to override the endpoint tohttps://eastus.api.cognitive.microsoft.com/face/v1.0/ which can be done by using another constructor of the FaceServiceClient class

FaceServiceAPIClient = new FaceServiceClient("Face API subscription key", "https://eastus.api.cognitive.microsoft.com/face/v1.0");

View original post

Power Apps – Canvas Apps – Unable to obtain access token for resource ‘https://gov.service.powerapps.us/’. A silent sign-in request was sent but no user is signed in. The cookies used to represent the user’s session were not sent in the request to Azure AD

Sachin Bansal's avatarBansal Blogs - Dynamics 365, PowerApps, Microsoft Flows, Power BI

Access1

Power Apps recently introduced sharing capabilities with Guest Users. Upon sharing users were not able to access app because of error “Unable to obtain access token for resource ‘https://gov.service.powerapps.us/’. A silent sign-in request was sent but no user is signed in. The cookies used to represent the user’s session were not sent in the request to Azure AD”.

As we were investigating this issue and reaching out to Microsoft support team, we came to know this is not just for Guest users and because of browser cookie settings. Make sure third-party cookies are not blocked and enabled. You can refer below steps to enable third party cookies:

Microsoft Edge:

  • Go to Settings from right side navigation

Access2

  • Click on Site Permissions in Left side navigation and select Cookies and site data

Access3

  • Make sure options are enabled and disabled as shown below

Access4Chrome:

  • Go to Settings from right side navigation

Access5

  • Expand Advanced…

View original post 42 more words

Log Canvas Power App telemetry data in Azure Application Insights | Power Apps

priyeshwagh777's avatarD365 Demystified

Here’s how you can register your Canvas Power App in your Azure’s Application Insights and log telemetry data into Azure.

Some basic info about what all you can see in Application Insights is –

  1. Count of Users who used the app
  2. Events logged, Sessions logged
  3. Device info
  4. Region info

It’s quite simple to set it up! Let’s take a look –

Registering in Application Insights in Azure

First, make sure you do have an Azure Subscription. Let’s look at how you can register an Application Insight record.

  1. Look for Application Insights in Azure in the search bar
  2. Then, among other records, you can register a new one which will identify with your Canvas Power App
  3. Review all that you entered and move ahead
  4. It’ll be deployed pretty quickly within a few minutes unlike some heavy Azure resources
  5. Upon completion, you can navigate to the resource and see the details

    Zoomed…

View original post 374 more words

{Advanced Customization Tip} Disable Advanced find for Non Admin users in Dynamics 365

deepeshsomani2013's avatarMSDYNAMICSBLOG BY DEEPESH

Requirement: In one of the recent queries that came across to me, Advanced find needed to be disabled for all the users in the Dynamics 365 except for System Administrator.

Solution: There are multiple possible solution one may think and apply. The best practice will be to try to convince the customer against such a customization and utilize Read privileges for restricting access to entities as needed on the basis of Security roles. However, if still there is client requirement like this we can achieve it as below:

1. Add Application ribbon under Client extensions in a solution and then open this solution in XRMToolbox, Ribbon Work bench 2016:

clip_image001

2. Add results_16 and results_32 png images as web resources and keep them ready as follows in the solution:

clip_image003

3. Add a new button into the application ribbon and give it label as Result and under command put the command name…

View original post 148 more words

Retrieve Multiple Plugin

Reblogged on ecellorscrm blog

muralikrishnasabbavarapublog's avatarMurali Sabbavarapu CRM Blog

Scenario:

  1. Users have organization level read access on Competitor entity in CRM.
  2. Competitor and system user entity have N:1 relationship and User lookup (Business Require) available in Competitor entity form

Have a requirement that the User should see “Competitor records” for which the respective user is tagged to and this should be applicable in all CRM areas (like  Advanced find, Lockups, Views…)

This can be achieved through Plug in with “RetrieveMultiple” message

Initially when the user logged in the system, he has access to all the Competitor records which are not tagged to him. (advanced find)

ret3

Below is the plugin code to achieve the above mentioned requirement.

public void Execute(IServiceProvider serviceProvider)

{

try

{

IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

if (context.Depth > 1)

return;

WhoAmIRequest whoReq = new WhoAmIRequest();// To know the user who logged in

WhoAmIResponse whoResp = (WhoAmIResponse)service.Execute(whoReq);

Guid userid…

View original post 229 more words

Plugin Execute Method- should be stateless|A deep insight

Hi All,

I was writing Plugins from long time, but this time i had a just a deeper insight into the exact code which we write and came to know that the Plugin’s execute method should be stateless as this code would cached and the same object would be called multiple times based on requirement to improve the CRM Performance.

CELEDON Partners had a great post about this from an architectural point of view can be found.

Hope this helps some one…

Cheers,

PMDY

Calculated & Roll up fields – Both sides of a coin

Today we would be discussing drawbacks in addition to advantages of using Rollup and Calculated fields which were in place from CRM 2015.

It is really good to know these when using these fields for your implementation, else later you might face serious problems caused by increased implementation costs.

So here we go,

Calculated Fields

Pros

  • Ability to populate a field with simple calculations based on other values and conditions on the form in a real time manner.   This alleviates the need for JavaScript in fairly straight forward scenarios such as adding days or months to a date, or adding or subtracting fields on the same entity.

Cons

  • Missing the kind of complexity you get from Excel formulas
    • Example:  There is no “MAX” function that you can use with dates to get the max of more than one datetime field.
  • Updates to these fields won’t trigger workflow updates
  • Fields are only available for retrieve in plugins and are not available as part of create or update plugins
  • Fields are virtual and not stored at the database level
  • Many times they are un-sortable in views unless you use all simple field types in your calculation
  • Not available offline with the Outlook Client
  • You cannot mix and/or statements.  Can only use all OR’s or all AND’s

Rollup Fields

Pros

  • Allows aggregation of data from related child entities up to a parent entity.  This allows for some aggregation scenarios that might have previously required the use of custom code in workflow, plugin, or complex JavaScript to be done much more easily.
    • Counts, Max, Min, and Sum
  • Stored in the database as an actual field
  • You can trigger this via the API in code manually and as an administrator you can postpone rollup calculations from settings.

Cons

  •  Not real time
    • Currently the default is every 12 hours by default.
    • Not good for on-demand reporting needs
  • Rollup re-calculations will not trigger a modify call at the platform level and there is no other good plugin hook to use besides registering a plugin on the related child entities that are part of the recalculation.

Let us wait if Microsoft brings some changes to avoid these limitations..

Cheers,

PMDY