예제 #1
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            rfm9XDevice.Initialise(Frequency, paBoost: true, rxPayloadCrcOn: true);
#if DEBUG
            rfm9XDevice.RegisterDump();
#endif

            rfm9XDevice.OnReceive += Rfm9XDevice_OnReceive;
#if ADDRESSED_MESSAGES_PAYLOAD
            rfm9XDevice.Receive(UTF8Encoding.UTF8.GetBytes(Environment.MachineName));
#else
            rfm9XDevice.Receive();
#endif
            rfm9XDevice.OnTransmit += Rfm9XDevice_OnTransmit;

            Task.Delay(10000).Wait();

            while (true)
            {
                string messageText = string.Format("Hello from {0} ! {1}", Environment.MachineName, MessageCount);
                MessageCount -= 1;

                byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                Debug.WriteLine("{0:HH:mm:ss}-TX {1} byte message {2}", DateTime.Now, messageBytes.Length, messageText);
#if ADDRESSED_MESSAGES_PAYLOAD
                this.rfm9XDevice.Send(UTF8Encoding.UTF8.GetBytes("AddressHere"), messageBytes);
#else
                this.rfm9XDevice.Send(messageBytes);
#endif
                Task.Delay(10000).Wait();
            }
        }
예제 #2
0
        public static void Main()
        {
            Rfm9XDevice rfm9XDevice  = new Rfm9XDevice(SPI_Devices.SPI1, Pins.GPIO_PIN_D10, Pins.GPIO_PIN_D9, Pins.GPIO_PIN_D2);
            byte        MessageCount = Byte.MinValue;

            rfm9XDevice.Initialise(frequency: 915000000, paBoost: true, rxPayloadCrcOn: true);
#if ADDRESSED_MESSAGES_PAYLOAD
            rfm9XDevice.Receive(Encoding.UTF8.GetBytes("Netduino"));
#else
            rfm9XDevice.Receive();
#endif
            rfm9XDevice.OnDataReceived += rfm9XDevice_OnDataReceived;
            rfm9XDevice.OnTransmit     += rfm9XDevice_OnTransmit;

            while (true)
            {
                string messageText = "Hello NetMF LoRa! " + MessageCount.ToString();
                MessageCount += 1;
                byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                Debug.Print("Sending " + messageBytes.Length + " bytes message " + messageText);

#if ADDRESSED_MESSAGES_PAYLOAD
                rfm9XDevice.Send(UTF8Encoding.UTF8.GetBytes("LoRaIoT1"), messageBytes);
#else
                rfm9XDevice.Send(messageBytes);
#endif
                Thread.Sleep(10000);
            }
        }
예제 #3
0
        static void Main()
        {
#if TINYCLR_V2_SC20100DEV_MIKROBUS_1 || TINYCLR_V2_SC20100DEV_MIKROBUS_2
            const string DeviceName = "SC20100DEVLoRa";
#endif
#if TINYCLR_V2_FEZDUINO
            const string DeviceName = "FezduinoLoRa";
#endif
#if TINYCLR_V2_FEZPORTAL
            const string DeviceName = "FezportalLoRa";
#endif
#if ADDRESSED_MESSAGES_PAYLOAD
            const string HostName = "LoRaIoT1";
#endif
            const double Frequency    = 915000000.0;
            byte         MessageCount = System.Byte.MaxValue;
#if TINYCLR_V2_SC20100DEV_MIKROBUS_1
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SC20100.SpiBus.Spi3, SC20100.GpioPin.PD3, SC20100.GpioPin.PD4, SC20100.GpioPin.PC5);
#endif
#if TINYCLR_V2_SC20100DEV_MIKROBUS_2
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SC20100.SpiBus.Spi3, SC20100.GpioPin.PD14, SC20100.GpioPin.PD15, SC20100.GpioPin.PA8);
#endif
#if TINYCLR_V2_FEZDUINO
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SC20100.SpiBus.Spi6, SC20100.GpioPin.PB1, SC20100.GpioPin.PA15, SC20100.GpioPin.PA1);
#endif
#if TINYCLR_V2_FEZPORTAL
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SC20100.SpiBus.Spi3, SC20100.GpioPin.PC13, SC20100.GpioPin.PD4, SC20100.GpioPin.PC2);
#endif

            rfm9XDevice.Initialise(Frequency, paBoost: true, rxPayloadCrcOn: true);
#if DEBUG
            rfm9XDevice.RegisterDump();
#endif

            rfm9XDevice.OnReceive += Rfm9XDevice_OnReceive;
#if ADDRESSED_MESSAGES_PAYLOAD
            rfm9XDevice.Receive(UTF8Encoding.UTF8.GetBytes(DeviceName));
#else
            rfm9XDevice.Receive();
#endif
            rfm9XDevice.OnTransmit += Rfm9XDevice_OnTransmit;

            Thread.Sleep(10000);

            while (true)
            {
                string messageText = string.Format("Hello from {0} ! {1}", DeviceName, MessageCount);
                MessageCount -= 1;

                byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                Debug.WriteLine($"{DateTime.Now:HH:mm:ss}-TX {messageBytes.Length} byte message {messageText}");
#if ADDRESSED_MESSAGES_PAYLOAD
                rfm9XDevice.Send(UTF8Encoding.UTF8.GetBytes(HostName), messageBytes);
#else
                rfm9XDevice.Send(messageBytes);
#endif
                Thread.Sleep(10000);
            }
        }
예제 #4
0
        static void Main()
        {
            byte MessageCount        = System.Byte.MaxValue;
            int  chipSelectPinNumber = Gpio.IO16;
            int  interruptPinNumber  = Gpio.IO26;

            Configuration.SetPinFunction(Gpio.IO12, DeviceFunction.SPI1_MISO);
            Configuration.SetPinFunction(Gpio.IO13, DeviceFunction.SPI1_MOSI);
            Configuration.SetPinFunction(Gpio.IO14, DeviceFunction.SPI1_CLOCK);

            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SpiBusId, chipSelectPinNumber, interruptPinNumber);

            Debug.WriteLine("devMobile.IoT.Rfm9x.LoRaDeviceClient starting");

            rfm9XDevice.Initialise(Frequency, paBoost: true);

            rfm9XDevice.OnReceive += Rfm9XDevice_OnReceive;
            rfm9XDevice.Receive();
            rfm9XDevice.OnTransmit += Rfm9XDevice_OnTransmit;

            Thread.Sleep(10000);

            while (true)
            {
                string messageText = $"Hello from {DeviceName} ! {MessageCount}";
                MessageCount -= 1;

                byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                Debug.WriteLine($"{DateTime.UtcNow:hh:mm:ss}-TX {messageBytes.Length} byte message {messageText}");
                rfm9XDevice.Send(messageBytes);
                Thread.Sleep(10000);
            }
        }
예제 #5
0
        static void Main()
        {
            //const string DeviceName = "FEZLoRa";
            //const string HostName = "LoRaIoT1";
            const string DeviceName = "LoRaIoT1";

#if ADDRESSED_MESSAGES_PAYLOAD
            const string HostName = "LoRaIoT2";
#endif
            const double Frequency    = 915000000.0;
            byte         MessageCount = System.Byte.MaxValue;
            Rfm9XDevice  rfm9XDevice  = new Rfm9XDevice(FEZ.GpioPin.D10, FEZ.GpioPin.D9, FEZ.GpioPin.D2);

            rfm9XDevice.Initialise(Frequency, paBoost: true, rxPayloadCrcOn: true);
#if DEBUG
            rfm9XDevice.RegisterDump();
#endif

            rfm9XDevice.OnReceive += Rfm9XDevice_OnReceive;
#if ADDRESSED_MESSAGES_PAYLOAD
            rfm9XDevice.Receive(UTF8Encoding.UTF8.GetBytes(DeviceName));
#else
            rfm9XDevice.Receive();
#endif
            rfm9XDevice.OnTransmit += Rfm9XDevice_OnTransmit;

            Thread.Sleep(10000);

            while (true)
            {
                string messageText = string.Format("Hello from {0} ! {1}", DeviceName, MessageCount);
                MessageCount -= 1;

                byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                Debug.WriteLine($"{DateTime.Now:HH:mm:ss}-TX {messageBytes.Length} byte message {messageText}");
#if ADDRESSED_MESSAGES_PAYLOAD
                rfm9XDevice.Send(UTF8Encoding.UTF8.GetBytes(HostName), messageBytes);
#else
                rfm9XDevice.Send(messageBytes);
#endif
                Thread.Sleep(10000);
            }
        }
        public void Run()
        {
            rfm9XDevice.Initialise(frequency: Frequency, paBoost: true, rxPayloadCrcOn: true);
            rfm9XDevice.Receive(deviceAddress);
            rfm9XDevice.OnReceive  += Rfm9XDevice_OnReceive;
            rfm9XDevice.OnTransmit += Rfm9XDevice_OnTransmit;

            Timer humidityAndtemperatureUpdates = new Timer(HumidityAndTemperatureTimerProc, null, dueTime, periodTime);

            Thread.Sleep(Timeout.Infinite);
        }
예제 #7
0
        static void initRadio(SSD1306Driver oledScreen)
        {
            //Set LoRa Pins
            byte MessageCount        = System.Byte.MaxValue;
            int  chipSelectPinNumber = Gpio.IO18;
            int  interruptPinNumber  = Gpio.IO26;
            int  resetPinNumber      = Gpio.IO14;

            Configuration.SetPinFunction(Gpio.IO19, DeviceFunction.SPI1_MISO);
            Configuration.SetPinFunction(Gpio.IO27, DeviceFunction.SPI1_MOSI);
            Configuration.SetPinFunction(Gpio.IO05, DeviceFunction.SPI1_CLOCK);

            //Initialize Modem - BEEEEEEEEEEEEEEEEEEEEEEP.......BUUUUUUUUUUUUUUUUUUUUUR....................WEEEEDOOOOWEEEEEDOOO.................SKRRRRRRRRRRRRRRRRRR
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SpiBusId, chipSelectPinNumber, resetPinNumber, interruptPinNumber);

            oledScreen.DrawString(0, 20, "Success.......");
            oledScreen.RefreshDisplay();
            rfm9XDevice.Initialise(Frequency, paBoost: true);
            oledScreen.DrawString(0, 30, "Powering Radio On.......");
            oledScreen.RefreshDisplay();
            rfm9XDevice.OnReceive += Rfm9XDevice_OnReceive;
            rfm9XDevice.Receive();
            rfm9XDevice.OnTransmit += Rfm9XDevice_OnTransmit;

            //LED INIT - Not required, just gave me something to see in my peripheral so I did not have to read the OLED all the time
            GpioController gpioc = new GpioController();
            GpioPin        led   = gpioc.OpenPin(OnBoardDevicePortNumber.Led, PinMode.Output);

            led.Write(PinValue.High);

            Thread.Sleep(5000); //Too fast and we reset

            int count = 0;

            while (true) //Send a message and update the OLED
            {
                string messageText = $"Hello from {DeviceName} ! {MessageCount}";
                MessageCount -= 1;
                count++;
                oledScreen.Clear();
                oledScreen.DrawString(0, 0, "Transmitting....");
                oledScreen.DrawString(0, 10, "Messages Sent: " + count.ToString());
                oledScreen.RefreshDisplay();
                byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                Debug.WriteLine($"{DateTime.UtcNow:hh:mm:ss}-TX {messageBytes.Length} byte message {messageText}");
                rfm9XDevice.Send(messageBytes);
                Thread.Sleep(1000);
                led.Toggle();
            }
        }
예제 #8
0
        public MeadowClient()
        {
            Led = new Led(Device, Device.Pins.OnboardLedGreen);

            try
            {
                sensor = new Sht31D(Device.CreateI2cBus());

                ISpiBus spiBus = Device.CreateSpiBus(500);

                rfm9XDevice = new Rfm9XDevice(Device, spiBus, Device.Pins.D09, Device.Pins.D10, Device.Pins.D12);

                rfm9XDevice.Initialise(Frequency, paBoost: true, rxPayloadCrcOn: true);
#if DEBUG
                rfm9XDevice.RegisterDump();
#endif
                rfm9XDevice.OnReceive += Rfm9XDevice_OnReceive;
                rfm9XDevice.Receive(deviceAddress);
                rfm9XDevice.OnTransmit += Rfm9XDevice_OnTransmit;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            while (true)
            {
                sensor.Update();

                Console.WriteLine($"{DateTime.UtcNow:HH:mm:ss}-TX T:{sensor.Temperature:0.0}C H:{sensor.Humidity:0}%");

                string payload = $"t {sensor.Temperature:0.0},h {sensor.Humidity:0}";

                Led.IsOn = true;

                rfm9XDevice.Send(fieldGatewayAddress, Encoding.UTF8.GetBytes(payload));

                Thread.Sleep(periodTime);
            }
        }
예제 #9
0
        static void Main()
        {
            byte MessageCount = System.Byte.MaxValue;

#if ST_STM32F429I_DISCOVERY
            int chipSelectPinNumber = PinNumber('C', 2);
            int resetPinNumber      = PinNumber('C', 3);
            int interruptPinNumber  = PinNumber('A', 4);
#endif
#if ESP32_WROOM_32_LORA_1_CHANNEL
            int chipSelectPinNumber = Gpio.IO16;
            int interruptPinNumber  = Gpio.IO26;

            Configuration.SetPinFunction(Gpio.IO12, DeviceFunction.SPI1_MISO);
            Configuration.SetPinFunction(Gpio.IO13, DeviceFunction.SPI1_MOSI);
            Configuration.SetPinFunction(Gpio.IO14, DeviceFunction.SPI1_CLOCK);

            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SpiBusId, chipSelectPinNumber, interruptPinNumber);
#endif
#if NETDUINO3_WIFI
            // Arduino D10->PB10
            int chipSelectPinNumber = PinNumber('B', 10);
            // Arduino D9->PE5
            int resetPinNumber = PinNumber('E', 5);
            // Arduino D2->PA3
            int interruptPinNumber = PinNumber('A', 3);
#endif
            Debug.WriteLine("devMobile.IoT.Rfm9x.LoRaDeviceClient starting");

#if ST_STM32F429I_DISCOVERY || NETDUINO3_WIFI
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SpiBusId, chipSelectPinNumber, resetPinNumber, interruptPinNumber);
#endif
            rfm9XDevice.Initialise(Frequency, paBoost: true);

#if DEBUG
            rfm9XDevice.RegisterDump();
#endif

            rfm9XDevice.OnReceive += Rfm9XDevice_OnReceive;
#if ADDRESSED_MESSAGES_PAYLOAD
            rfm9XDevice.Receive(UTF8Encoding.UTF8.GetBytes(DeviceName));
#else
            rfm9XDevice.Receive();
#endif
            rfm9XDevice.OnTransmit += Rfm9XDevice_OnTransmit;

            Thread.Sleep(10000);

            while (true)
            {
                string messageText = $"Hello from {DeviceName} ! {MessageCount}";
                MessageCount -= 1;

                byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                Debug.WriteLine($"{DateTime.UtcNow:hh:mm:ss}-TX {messageBytes.Length} byte message {messageText}");
#if ADDRESSED_MESSAGES_PAYLOAD
                rfm9XDevice.Send(UTF8Encoding.UTF8.GetBytes(HostName), messageBytes);
#else
                rfm9XDevice.Send(messageBytes);
#endif
                Thread.Sleep(10000);
            }
        }
예제 #10
0
        static void Main()
        {
            byte MessageCount = System.Byte.MaxValue;

#if ST_STM32F429I_DISCOVERY
            int ledPinNumber        = PinNumber('G', 14);
            int chipSelectPinNumber = PinNumber('C', 2);
            int resetPinNumber      = PinNumber('C', 3);
            int interruptPinNumber  = PinNumber('A', 4);
#endif
#if ESP32_WROOM_32_LORA_1_CHANNEL
            int ledPinNumber        = Gpio.IO17;
            int chipSelectPinNumber = Gpio.IO16;
            int interruptPinNumber  = Gpio.IO26;

            Configuration.SetPinFunction(Gpio.IO12, DeviceFunction.SPI1_MISO);
            Configuration.SetPinFunction(Gpio.IO13, DeviceFunction.SPI1_MOSI);
            Configuration.SetPinFunction(Gpio.IO14, DeviceFunction.SPI1_CLOCK);

            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SpiBusId, chipSelectPinNumber, interruptPinNumber);
#endif
#if NETDUINO3_WIFI
            int ledPinNumber = PinNumber('A', 10);
            // Arduino D10->PB10
            int chipSelectPinNumber = PinNumber('B', 10);
            // Arduino D9->PE5
            int resetPinNumber = PinNumber('E', 5);
            // Arduino D2->PA3
            int interruptPinNumber = PinNumber('A', 3);
#endif
            Debug.WriteLine("devMobile.IoT.Rfm9x.LoRaDeviceClient starting");

            GpioController gpioController = GpioController.GetDefault();

            led = gpioController.OpenPin(ledPinNumber);
            led.SetDriveMode(GpioPinDriveMode.Output);
            led.Write(GpioPinValue.Low);

#if ST_STM32F429I_DISCOVERY || NETDUINO3_WIFI
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SpiBusId, chipSelectPinNumber, resetPinNumber, interruptPinNumber);
#endif
            rfm9XDevice.Initialise(Frequency
                                   , rxPayloadCrcOn: true
                                   );

#if DEBUG
            rfm9XDevice.RegisterDump();
#endif

            rfm9XDevice.OnReceive += Rfm9XDevice_OnReceive;
#if ADDRESSED_MESSAGES_PAYLOAD
            rfm9XDevice.Receive(UTF8Encoding.UTF8.GetBytes(DeviceName));
#else
            rfm9XDevice.Receive();
#endif
            rfm9XDevice.OnTransmit += Rfm9XDevice_OnTransmit;

            Thread.Sleep(10000);

            while (true)
            {
                string messageText = string.Format("Hello from {0} ! {1}", DeviceName, MessageCount);
                MessageCount -= 1;

                byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                Debug.WriteLine(string.Format("{0}-TX {1} byte message {2}", DateTime.UtcNow.ToString("HH:mm:ss"), messageBytes.Length, messageText));
#if ADDRESSED_MESSAGES_PAYLOAD
                rfm9XDevice.Send(UTF8Encoding.UTF8.GetBytes(HostName), messageBytes);
#else
                rfm9XDevice.Send(messageBytes);
#endif
                Thread.Sleep(10000);
            }
        }
예제 #11
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            StorageFolder localFolder = ApplicationData.Current.LocalFolder;

            try
            {
                // see if the configuration file is present if not copy minimal sample one from application directory
                if (localFolder.TryGetItemAsync(ConfigurationFilename).AsTask().Result == null)
                {
                    StorageFile templateConfigurationfile = Package.Current.InstalledLocation.GetFileAsync(ConfigurationFilename).AsTask().Result;
                    templateConfigurationfile.CopyAsync(localFolder, ConfigurationFilename).AsTask();
                }

                // Load the settings from configuration file exit application if missing or invalid
                StorageFile file = localFolder.GetFileAsync(ConfigurationFilename).AsTask().Result;

                applicationSettings = (JsonConvert.DeserializeObject <ApplicationSettings>(FileIO.ReadTextAsync(file).AsTask().Result));
            }
            catch (Exception ex)
            {
                this.logging.LogMessage("JSON configuration file load failed " + ex.Message, LoggingLevel.Error);
                return;
            }

            // Log the Application build, shield information etc.
            LoggingFields applicationBuildInformation = new LoggingFields();

#if DRAGINO
            applicationBuildInformation.AddString("Shield", "DraginoLoRaGPSHat");
#endif
#if ELECROW
            applicationBuildInformation.AddString("Shield", "ElecrowRFM95IoTBoard");
#endif
#if M2M
            applicationBuildInformation.AddString("Shield", "M2M1ChannelLoRaWanGatewayShield");
#endif
#if ELECTRONIC_TRICKS
            applicationBuildInformation.AddString("Shield", "ElectronicTricksLoRaLoRaWANShield");
#endif
#if UPUTRONICS_RPIZERO_CS0
            applicationBuildInformation.AddString("Shield", "UputronicsPiZeroLoRaExpansionBoardCS0");
#endif
#if UPUTRONICS_RPIZERO_CS1
            applicationBuildInformation.AddString("Shield", "UputronicsPiZeroLoRaExpansionBoardCS1");
#endif
#if UPUTRONICS_RPIPLUS_CS0
            applicationBuildInformation.AddString("Shield", "UputronicsPiPlusLoRaExpansionBoardCS0");
#endif
#if UPUTRONICS_RPIPLUS_CS1
            applicationBuildInformation.AddString("Shield", "UputronicsPiPlusLoRaExpansionBoardCS1");
#endif
#if ADAFRUIT_RADIO_BONNET
            applicationBuildInformation.AddString("Shield", "AdafruitRadioBonnet");
#endif
#if CLOUD_DEVICE_BOND
            applicationBuildInformation.AddString("Bond", "Supported");
#else
            applicationBuildInformation.AddString("Bond", "NotSupported");
#endif
#if CLOUD_DEVICE_PUSH
            applicationBuildInformation.AddString("Push", "Supported");
#else
            applicationBuildInformation.AddString("Push", "NotSupported");
#endif
#if CLOUD_DEVICE_SEND
            applicationBuildInformation.AddString("Send", "Supported");
#else
            applicationBuildInformation.AddString("Send", "NotSupported");
#endif
#if PAYLOAD_TEXT
            applicationBuildInformation.AddString("PayloadProcessor", "Text");
#endif
#if PAYLOAD_TEXT_COMA_SEPARATED_VALUES
            applicationBuildInformation.AddString("PayloadProcessor", "ComaSeperatedValues");
#endif
#if PAYLOAD_BINARY_BINARY_CODED_DECIMAL
            applicationBuildInformation.AddString("PayloadProcessor", "BinaryCodedDecimal");
#endif
#if PAYLOAD_BINARY_CAYENNE_LOW_POWER_PAYLOAD
            applicationBuildInformation.AddString("PayloadProcessor", "CayenneLowPowerPayload");
#endif

            applicationBuildInformation.AddString("Timezone", TimeZoneSettings.CurrentTimeZoneDisplayName);
            applicationBuildInformation.AddString("OSVersion", Environment.OSVersion.VersionString);
            applicationBuildInformation.AddString("MachineName", Environment.MachineName);

            // This is from the application manifest
            Package        package   = Package.Current;
            PackageId      packageId = package.Id;
            PackageVersion version   = packageId.Version;

            applicationBuildInformation.AddString("ApplicationVersion", string.Format($"{version.Major}.{version.Minor}.{version.Build}.{version.Revision}"));
            this.logging.LogEvent("Application starting", applicationBuildInformation, LoggingLevel.Information);

            try
            {
#if DRAGINO
                rfm9XDevice = new Rfm9XDevice(ChipSelectPin.CS0, ChipSelectLine, ResetLine, InterruptLine);
#endif
#if M2M
                rfm9XDevice = new Rfm9XDevice(ChipSelectPin.CS0, ChipSelectLine, ResetLine, InterruptLine);
#endif
#if ELECROW
                rfm9XDevice = new Rfm9XDevice(ChipSelectPin.CS1, ResetLine, InterruptLine);
#endif
#if ELECTRONIC_TRICKS
                rfm9XDevice = new Rfm9XDevice(ChipSelectPin.CS0, ResetLine, InterruptLine);
#endif
#if UPUTRONICS_RPIZERO_CS0
                rfm9XDevice = new Rfm9XDevice(ChipSelectPin.CS0, InterruptLine);
#endif
#if UPUTRONICS_RPIZERO_CS1
                rfm9XDevice = new Rfm9XDevice(ChipSelectPin.CS1, InterruptLine);
#endif
#if UPUTRONICS_RPIPLUS_CS0
                rfm9XDevice = new Rfm9XDevice(ChipSelectPin.CS0, InterruptLine);
#endif
#if UPUTRONICS_RPIPLUS_CS1
                rfm9XDevice = new Rfm9XDevice(ChipSelectPin.CS1, InterruptLine);
#endif
#if ADAFRUIT_RADIO_BONNET
                rfm9XDevice = new Rfm9XDevice(ChipSelectPin.CS1, ResetLine, InterruptLine);
#endif
            }
            catch (Exception ex)
            {
                this.logging.LogMessage("Hardware initialisation failed " + ex.Message, LoggingLevel.Error);
                return;
            }

            // Log the Azure connection string and associated settings
            LoggingFields azureIoTHubSettings = new LoggingFields();
            azureIoTHubSettings.AddString("DeviceConnectionString", this.applicationSettings.AzureIoTHubDeviceConnectionString);
            azureIoTHubSettings.AddString("TransportType", this.applicationSettings.AzureIoTHubTransportType.ToString());
            azureIoTHubSettings.AddString("SensorIDIsDeviceIDSensorID", this.applicationSettings.SensorIDIsDeviceIDSensorID.ToString());
            this.logging.LogEvent("AzureIoTHub configuration", azureIoTHubSettings, LoggingLevel.Information);

            // Connect the IoT hub first so we are ready for any messages
            try
            {
                this.azureIoTHubClient = DeviceClient.CreateFromConnectionString(this.applicationSettings.AzureIoTHubDeviceConnectionString, this.applicationSettings.AzureIoTHubTransportType);
            }
            catch (Exception ex)
            {
                this.logging.LogMessage("IoT Hub connection failed " + ex.Message, LoggingLevel.Error);
                return;
            }

            try
            {
                TwinCollection reportedProperties;
                reportedProperties = new TwinCollection();

                // This is from the OS
                reportedProperties["Timezone"]    = TimeZoneSettings.CurrentTimeZoneDisplayName;
                reportedProperties["OSVersion"]   = Environment.OSVersion.VersionString;
                reportedProperties["MachineName"] = Environment.MachineName;

                reportedProperties["ApplicationDisplayName"] = package.DisplayName;
                reportedProperties["ApplicationName"]        = packageId.Name;
                reportedProperties["ApplicationVersion"]     = string.Format($"{version.Major}.{version.Minor}.{version.Build}.{version.Revision}");

                // Unique identifier from the hardware
                SystemIdentificationInfo systemIdentificationInfo = SystemIdentification.GetSystemIdForPublisher();
                using (DataReader reader = DataReader.FromBuffer(systemIdentificationInfo.Id))
                {
                    byte[] bytes = new byte[systemIdentificationInfo.Id.Length];
                    reader.ReadBytes(bytes);
                    reportedProperties["SystemId"] = BitConverter.ToString(bytes);
                }

                azureIoTHubClient.UpdateReportedPropertiesAsync(reportedProperties).Wait();
            }
            catch (Exception ex)
            {
                this.logging.LogMessage("IoT Hub updating reported properties failed " + ex.Message, LoggingLevel.Error);
            }

            // Wire up the field gateway restart method handler
            try
            {
                azureIoTHubClient.SetMethodHandlerAsync("Restart", RestartAsync, null);
            }
            catch (Exception ex)
            {
                this.logging.LogMessage("Azure IoT Hub Restart method handler setup failed " + ex.Message, LoggingLevel.Error);
                return;
            }

#if CLOUD_DEVICE_BOND
            // Wire up the bond device method handler
            try
            {
                azureIoTHubClient.SetMethodHandlerAsync("DeviceBond", this.DeviceBondAsync, null);
            }
            catch (Exception ex)
            {
                this.logging.LogMessage("Azure IoT Hub Device Bond method handler setup failed " + ex.Message, LoggingLevel.Error);
                return;
            }
#endif

#if CLOUD_DEVICE_PUSH
            // Wire up the push message to device method handler
            try
            {
                this.azureIoTHubClient.SetMethodHandlerAsync("DevicePush", this.DevicePushAsync, null);
            }
            catch (Exception ex)
            {
                this.logging.LogMessage("Azure IoT Hub DevicePush method handler setup failed " + ex.Message, LoggingLevel.Error);
                return;
            }
#endif

#if CLOUD_DEVICE_SEND
            // Wire up the send message to device method handler
            try
            {
                this.azureIoTHubClient.SetMethodHandlerAsync("DeviceSend", this.DeviceSendAsync, null);
            }
            catch (Exception ex)
            {
                this.logging.LogMessage("Azure IoT Hub client DeviceSend method handler setup failed " + ex.Message, LoggingLevel.Error);
                return;
            }
#endif

            // Configure the LoRa module
            rfm9XDevice.OnReceive  += Rfm9XDevice_OnReceive;
            rfm9XDevice.OnTransmit += Rfm9XDevice_OnTransmit;

            rfm9XDevice.Initialise(this.applicationSettings.Frequency,
                                   rxDoneignoreIfCrcMissing: true,
                                   rxDoneignoreIfCrcInvalid: true,
                                   paBoost: this.applicationSettings.PABoost, maxPower: this.applicationSettings.MaxPower, outputPower: this.applicationSettings.OutputPower,
                                   ocpOn: this.applicationSettings.OCPOn, ocpTrim: this.applicationSettings.OCPTrim,
                                   lnaGain: this.applicationSettings.LnaGain, lnaBoost: this.applicationSettings.LNABoost,
                                   bandwidth: this.applicationSettings.Bandwidth, codingRate: this.applicationSettings.CodingRate, implicitHeaderModeOn: this.applicationSettings.ImplicitHeaderModeOn,
                                   spreadingFactor: this.applicationSettings.SpreadingFactor,
                                   rxPayloadCrcOn: true,
                                   symbolTimeout: this.applicationSettings.SymbolTimeout,
                                   preambleLength: this.applicationSettings.PreambleLength,
                                   payloadLength: this.applicationSettings.PayloadLength,
                                   payloadMaxLength: this.applicationSettings.PayloadMaxLength,
                                   freqHoppingPeriod: this.applicationSettings.FreqHoppingPeriod,
                                   lowDataRateOptimize: this.applicationSettings.LowDataRateOptimize,
                                   ppmCorrection: this.applicationSettings.PpmCorrection,
                                   detectionOptimize: this.applicationSettings.DetectionOptimize,
                                   invertIQ: this.applicationSettings.InvertIQ,
                                   detectionThreshold: this.applicationSettings.DetectionThreshold,
                                   syncWord: this.applicationSettings.SyncWord
                                   );

#if DEBUG
            rfm9XDevice.RegisterDump();
#endif

            rfm9XDevice.Receive(Encoding.UTF8.GetBytes(this.applicationSettings.Address));

            LoggingFields loRaSettings = new LoggingFields();
            loRaSettings.AddString("Address", this.applicationSettings.Address);
            loRaSettings.AddDouble("Frequency", this.applicationSettings.Frequency);
            loRaSettings.AddBoolean("PABoost", this.applicationSettings.PABoost);

            loRaSettings.AddUInt8("MaxPower", this.applicationSettings.MaxPower);
            loRaSettings.AddUInt8("OutputPower", this.applicationSettings.OutputPower);
            loRaSettings.AddBoolean("OCPOn", this.applicationSettings.OCPOn);
            loRaSettings.AddUInt8("OCPTrim", this.applicationSettings.OCPTrim);

            loRaSettings.AddString("LnaGain", this.applicationSettings.LnaGain.ToString());
            loRaSettings.AddBoolean("lnaBoost", this.applicationSettings.LNABoost);

            loRaSettings.AddString("codingRate", this.applicationSettings.CodingRate.ToString());
            loRaSettings.AddString("implicitHeaderModeOn", applicationSettings.ImplicitHeaderModeOn.ToString());
            loRaSettings.AddString("spreadingFactor", this.applicationSettings.SpreadingFactor.ToString());
            loRaSettings.AddBoolean("rxPayloadCrcOn", true);

            loRaSettings.AddUInt8("symbolTimeout", this.applicationSettings.SymbolTimeout);
            loRaSettings.AddUInt8("preambleLength", this.applicationSettings.PreambleLength);
            loRaSettings.AddUInt8("payloadLength", this.applicationSettings.PayloadLength);

            loRaSettings.AddUInt8("payloadMaxLength", this.applicationSettings.PayloadMaxLength);
            loRaSettings.AddUInt8("freqHoppingPeriod", this.applicationSettings.FreqHoppingPeriod);
            loRaSettings.AddBoolean("lowDataRateOptimize", this.applicationSettings.LowDataRateOptimize);
            loRaSettings.AddUInt8("ppmCorrection", this.applicationSettings.PpmCorrection);

            loRaSettings.AddString("detectionOptimize", this.applicationSettings.DetectionOptimize.ToString());
            loRaSettings.AddBoolean("invertIQ", this.applicationSettings.InvertIQ);
            loRaSettings.AddString("detectionThreshold", this.applicationSettings.DetectionThreshold.ToString());
            loRaSettings.AddUInt8("SyncWord", this.applicationSettings.SyncWord);

            this.logging.LogEvent("LoRa configuration", loRaSettings, LoggingLevel.Information);

            this.deferral = taskInstance.GetDeferral();
        }