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); } }
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); } }
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); } }
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); } }
private void HumidityAndTemperatureTimerProc(object state) { _led.Set(0, 128, 0); double humidity = sensor.Humidity(); double temperature = sensor.Temperature(); Debug.Print(DateTime.UtcNow.ToString("hh:mm:ss") + " H:" + humidity.ToString("F1") + " T:" + temperature.ToString("F1")); rfm9XDevice.Send(fieldGatewayAddress, Encoding.UTF8.GetBytes("t " + temperature.ToString("F1") + ",H " + humidity.ToString("F0"))); }
private void HumidityAndTemperatureTimerProc(object state) { double humidity = sensor.Humidity(); double temperature = sensor.Temperature(); Debug.WriteLine($"{DateTime.UtcNow:hh:mm:ss} TX-H:{humidity:F0}% T:{temperature:F1}°"); rfm9XDevice.Send(fieldGatewayAddress, Encoding.UTF8.GetBytes($"T {temperature:F1},H {humidity:F0}")); led.Write(GpioPinValue.High); }
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(); } }
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); } }
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); } }
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); } }