static void Main() { RF24 radio = new RF24(); byte messageCount = System.Byte.MaxValue; try { radio.OnDataReceived += Radio_OnDataReceived; radio.OnTransmitFailed += Radio_OnTransmitFailed; radio.OnTransmitSuccess += Radio_OnTransmitSuccess; #if NETDUINO3_WIFI radio.Initialize("SPI2", PinNumber('A', 2), PinNumber('A', 1), PinNumber('A', 3)); #endif radio.Address = Encoding.UTF8.GetBytes(DeviceAddress); radio.Channel = 15; //radio.PowerLevel = PowerLevel.Max; //radio.PowerLevel = PowerLevel.High; //radio.PowerLevel = PowerLevel.Low; radio.PowerLevel = PowerLevel.Minimum; radio.DataRate = DataRate.DR250Kbps; //radio.DataRate = DataRate.DR1Mbps; //radio.DataRate = DataRate.DR2Mbps; radio.IsEnabled = true; radio.IsAutoAcknowledge = true; radio.IsDyanmicAcknowledge = false; radio.IsDynamicPayload = true; Debug.WriteLine($"Address: {Encoding.UTF8.GetString(radio.Address, 0, radio.Address.Length)}"); Debug.WriteLine($"PowerLevel: {radio.PowerLevel}"); Debug.WriteLine($"IsAutoAcknowledge: {radio.IsAutoAcknowledge}"); Debug.WriteLine($"Channel: {radio.Channel}"); Debug.WriteLine($"DataRate: {radio.DataRate}"); Debug.WriteLine($"IsDynamicAcknowledge: {radio.IsDyanmicAcknowledge}"); Debug.WriteLine($"IsDynamicPayload: {radio.IsDynamicPayload}"); Debug.WriteLine($"IsEnabled: {radio.IsEnabled}"); Debug.WriteLine($"Frequency: {radio.Frequency}"); Debug.WriteLine($"IsInitialized: {radio.IsInitialized}"); Debug.WriteLine($"IsPowered: {radio.IsPowered}"); while (true) { string payload = $"hello {messageCount}"; messageCount -= 1; Debug.WriteLine($"{DateTime.UtcNow:HH:mm:ss}-TX {payload.Length} byte message {payload}"); radio.SendTo(Encoding.UTF8.GetBytes(BaseStationAddress), Encoding.UTF8.GetBytes(payload)); Thread.Sleep(30000); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public MeadowApp() { try { var config = new Meadow.Hardware.SpiClockConfiguration(2000, SpiClockConfiguration.Mode.Mode0); ISpiBus spiBus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config); Radio.OnDataReceived += Radio_OnDataReceived; Radio.OnTransmitFailed += Radio_OnTransmitFailed; Radio.OnTransmitSuccess += Radio_OnTransmitSuccess; Radio.Initialize(Device, spiBus, Device.Pins.D09, Device.Pins.D10, Device.Pins.D11); Radio.Address = Encoding.UTF8.GetBytes(DeviceAddress); Radio.Channel = nRF24Channel; Radio.PowerLevel = PowerLevel.High; Radio.DataRate = DataRate.DR250Kbps; Radio.IsEnabled = true; Radio.IsAutoAcknowledge = true; Radio.IsDyanmicAcknowledge = false; Radio.IsDynamicPayload = true; Console.WriteLine($"Address: {Encoding.UTF8.GetString(Radio.Address)}"); Console.WriteLine($"Channel: {Radio.Channel}"); Console.WriteLine($"Frequency: {Radio.Frequency}"); Console.WriteLine($"PowerLevel: {Radio.PowerLevel}"); Console.WriteLine($"DataRate: {Radio.DataRate}"); Console.WriteLine($"IsEnabled: {Radio.IsEnabled}"); Console.WriteLine($"IsAutoAcknowledge: {Radio.IsAutoAcknowledge}"); Console.WriteLine($"IsDynamicAcknowledge: {Radio.IsDyanmicAcknowledge}"); Console.WriteLine($"IsDynamicPayload: {Radio.IsDynamicPayload}"); Console.WriteLine($"IsInitialized: {Radio.IsInitialized}"); Console.WriteLine($"IsPowered: {Radio.IsPowered}"); while (true) { string payload = "hello " + DateTime.Now.ToShortTimeString(); Console.WriteLine($"{DateTime.UtcNow:HH:mm:ss}-TX {payload.Length} byte message {payload}"); Radio.SendTo(Encoding.UTF8.GetBytes(BaseStationAddress), Encoding.UTF8.GetBytes(payload)); Task.Delay(10000).Wait(); } } catch (Exception ex) { Console.WriteLine(ex.Message); return; } }
void SendMessageTimer1(ThreadPoolTimer timer) { Radio1.SendTo(Encoding.UTF8.GetBytes(DeviceAddress1), Encoding.UTF8.GetBytes("hello from 1" + DateTime.Now.Second)); }
public MeadowClient() { Led = new Led(Device, Device.Pins.OnboardLedGreen); try { sensor = new Sht31D(Device.CreateI2cBus()); var config = new Meadow.Hardware.SpiClockConfiguration( 2000, SpiClockConfiguration.Mode.Mode0); ISpiBus spiBus = Device.CreateSpiBus( Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config); Radio.OnDataReceived += Radio_OnDataReceived; Radio.OnTransmitFailed += Radio_OnTransmitFailed; Radio.OnTransmitSuccess += Radio_OnTransmitSuccess; Radio.Initialize(Device, spiBus, Device.Pins.D09, Device.Pins.D10, Device.Pins.D11); Radio.Address = Encoding.UTF8.GetBytes(DeviceAddress); Radio.Channel = nRF24Channel; Radio.PowerLevel = PowerLevel.Low; Radio.DataRate = DataRate.DR250Kbps; Radio.IsEnabled = true; Radio.IsAutoAcknowledge = true; Radio.IsDyanmicAcknowledge = false; Radio.IsDynamicPayload = true; Console.WriteLine($"Address: {Encoding.UTF8.GetString(Radio.Address)}"); Console.WriteLine($"PowerLevel: {Radio.PowerLevel}"); Console.WriteLine($"IsAutoAcknowledge: {Radio.IsAutoAcknowledge}"); Console.WriteLine($"Channel: {Radio.Channel}"); Console.WriteLine($"DataRate: {Radio.DataRate}"); Console.WriteLine($"IsDynamicAcknowledge: {Radio.IsDyanmicAcknowledge}"); Console.WriteLine($"IsDynamicPayload: {Radio.IsDynamicPayload}"); Console.WriteLine($"IsEnabled: {Radio.IsEnabled}"); Console.WriteLine($"Frequency: {Radio.Frequency}"); Console.WriteLine($"IsInitialized: {Radio.IsInitialized}"); Console.WriteLine($"IsPowered: {Radio.IsPowered}"); } 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}%"); Led.IsOn = true; string values = "T " + sensor.Temperature.ToString("F1") + ",H " + sensor.Humidity.ToString("F0"); // Stuff the 2 byte header ( payload type & deviceIdentifierLength ) + deviceIdentifier into payload byte[] payload = new byte[1 + Radio.Address.Length + values.Length]; payload[0] = (byte)((1 << 4) | Radio.Address.Length); Array.Copy(Radio.Address, 0, payload, 1, Radio.Address.Length); Encoding.UTF8.GetBytes(values, 0, values.Length, payload, Radio.Address.Length + 1); Radio.SendTo(Encoding.UTF8.GetBytes(BaseStationAddress), payload); Thread.Sleep(periodTime); } }
void SendMessageTimer(ThreadPoolTimer timer) { const string DeviceAddress = "Dev01"; Radio.SendTo(Encoding.UTF8.GetBytes(DeviceAddress), Encoding.UTF8.GetBytes("hello " + DateTime.Now.Second)); }