Back in August 2022 I posted .NET nanoFramework RAK3172 Library Usage on my blog about how to use the RAK3172LoRaWAN-NetNF library with a STM32F7 Discovery/Sparkfun Thing Plus ESP32 WROOM and RAK3172 Breakout Board.
In my .NET nanoFramework and RAK WisBlock sensors Hackster project I had documented how to get the.NET nanoFramework running on a RAKwireless RAK11200 wisBlock WiFi Core Module/RAK2305 WiFi Espressif ESP32 Wireless Modules and read a selection of sensors.
The WisBlock Core is usually the processing unit of an IoT solution but none of the devices can run the .NET nanoFramework and LoRaWAN connectivity simultaneously.
Normally, the WisBlock Core would run a custom application which uses Wisblock Wireless and Wisblock Sensor modules. e.g. a RAK3373 Core module could use a RAK2305 Wireless module to connect to a Wireless Access Point.
I then realised "If the RAK3372 Core module can control a RAK2305 Wireless module then maybe a RAK2305 Wireless module can control a RAK3372 Core module"
The first step was to mount the RAK3372 Core, and RAK2305 Wireless modules on a RAK5005-O base board.
Then load the .NET nanoFramework runtime with nanoff
The RUI3 Serial operating modes indicated that the RAK3172 should be able process AT Commands on the Serial and Serial2 ports.
The nanoFramework uses TXD0 and RXD0 (for flashing & debugging etc.), so only TXD1(IO17) and RXD1(IO16) were available.
The RAK2305 TXD1 and RXD1 are connected to PIN34 and PIN33 on the BTB40_M Connector. The RAK2305 module is then plugged into the BTB40_F IO Extension Slot on the RAK5005.
The RAK5005 TXD1 is connected to PIN33, and RXD1 to PIN34 on the BTB40_F connector. The RAK5005 TXD1 is connected to PIN 33, and RXD1 to PIN34 on the CPU Slot BTB40_F connector (TX/RX cross over here). The RAK3372 in plugged into the BTB40_F socket on the RAK5005.
The RAK3372 TXD1 is connected to PIN33, and RXD1 to PIN34 on the BTB40_M connector. (The TXD1 and RXD1 labels are incorrect in the RAK3372 schematic).
I then used the BreakOutSerial application to confirm connectivity.
public static void Main()
{
Debug.WriteLine("devMobile.IoT.LoRaWAN.nanoFramework.RAK3172 BreakoutSerial starting");
try
{
// set GPIO functions for COM2 (this is UART1 on ESP32)
Configuration.SetPinFunction(Gpio.IO21, DeviceFunction.COM2_TX);
Configuration.SetPinFunction(Gpio.IO19, DeviceFunction.COM2_RX);
Debug.Write("Ports:");
foreach (string port in SerialPort.GetPortNames())
{
Debug.Write($" {port}");
}
Debug.WriteLine("");
using (_SerialPort = new SerialPort(SerialPortId))
{
// set parameters
_SerialPort.BaudRate = 115200;
_SerialPort.Parity = Parity.None;
_SerialPort.DataBits = 8;
_SerialPort.StopBits = StopBits.One;
_SerialPort.Handshake = Handshake.None;
_SerialPort.NewLine = "\r\n";
_SerialPort.ReadTimeout = 1000;
//_SerialPort.WatchChar = '\n'; // May 2022 WatchChar event didn't fire github issue https://github.com/nanoframework/Home/issues/1035
_SerialPort.DataReceived += SerialDevice_DataReceived;
_SerialPort.Open();
_SerialPort.WatchChar = '\n';
_SerialPort.ReadExisting(); // Running at 115K2 this was necessary
for (int i = 0; i < 5; i++)
{
string atCommand;
atCommand = "AT+VER=?";
//atCommand = "AT+SN=?"; // Empty response?
//atCommand = "AT+HWMODEL=?";
//atCommand = "AT+HWID=?";
//atCommand = "AT+DEVEUI=?";
//atCommand = "AT+APPEUI=?";
//atCommand = "AT+APPKEY=?";
//atCommand = "ATR";
//atCommand = "AT+SLEEP=4000";
//atCommand = "AT+ATM";
//atCommand = "AT+NWM=1";
//atCommand = "AT?";
//atCommand = "+++";
Debug.WriteLine("");
Debug.WriteLine($"{DateTime.UtcNow:hh:mm:ss} {i} TX:{atCommand} bytes:{atCommand.Length}--------------------------------");
_SerialPort.WriteLine(atCommand);
Thread.Sleep(5000);
}
}
Debug.WriteLine("Done");
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
private static void SerialDevice_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort serialPort = (SerialPort)sender;
switch (e.EventType)
{
case SerialData.Chars:
break;
case SerialData.WatchChar:
string response = serialPort.ReadExisting();
//Debug.Write($"{DateTime.UtcNow:hh:mm:ss} RX:{response} bytes:{response.Length}");
Debug.Write(response);
break;
default:
Debug.Assert(false, $"e.EventType {e.EventType} unknown");
break;
}
}
}
}
I then configured the DevEUI, JoinEUI and AppKey in config.cs of the RAK3172LoRaWANDeviceClient application.
namespace devMobile.IoT.LoRaWAN
{
public class Config
{
#if DEVEUI_SET
public const string devEui = "...";
#endif
#if OTAA
public const string JoinEui = "...";
public const string AppKey = "..."
//public const string AppKey = "03C06FBFC2F3B396DE07ECF09404F6FE";
#endif
#if ABP
public const string DevAddress = "...";
public const string NwksKey = "...";
public const string AppsKey = "...";
#endif
}
}
The features supported by RAK3172LoRaWANDeviceClient are configured with a series of compile time directives.
//#define ST_STM32F769I_DISCOVERY // nanoff --target ST_STM32F769I_DISCOVERY --update
//#define SPARKFUN_ESP32_THING_PLUS // nanoff --platform esp32 --serialport COM4 --update
#define RAK_WISBLOCK_RAK2305 // nanoff --update --platform esp32 --serialport COM4
//#define DEVICE_DEVEUI_SET
//#define FACTORY_RESET
//#define PAYLOAD_BCD
#define PAYLOAD_BYTES
//#define OTAA
//#define ABP
//#define CONFIRMED
//#define UNCONFIRMED
//#define REGION_SET
//#define ADR_SET
//#define SLEEP
The SendMessageTimer is started when the network join successful. The RAK3172LoRaWANDeviceClient application then sends a message every time SendMessageTimerCallback is called.
After sometime spent reviewing the schematics the RAK3372, Wisblock Base and RAK2305/RAK19007 combination running the .NET nanoFramwork worked. The RAK5005 with its built-in solar battery charging (other base modules also have this functionality) and additional WisBlock modules would be a good platform for "proof of concept" LoRaWAN projects.
AddendaI'm not certain that a RAK4361 Core module running the default software will work.
In the RAK4361 theRUI3 Serial operating modes documentation AT Commands will only be processed on Serial(USB port) Serial1(TDX0/RXD0).
Comments
Please log in or sign up to comment.