My next proof of concept uses a Weather click and nRF C click to upload temperature and humidity data to a Xively gateway running on a spare Netduino 2 Plus. I have a couple of Azure Event hub gateways (direct & queued) which require a Netduino 3 Wifi (for TLS/AMQPS support) and I’ll build a client for them in a coming post.
I initially purchased an nRF T click but something wasn’t quite right with its interrupt output. The interrupt line wasn’t getting pulled low at all so there were no send success/failure events. If I disabled the pull up resistor and strobed the interrupt pin on start-up the device would work for a while.
using (OutputPort Int = new OutputPort(socket.Int, true)) { Int.Write(true); }; ... _irqPin = new InterruptPort(socket.Int, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
The code sends a reading every 10 seconds and has been running for a couple of days. It strobes Led1 for each successful send and turns on Led2 when a send fails.
private static readonly byte[] deviceAddress = Encoding.UTF8.GetBytes("Quail"); private static readonly byte[] gatewayAddress = Encoding.UTF8.GetBytes("12345"); private const byte gatewayChannel = 10; private const NRFC.DataRate gatewayDataRate = NRFC.DataRate.DR1Mbps; private const int XivelyUpdateDelay = 10000; private const char XivelyGatewayChannelIdTemperature = 'J'; private const char XivelyGatewayChannelIdHumidity = 'K'; public static void Main() { NRFC nRF24Click = new NRFC(Hardware.SocketFour); nRF24Click.Configure(deviceAddress, gatewayChannel, gatewayDataRate); nRF24Click.OnTransmitFailed += nRF24Click_OnTransmitFailed; nRF24Click.OnTransmitSuccess += nRF24Click_OnTransmitSuccess; nRF24Click.Enable(); // Configure the weather click WeatherClick weatherClick = new WeatherClick(Hardware.SocketOne, WeatherClick.I2CAddresses.Address0); weatherClick.SetRecommendedMode(WeatherClick.RecommendedModes.WeatherMonitoring); Thread.Sleep(XivelyUpdateDelay); while (true) { string temperatureMessage = XivelyGatewayChannelIdTemperature + weatherClick.ReadTemperature().ToString("F1"); Debug.Print(temperatureMessage); MBN.Hardware.Led1.Write(true); nRF24Click.SendTo(gatewayAddress, Encoding.UTF8.GetBytes(temperatureMessage)); Thread.Sleep(XivelyUpdateDelay); string humidityMessage = XivelyGatewayChannelIdHumidity + weatherClick.ReadHumidity().ToString("F1"); Debug.Print(humidityMessage); MBN.Hardware.Led1.Write(true); nRF24Click.SendTo(gatewayAddress, Encoding.UTF8.GetBytes(humidityMessage)); Thread.Sleep(XivelyUpdateDelay); } } static void nRF24Click_OnTransmitSuccess() { MBN.Hardware.Led1.Write(false); if (MBN.Hardware.Led2.Read()) { MBN.Hardware.Led2.Write(false); } Debug.Print("nRF24Click_OnTransmitSuccess"); } static void nRF24Click_OnTransmitFailed() { MBN.Hardware.Led2.Write(true); Debug.Print("nRF24Click_OnTransmitFailed"); }
I need to have a look at interfacing some more sensors and soak testing the solution.
The MikroBus.Net team have done a great job with the number & quality of the drivers they have available.