M5Stack with Blue Lorawan Module

Hi

I’m trying to connect my M5stack to the network, but keep failing, the module uses AT commands, i have setup according to info in the web, is there anything i’m doing wrong in the setup ? I have Tried both OTTA and ABP, Thanks

Q

#include <M5Stack.h>

HardwareSerial Serial2(2);

String cmd_DEF = "AT+FDEFAULT";
String cmd_RESET = "AT+RESET";

//String cmd_OTTA_mode = "AT+MODE=LWOTAA";


String cmd_DevEui = "AT+ID=DevEui, \"47eabd4800370055\"";
String cmd_DevAddr = "AT+ID=DevAddr, \"07585E3D\"";
String cmd_NWKSKEY = "AT+KEY=NWKSKEY, \"2B7E151628AED2A6ABF7158809CF4F3C\"";
String cmd_APPSKEY = "AT+KEY=APPSKEY, \"2B7E151628AED2A6ABF7158809CF4F3C\"";

String cmd_BAND = "AT+DR=EU868";
String cmd_DR = "AT+DR=DR5";
String cmd_ADR = "AT+ADR=ON";

String cmd_rfconf_ch0D = "AT+CH=0, 0";
String cmd_rfconf_ch1D = "AT+CH=1, 0";
String cmd_rfconf_ch2D = "AT+CH=2, 0";
String cmd_rfconf_ch3D = "AT+CH=3, 0";
String cmd_rfconf_ch4D = "AT+CH=4, 0";
String cmd_rfconf_ch5D = "AT+CH=5, 0";
String cmd_rfconf_ch6D = "AT+CH=6, 0";

String cmd_rfconf_ch0 = "AT+CH=0, 868.1, DR0, DR5";
String cmd_rfconf_ch1 = "AT+CH=1, 868.3, DR0, DR5";
String cmd_rfconf_ch2 = "AT+CH=2, 868.5, DR0, DR5";
String cmd_rfconf_ch3 = "AT+CH=3, 867.1, DR0, DR5";
String cmd_rfconf_ch4 = "AT+CH=4, 867.3, DR0, DR5";
String cmd_rfconf_ch5 = "AT+CH=5, 867.5, DR0, DR5";
String cmd_rfconf_ch6 = "AT+CH=6, 867.7, DR0, DR5";

String cmd_CH = "AT+CH=NUM, 0-6";

String cmd_RX1 = "AT+RXWIN1=1,868.3";
String cmd_RX2 = "AT+RXWIN2=869.525,DR0";

String cmd_POW = "AT+POWER=14";
String cmd_JOIN = "AT+JOIN=FORCE";

String cmd_send_data = "AT+MSG=\"Data to send\"";

void setup() {
  
  M5.begin();
  Wire.begin();
  // Lcd display
  M5.Lcd.setBrightness(100);
  M5.Lcd.fillScreen(BLACK);
  M5.Lcd.setCursor(10, 10);
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.setTextSize(1);
  M5.Lcd.printf("LoraWAN Network");
  delay(300);
  M5.Lcd.fillScreen(BLACK);
  delay(150);
  M5.Lcd.setCursor(0, 10);
  M5.Lcd.fillScreen(BLACK);
  for(int i=0; i<200; i++) {
        M5.Lcd.setBrightness(i);
        delay(2);
  }
  
  
  Serial.begin(115200);
  
  // Serial2.begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert)
  Serial2.begin(9600, SERIAL_8N1, 16, 17);
  Serial2.flush();
  /* LoRaWAN Init */
  
  M5.Lcd.println("Setting up the LoraWAN Connetion");
  Serial2.println(cmd_DEF);
  Serial2.println(cmd_RESET);
  delay(1000);
  Serial2.println(cmd_DevEui);
  Serial2.println(cmd_DevAddr);
  Serial2.println(cmd_NWKSKEY);
  Serial2.println(cmd_APPSKEY);
  delay(1000);
  Serial2.println(cmd_BAND);
  Serial2.println(cmd_DR);
  Serial2.println(cmd_ADR);
  Serial2.println(cmd_rfconf_ch0D);
  Serial2.println(cmd_rfconf_ch1D);
  Serial2.println(cmd_rfconf_ch2D);
  Serial2.println(cmd_rfconf_ch3D);
  Serial2.println(cmd_rfconf_ch4D);
  Serial2.println(cmd_rfconf_ch5D);
  Serial2.println(cmd_rfconf_ch6D);
  Serial2.println(cmd_rfconf_ch0);
  Serial2.println(cmd_rfconf_ch1);
  Serial2.println(cmd_rfconf_ch2);
  Serial2.println(cmd_rfconf_ch4);
  Serial2.println(cmd_rfconf_ch5);
  Serial2.println(cmd_rfconf_ch6);
  Serial2.println(cmd_CH);
  Serial2.println(cmd_RX1);
  
  Serial2.println(cmd_RX2);
  Serial2.println(cmd_POW);
  delay(1000);
  M5.Lcd.println("Connecting to the LoraWAN Connetion");

  //Serial2.println(cmd_JOIN); // Only for OTTA
  //M5.Lcd.println("Sending Data.");
  Serial2.println(cmd_send_data);
  
}

void loop() {
  //Serial2.println(cmd_send_data);
  //delay(100);
  
  if(Serial.available()) {
    int ch = Serial.read();
    Serial2.write(ch);  
  }

  if(Serial2.available()) {
    int ch = Serial2.read();
    Serial.write(ch);
    //M5.Lcd.println(ch);
  }
}

This does not seem to be a valid TTN device address. The back-end will filter these messages.

2 Likes

Hi

I managed to get connected with the following.

Thanks

#include <M5Stack.h>

HardwareSerial Serial2(2);

int period = 158000;
unsigned long time_now = 0;

String cmd_DEF = "AT+FDEFAULT";
String cmd_OTTA_mode = "AT+MODE=LWOTAA";
String cmd_DevEui = "AT+ID=DevEui";
String cmd_JOIN = "AT+JOIN=FORCE";
String cmd_send_data = "AT+MSG=\"Data to send\"";

void setup() {
  
  M5.begin();
  Wire.begin();
  // Lcd display
  M5.Lcd.setBrightness(100);
  M5.Lcd.fillScreen(BLACK);
  M5.Lcd.setCursor(10, 10);
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.setTextSize(1);
  M5.Lcd.printf("LoraWAN Network");
  delay(300);
  M5.Lcd.fillScreen(BLACK);
  delay(150);
  M5.Lcd.setCursor(0, 10);
  M5.Lcd.fillScreen(BLACK);
  for(int i=0; i<200; i++) {
        M5.Lcd.setBrightness(i);
        delay(2);
  }
  
  Serial.begin(115200);
  
  Serial2.begin(9600, SERIAL_8N1, 16, 17);
  Serial2.flush();
  /* LoRaWAN Init */
  M5.Lcd.println("Setting up the LoraWAN Connetion");
  Serial2.println(cmd_DEF);
  delay(2000);
  Serial2.println(cmd_OTTA_mode);
  delay(1000);
  Serial2.println(cmd_DevEui);
  delay(1000);
  Serial2.println(cmd_OTTA_mode);
  delay(3000);
  M5.Lcd.println("Joining Network.");
  Serial2.println(cmd_JOIN);
  delay(3000);
  M5.Lcd.println("Message will be send in 155000ms, when next Band is availible");
}

void loop() {
    if(millis() > time_now + period){
        time_now = millis();
        M5.Lcd.println("Sending Data.");
        Serial2.println(cmd_send_data);
    }
    if(Serial2.available()) {
        int ch = Serial2.read();
        Serial.write(ch);
    }
}

I spent my last week with the M5Stack and his LoRaWAN module.I have adapted the Seeeduino library for the RHF76-052 an pasted all on GitHub.

2 Likes

Thanks to your release, I got it running. :pray:

Regards
Christoph