Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with IoT Hub #1

Open
ikivela opened this issue Nov 11, 2022 · 11 comments
Open

Problem with IoT Hub #1

ikivela opened this issue Nov 11, 2022 · 11 comments

Comments

@ikivela
Copy link

ikivela commented Nov 11, 2022

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
Copy link
Owner

KiwiBryn commented Nov 11, 2022

@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
Copy link
Owner

@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
Copy link
Owner

@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
Copy link
Owner

@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
Copy link
Author

ikivela commented Nov 14, 2022

@KiwiBryn thanks for debugging

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

@KiwiBryn
Copy link
Owner

KiwiBryn commented Nov 14, 2022 via email

@ikivela
Copy link
Author

ikivela commented Nov 16, 2022

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
Copy link
Owner

@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
Copy link
Author

ikivela commented Nov 17, 2022

@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
Copy link
Owner

@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
Copy link
Owner

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants