After having some problems with my Netduino 3 wifi Azure Event Hub client code (which are most probably due to the issues discussed here) I decided to have a look at AMQPNetLite which had been suggested by Paolo Patierno in a response to one of my posts in the Netduino forums.
I usually create a “minimalist” project so I can figure out how a new library works without an domain specific code getting in the way. Overall, my first experience was pretty positive, the code compiled first time, ran second time and worked third time.
The objective for my first AMQPNetLite application running on my Netduino 3 Wifi was to connect to my home wifi, wait for an IP address then upload an event to an Azure EventHub
private const int amqpPortNumber = 5671; private const string sbNamespace = "ServiceBus Namespace"; private const string keyName = "SaS Key name"; private const string keyValue = "SaS Key value"; private const string eventHub = "EventHub name"; ... // Wait for Network address if DHCP NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0]; if (networkInterface.IsDhcpEnabled) { Debug.Print(" Waiting for IP address "); while (NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress == IPAddress.Any.ToString()) { Debug.Print("."); } } // Display network config for debugging Debug.Print("Network configuration"); Debug.Print(" Network interface type: " + networkInterface.NetworkInterfaceType.ToString()); Debug.Print(" MAC Address: " + BytesToHexString(networkInterface.PhysicalAddress)); Debug.Print(" DHCP enabled: " + networkInterface.IsDhcpEnabled.ToString()); Debug.Print(" Dynamic DNS enabled: " + networkInterface.IsDynamicDnsEnabled.ToString()); Debug.Print(" IP Address: " + networkInterface.IPAddress.ToString()); Debug.Print(" Subnet Mask: " + networkInterface.SubnetMask.ToString()); Debug.Print(" Gateway: " + networkInterface.GatewayAddress.ToString()); foreach (string dnsAddress in networkInterface.DnsAddresses) { Debug.Print(" DNS Server: " + dnsAddress.ToString()); } string deviceId = BytesToHexString(networkInterface.PhysicalAddress); Debug.Print("DeviceId " + deviceId.ToString());
Then I constructed the AMQP address for the event hub, started an AMQP session and sent the message. I tried sending a message with a JSON payload and also using the “type safe” application properties.
try { Address address = new Address(sbNamespace, amqpPortNumber, keyName, keyValue); Connection connection = new Connection(address); Session session = new Session(connection); SenderLink sender = new SenderLink(session, "send-link", eventHub); string messageBody = @"{""DeviceId"":""" + deviceId + @""",""Time"":""" + DateTime.Now.ToString("yy-MM-dd hh:mm:ss") + @"""}"; Message message = new Message() { //BodySection = new Data() { Binary = Encoding.UTF8.GetBytes(messageBody)}, ApplicationProperties = new Amqp.Framing.ApplicationProperties(), }; message.ApplicationProperties["Time"] = DateTime.Now; message.ApplicationProperties["DeviceId"] = deviceId; sender.Send(message); sender.Close(); session.Close(); connection.Close(); } catch (Exception ex) { Debug.Print("ERROR: Publish failed with error: " + ex.Message); }
For my scenario I was pleasantly surprised how easy it was to get working.
AMQP has a non TLS option (only for non sensitive data) and if this is supported I could use a device like a Netduino 3 Ethernet which don’t have baked in TLS support.
Pingback: My first AzureSBLite program | devMobile's blog
Did you have to modify or extend the Event Hub? Or should this also work with any existing Event Hub, already accessible by the Nuget package for Azure Service Bus?
Hi,
Works well with Azure ServiceBus queues & event hubs. I used it (+AzureSBLite) in my recent MS Ignite NZ presentation running on .NetMF Netduino 3 Wifi & Windows 10 IoT Core RPI devices
For AMQPNetLite I use the GitHub source rather than the nuget package as it is a little bit more current.
Have some new posts about an AMQPNetLite based field gateway coming.
@KiwiBryn
Hi
I’ve just started using Netduino N3 Wifi, trying to connect to Azure IOT hub.
Is your sample code above still working? I tried it and it fails with a SSL authentication error. I even tried it by setting the Connection.DisableServerCertValidation = true. No luck…
I scoured the internet and came across old posts (2015) discussing the Netduino SSL problem and it looks like it still not solved.
There is a mention of a SSL issue that still needs to be fixed in Wilderness Labs TinyCLR Github repository.
I know this is an old post, but your help shall be much appreciated.
Thanks and regards.
Hi
Last time I checked the issues hadn’t been fixed.
I used reflector to drill down through the .NetMF C# code to C interface and then hit the wall. I think the config of the TI Wifi module needs tweaking.
I built a Windows10IoTCore based field gateway so I could connect my N3X devices to Azure IoT Hubs (AdaFruit.IO as well)
https://www.hackster.io/KiwiBryn/azure-iot-hub-nrf24l01-windows-10-iot-core-field-gateway-b70917
@KiwiBryn
Thank @KiwiBryn.
Its really sad because the Netduino N3 Wifi is otherwise quite a nice device.
Did you inform Wilderness about your hunch? From reading their issue log it looks like they are simply waiting for outside help. This might just get them going again?
Looks like the gateway is the way to go for now. Thanks a lot for the link.
Regards
Heinrich
Hi
I’ll give them a nudge again….
Have a look at AdaFruit.IO (https://io.adafruit.com/) it’s free for hobbyists USD10 a month for “professional” works pretty well.
If your application is “hobbyist” I have an AdaFruit.IO Netduino3Wifi client (https://blog.devmobile.co.nz/2018/01/03/adafruit-io-basic-netduino-http-client/) and nRF24L01 FieldGateway in pipeline just need to do blog post.
Sensors around my house (https://io.adafruit.com/BrynHLewis/dashboards/home-environment)
@KiwiBryn
I’ll definitely have a look at AdaFruit.IO. Thanks for the info. The application is ‘hobbyist”.
Thanks also for considering giving Wilderness a nudge 🙂
Regards
Heinrich
Looks like good news. I just installed a beta of their latest firmware and I am now able to access the Azure IOT hub from Netduino (without the need for added certificates etc).
https://community.wildernesslabs.co/t/beta-of-netduino-3-wifi-firmware-version-4-3-2-4/653/3
It is quite possible the problem is now finally sorted. For IOT I’m using the [azure-iot-sdk-csharp] which includes client source code for NetMF 4.3.
Hi
I’ll download the latest binaries to one of my N3Ws and see if my nasty certificate test harness can get to the Azure https endpoint.
If that works i’ll try the AMQPs connectivity.
@KiwiBryn
Good, lets see!