Can the Edge Driver read from the Certificate file?

Hi there. I’m writing an Awair Edge Device Driver with MQTT capabilities. It connects to the server on port 8883 SSL so it requires a certificate. I have successfully tested the connection using an IDE (Zerobrane) and the message went through.
However, when I actually used the same code in the driver, I got the very basic error “MQTT client error: failed to open network connection: luasocket connect failed: socket.connect failed: host or service not provided, or not known”. Thus, I was wondering if somehow the driver was not reading from the certificate (I did create a client with reference to the certificate file).

The files in the package look like this and I’m referencing the certificate file like that:
image

Of course as always, I welcome any new ideas and approaches. Thank you very much in advance.

Hi, @sleepdeprived!

I checked your question with the engineering team and they mentioned the following:

  1. Currently, the Edge driver implementation only supports .pem certificates
  2. Checking the Awair website, they describe their local API as a REST API. Their MQTT API goes to an Awair cloud service.
    a. This is an important point because, if you’re trying to connect to Awair’s cloud, the driver won’t work because they don’t support access to the public Internet. Edge Drivers can only talk to devices on their local network.

Hey there @nayelyz
Thank you very much for the reply and clarification. On the second note, the Awair local API has nothing to do with the MQTT as it stands in my case. The plan is to pull the Awair data via a local API call and decode it and emit the events. Then, record the states and if they change by a specific amount, encode the new data into a json string and send it to the MQTT broker as a payload message.
On the first note, I have gone ahead and convert the .crt into .pem. However, it threw a 504 Gateway time out error when I tried to install the new package into the device. I wonder if you might know what’s going on?

Never mind, I can install the driver now. However, I still got the luasocket connection error.

Is it possible for you to share your code with us so the engineering team can take a look, please?
You can send a zip file to build@smartthings.com

Hi, Haru.

I’m replying here for other people’s reference.
I asked the team to check the code and they found this:

uri = "<omitted>.cloudapp.azure.com",

This means you’re trying to connect to a Cloud service that I mentioned here that wasn’t available for drivers.

About your statement here, the team mentioned that the MQTT connection still needs to use a TCP socket at some point under the hood, and, DNS resolution is not implemented in the ST Lua libraries either.
So, you’re passing a Cloud direction directly to the TCP socket and that’s why the connection is not successful. What we meant before with “Edge Drivers can only talk to devices on their local network”, was “sockets can only open connections to IP addresses that are on the private LAN/in the private address spaces”. For example:

10.0.0.0 -> 10.255.255.255,
172.16.0.0 -> 172.31.255.255
192.168.0.0 -> 192.168.255.255

If you want to use a .local URI for convenience, you’ll need to use the st.mdns package and its APIs to do hostname resolution on the local network.
Another option is to have some kind of proxy outside the Hub (but in your local network) and make the driver point to it.

I see how it is. Thank you very much Nayelyz. I have one more question though, would it be possible with SmartApps? I think I saw somewhere that SmartApps worked with Node Red and it’s also a cloud service.

It could be possible but they are not currently available in the Developer Workspace, please, follow this thread: