Not Able to read from Configuration file in EdgeHub Triggered Edge Module

Satyam Chauhan 607 Reputation points
2022-12-27T10:40:22.017+00:00

Hi,

I have an Edge Module which is EdgeHub Triggered, and the .csproj file looks like -

The local.settings.json file consists of key value pairs, I want to use the config in the in-process azure function with Startup.cs file.
But it is returning the values as null every time. I tried to read it as environment variable but still it is giving null.

What could be a good way to add configuration file and read it from local environment as we will not be able to use device twin in our production environment.

Azure IoT Edge
Azure IoT Edge
An Azure service that is used to deploy cloud workloads to run on internet of things (IoT) edge devices via standard containers.
599 questions
{count} votes

Accepted answer
  1. Sander van de Velde | MVP 36,766 Reputation points MVP Volunteer Moderator
    2023-01-13T23:05:00.7166667+00:00

    Hello Satyam Chauhan,

    you have created a custom Azure IoT Edge module but you do not want it to configure using C2D twin messages.

    Normally, if you want to manipulate an Azure IoT Edge module when it starts, you use Module twin desired properties. These are originally coming from the IoT Hub but the Edge Hub can hand them out also for offline scenarios.

    An alternative is using environment variables as seen in the generic configuration of docker containers. Using these environment variables is also supported in the Deployment manifest for each module.

    As seen in this C# example, modules can access these variables as regular environment variables:

    var variables = Environment.GetEnvironmentVariables();
    Console.WriteLine($"Found {variables.Count} Environment variables:");
    foreach (DictionaryEntry variable in variables)
    {  
      Console.WriteLine($"Environment variable '{variable.Key}': '{variable.Value}'");
    }
    

    Remember, if you use this and you want to change a variable, you need to deploy a new version of the Deployment manifest.

    Potentially, this can have an impact on all other modules running on the same edge (eg. getting a new set of the same twins). Please double-check this potential behavior.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.