IoT Edge on Raspberry Pi - using GPIO Driver - iot

Using VScode I have taken the led-blink sample code from https://github.com/dotnet/iot and placed it into an IotEdge module template with the intention of having it run in a container on IoT edge and then use device twin properties to modify some of the variables on the fly through IoT Hub. After loading the module it starts ups but the logs show the following error
Unhandled exception. System.IO.IOException: Error 2 initializing the Gpio driver.
at System.Device.Gpio.Drivers.RaspberryPi3LinuxDriver.Initialize()
at System.Device.Gpio.Drivers.RaspberryPi3LinuxDriver.OpenPin(Int32 pinNumber)
at System.Device.Gpio.Drivers.RaspberryPi3Driver.OpenPin(Int32 pinNumber)
at System.Device.Gpio.GpioController.OpenPin(Int32 pinNumber)
at edgetestmodule20sep.Program.Main(String[] args) in /app/Program.cs:line 29
Can anyone advise what is going on here and what a possible solution might be?

Related

Error in Azure IoT Edge runtime - A module runtime error occurred

iotedge list command error
Hi,
On running the iotedge list command it is throwing - A module runtime error occurred. Is there something missed. It was working fine till yesterday.
If you are still blocked, you can check the below information.
There could be multiple reasons for the module runtime error on IoT Edge.
Was it working earlier and stopped suddenly? As Matthijs mentioned in
the comments, collect complete logs to know more about the issue.
Refer Gather debug information with 'support-bundle' command
Also, check Azure IoT Edge security manager logs. The IoT Edge
security manager is responsible for operations like initializing the
IoT Edge system at startup and provisioning devices. If IoT Edge
isn't starting, the security manager logs may provide useful
information.
Make sure that the module is properly configured and all
required environment variables are set.
If the issue still persists, you can try restarting the module or the
entire IoT Edge device to see if that resolves the issue.
You can also check Solutions to common issues for Azure IoT Edge for most common errors and solutions.

How to set up SSL certificates for containerized EventHubs message processors?

I've been writing an EventHubs message processor that just connects to EventHubs and processes messages on the EventHub. I've been developing in Visual Studio on Windows using .NET 6. Things work as expected on Windows; I can:
Connect to EventHubs
Receive messages
Do the message processing I want
Great. I then wanted to scale my message processor horizontally and decided that I would Dockerize it, and since .NET 6 runs on Linux, I would cross-compile it for Linux and eventually deploy multiple instances of my message processor on Docker Desktop as a next step. I eventually want to stick it on Kubernetes to scale up by an order of magnitude or two.
It was easy to Dockerize my Project in Visual Studio. I simply right-clicked the Project and selected Add -> Docker Support. Visual Studio detected I had Docker Desktop installed and generated all the config files I needed, and added an appropriate build configuration so that I could compile a binary, build a Docker image with it, and automatically deploy it to my local Docker Desktop instance.
.NET 6 also compiled without errors, which was great. However, when my container spins up, I get hit with the following runtime error:
System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: PartialChain
and there is a stack trace (omitted here for brevity) stemming from something in the EventHubs processor library:
<...many layers...> at Azure.Messaging.EventHubs.Primitives.EventProcessor-1.RunProcessingAsync(CancellationToken cancellationToken)
I am correctly passing my EventHubs connection string to my container, but what I surmise is that my container is missing an SSL certificate or has a misconfigured SSL certificate. I suppose Visual Studio has helpfully silently gone ahead and installed a development certificate when I developed my message processor on Windows so that EventHubs connections "just work" in my development environment, but that SSL certificate is not available to my container, since it isn't part of the build output.
I know I probably should be using Azure key vault or whatever secret management service they provide, but how else can I resolve this SSL certificate issue as quickly or painlessly as possible? It would be nice if I can just keep my connection string in my appsettings.json (It's fine. Toy project, only using Azure free credits anyway.)
The easiest way forward would be to register a handler that participates in certificate validation and can, if desired, override normal handling and force acceptance. This, of course, comes with the warning that you're bypassing standard security checks and may be putting your network and host in danger.
You don't mention which client you're using, but each takes a set of options in their constructor. The options for each type have a member named ConnectionOptions which returns an EventHubsConnectionOptions instance that allows you to register a CertificateValidationCallback.
The Event Hubs Influencing SSL certificate validation sample demonstrates how to use it. More information is also available in the .NET documentation for RemoteCertificateValidationCallback.

Using DevTools features with Selenium Grid on Docker

I managed to work with DevTools features in Selenium 4 locally, but when I tried to use it on Selenium Grid, it didn't work.
In order to investigate it, I installed a local grid with one Chrome node using docker-compose and I got the same error:
OpenQA.Selenium.WebDriverException : Unexpected error creating WebSocket DevTools session.
----> System.Net.WebSockets.WebSocketException : Unable to connect to the remote server
----> System.Net.Http.HttpRequestException : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (172.18.0.3:4444)
----> System.Net.Sockets.SocketException : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Where 172.18.0.3 is the private IP of chrome-node container.
I guess that the main reason is that I don't have access to that IP from the host, and that's probably a docker configuration matter, on which I'm not an expert. But that wasn't the only problem.
Using the debugger, I was able to track that the driver tries to use this address due to the following capability that is returned from the driver after creation: "se:cdp": "ws://172.18.0.3:4444/session/2c519f679e1060cdc926ca74e63e222f/se/cdp". I then tweaked this value (in the debugger, before trying to create the connection to the DevTools protocol) to use localhost instead of the private IP, and then I got the following error: IOException: The response ended prematurely..
What do I need to do in order to use the DevTools features of Selenium through Selenium Grid (and docker)?
Adding - SE_NODE_GRID_URL=http://localhost:4444/ environment to the "chrome" container in the docker-compose yaml file solves the problem.
If you want to access the grid from outside of the host, instead of localhost write the IP or name of the machine.

How to debug edgeHub module in Azure IoT Edge

is there anyway to trace the messaging flow in edgeHub?
i have two modules that connect sensors (the opc-ua publisher) and a coap proxy and i am routing them to the cloud with
"all2hub": "FROM /messages/* INTO $upstream"
That works fine and I can see the telemetry from both devices
If i add another module that does nothing but writes to the console every message it receives with
"all2test": "FROM /messages/* INTO BrokeredEndpoint(\"/modules/tester/inputs/test\")"
I don't get a single message coming to the test module...I wonder if I could trace and see what is happening....
You can enable debug logs for edgeHub by adding RuntimeLogLevel environment variable with value debug to the deployment (from the portal go to Set modules -> Configured advanced Edge runtime settings)
Another way to enable debug logs is by updating the IoT Edge security manager config file
Replace env: {} with
env:
RuntimeLogLevel: debug
Save the file and restart the IoT Edge security manager.
With debug logs enavled you should check edgeHub logs if messages are received and sent.

How to protect ConnectionStrings in Azure IoT Edge module code?

Typing the connection string in the configuration file (as shown in the official example: https://github.com/Azure-Samples/iot-edge-samples/blob/master/js/simple/gw.cloud.config.json#L38) doesn't seem right.
Environment variables may be provided to the modules by the Edge Runtime (https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/iot-edge/iot-edge-runtime.md) but as far as I can see there is no way to modify its behaviour.
In the first document(https://github.com/Azure-Samples/iot-edge-samples/blob/master/js/simple/gw.cloud.config.json#L38), it shows how to customize the IoT Edge runtime (gw.[local|cloud].config.json). You can update gw.cloud.config.json by replacing <IoT Hub device connection string> with your actual IoT Hub device connection string to establish connection between IoT Edge application and Azure IoT Hub.
In the next document(https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/iot-edge/iot-edge-runtime.md), you can also configure the IoT Edge runtime by executing the following command.You will find the connection string setting in C:\ProgramData\azure-iot-edge\config\config.json.
iotedgectl setup --connection-string "{device connection string}" --nopass

Resources