KiwiBryn / TTIV3AzureIoTConnector

Slow rebuild of TTNV3 connector without MQTT, then Azure storage queues, lots of appsettings options, but with AzureKeyVault coming
1 stars 1 forks source link

Problem with IoT Hub #1

Open ikivela opened 1 year ago

ikivela commented 1 year ago

I have problem getting started...I tried to follow your hackster.io guide, created azure functions, iot hub, but ttn webhook receives error code 422.

I followed the logs from TTIV3WebHookAzureIoTHubIntegration1. It seems that there is no error, but connection to IoT Hub is broken? How can debug this?

2022-11-11T13:03:15.719 [Information] [13:03:15]info: Queued[0]
2022-11-11T13:03:15.719 [Information] Uplink-DeviceID:dragino1 ApplicationID:dragino Port:1
2022-11-11T13:03:15.720 [Information] Executed 'Functions.Uplink' (Succeeded, Id=675e144e-89b8-4fe3-be50-e3af029579f6, Duration=5ms)
2022-11-11T13:03:15.722 [Information] [13:03:15]warn: Queued[0]
2022-11-11T13:03:15.722 [Information] Uplink-DeviceID:dragino1 unknown IoT Hub Connect
KiwiBryn commented 1 year ago

@ikivela the usual reason for this sort of error message is that Azure IoT Hub device ids are case sensitive.

Double check DevceID "dragino1" in you IoT Hub

I also just noticed in the code this could occur if the Azure IoT Hub connection string "_azureIoTSettings.IoTHub.IoTHubConnectionString" was missing/invalid.

Will patch and test later this AM currently NZT (UTC+13)

@KiwiBryn

KiwiBryn commented 1 year ago

@ikivela

Ran code up in debugger, I'm caching the Azure IoT Hub DeviceClients and the failure is getting cached.

If you could look in the logging there should have been a failure the first time the LoRaWAN device uplinked. That will tell you what went wrong. In application Insights try searching

"no TTI Application settings configured" "no TTI API Key configured" "no TTI Webhook ID configured" "Application settings not configured" "Unknown DeviceID"

Most probably the last one.

I will have a think about to handle this better.

@KiwiBryn

KiwiBryn commented 1 year ago

@ikivela

Have a look at Stop-Caching-of-nulls-so-that-recovery-from-failure works branch.

I'm working the fix there need todo some more testing next couple of days then will release

@KiwiBryn

KiwiBryn commented 1 year ago

@ikivela

Fixes to uplink function checked in branch. Considering same approach for other functions

Will test some more. then merge back into master.

Also planning to do .NET 6 upgrade

Blog post at https://blog.devmobile.co.nz to follow about going back to application code (had been running reliably for ages and not touched it) after so long.

@KiwiBryn

ikivela commented 1 year ago

@KiwiBryn thanks for debugging

Did you already push another branch to git? I can't see it.

KiwiBryn commented 1 year ago

Hi

Pushed now, had forgotten

@@.***>

From: Ilkka Kivelä @.> Sent: Tuesday, 15 November 2022 12:22 AM To: KiwiBryn/TTIV3AzureIoTConnector @.> Cc: Bryn Lewis @.>; Mention @.> Subject: Re: [KiwiBryn/TTIV3AzureIoTConnector] Problem with IoT Hub (Issue #1)

@KiwiBrynhttps://github.com/KiwiBryn thanks for debugging

Did you already push another branch to git? I can't see it.

— Reply to this email directly, view it on GitHubhttps://github.com/KiwiBryn/TTIV3AzureIoTConnector/issues/1#issuecomment-1313527567, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADB7JOLZQA7JMY5REKRE5FLWIIOD3ANCNFSM6AAAAAAR5S7IOE. You are receiving this because you were mentioned.Message ID: @.**@.>>

ikivela commented 1 year ago

I found out that the problem is with this setting

Uplink-ApplicationID:scip IoTHub Application settings not configured

How this variable should be configured? There no explanation of it hackster guide.

KiwiBryn commented 1 year ago

@ikivela I'm assuming your settings file looks something like this

 "AzureIoT": {
    "DeviceClientCacheSlidingExpiration": "P2H30M",
    "IoTHub": {
      "IoTHubConnectionString": "HostName=tti...KQ=",
    }
}

If "scip" is is your TTN application id try adding

 "AzureIoT": {
    "DeviceClientCacheSlidingExpiration": "P2H30M",
    "IoTHub": {
      "IoTHubConnectionString": "HostName=tti...KQ=",
      "Applications": {
          "scip":{
             "DtdlModelId": ""
          },
       },
    },
}

It was added so a DTDL model ID could be configured for an application. Will make more "optional"

@KiwiBryn

ikivela commented 1 year ago

@KiwiBryn

Thanks for your help. The problem was that I didn't add variable DtdlModelId. After adding, it worked fine. image

I have to admit this was my first C# deployment ever, so it took a while figure out things...I.e. the lazycache was caching the device, and because of that I saw warnings only after restarting the function.

For wider adaptation, you could maybe write step-by-step guide. Anyway, thanks for publishing this repo!

KiwiBryn commented 1 year ago

@ikivela it's great you're up and running now.

The code was still evolving a bit after I wrote the Hackster post so not 100% upto date

I started writing a blog post but ran out of steam, should finish it

@KiwiBryn

KiwiBryn commented 1 year ago

@ikivela was just wondering how you were going?

Have done a .NET 6 upgrade so solution on an LTS version. This forced an upgrade to V4 functions runtime which I'm testing.

If my Uplink message processing is okay i'll do a merge then the .NET version updates

@KiwiBryn