<commit_before>#include <rn2483.h>
#include <SoftwareSerial.h>

#define RADIO_RESET_PIN 12

/*
 * Please create a radiokeys.h file containing the keys you got
 * when registering with TTN. It should look somewhat like:
 * 
 * #define RADIO_APPEUI "40B3D17ED00301A6"
 * #define RADIO_APPKEY "<KEY>"
 * 
 */
#include "radiokeys.h"
#if !defined(RADIO_APPEUI)
#define RADIO_APPEUI "not defined"
#define RADIO_APPKEY "not defined"
#define REGISTERFIRST 1
#endif

SoftwareSerial mySerial(10, 11); // RX, TX

//create an instance of the rn2483 library, 
//giving the software serial as port to use
rn2483 myLora(mySerial);

// the setup routine runs once when you press reset:
void setup_radio() 
{

  initialize_radio();

#if defined(REGISTERFIRST)
  Serial.println("You need to generate keys at TTN.");
  print_radio_hweui();
  Serial.println("Halting.");
  while(true){}
#else
  join_TTN();
#endif
}

void initialize_radio() {
  //reset rn2483
  pinMode(RADIO_RESET_PIN, OUTPUT);
  digitalWrite(RADIO_RESET_PIN, LOW);
  delay(500);
  digitalWrite(RADIO_RESET_PIN, HIGH);

  //Autobaud the rn2483 module to 9600. The default would otherwise be 57600.
  mySerial.begin(9600); //serial port to radio
  myLora.autobaud();
}

void print_radio_hweui() {
  //print out the HWEUI so that we can register it via ttnctl
  Serial.println("When using OTAA, register this DevEUI: ");
  Serial.println(myLora.hweui());
  Serial.println("RN2483 firmware version:");
  Serial.println(myLora.sysver());
}

void join_TTN() {
  //OTAA: initOTAA(String AppEUI, String AppKey);
  Serial.println("Joining with EUI ");
  Serial.print(RADIO_APPEUI);
  Serial.print(" and app key ");
  Serial.println(RADIO_APPEUI);
  
  digitalWrite(LED_PIN, HIGH);
  bool join_result = myLora.initOTAA(RADIO_APPEUI, RADIO_APPKEY);

  while(!join_result) {
    Serial.println("Join failed. Retry in one minute. Are your keys correct, and do you have TTN coverage?");

    for (int i=0; i<60; i++) {
      digitalWrite(LED_PIN, LOW);
      delay(500); //delay a minute before retry
      digitalWrite(LED_PIN, HIGH);
      delay(500); //delay a minute before retry
    }
    join_result = myLora.init();
  }
  
  Serial.println("Successfully joined TTN."); 
  digitalWrite(LED_PIN, LOW);
}

// the loop routine runs over and over again forever:
void send_to_TTN(String data)  {
  digitalWrite(LED_PIN, HIGH);
  <commit_msg>Better logging and blinking.<commit_after>#include <rn2483.h>
#include <SoftwareSerial.h>

#define RADIO_RESET_PIN 12

/*
 * Please create a radiokeys.h file containing the keys you got
 * when registering with TTN. It should look somewhat like:
 * 
 * #define RADIO_APPEUI "40B3D17ED00301A6"
 * #define RADIO_APPKEY "<KEY>"
 * 
 * Register your application in the dashboard of TTN at
 * https://staging.thethingsnetwork.org/applications
 * 
 */
#include "radiokeys.h"
#if !defined(RADIO_APPEUI)
#define RADIO_APPEUI "not defined"
#define RADIO_APPKEY "not defined"
#define REGISTERFIRST 1
#endif

SoftwareSerial mySerial(10, 11); // RX, TX

//create an instance of the rn2483 library, 
//giving the software serial as port to use
rn2483 myLora(mySerial);

// the setup routine runs once when you press reset:
void setup_radio()  {
  initialize_radio();

#if defined(REGISTERFIRST)
  Serial.println("You need to generate keys at TTN.");
  print_radio_hweui();
  Serial.println("Halting.");
  while(true){}
#else
  join_TTN();
#endif
}

void initialize_radio() {
  //reset rn2483
  pinMode(RADIO_RESET_PIN, OUTPUT);
  digitalWrite(RADIO_RESET_PIN, LOW);
  delay(500);
  digitalWrite(RADIO_RESET_PIN, HIGH);

  //Autobaud the rn2483 module to 9600. The default would otherwise be 57600.
  mySerial.begin(9600); //serial port to radio
  myLora.autobaud();
}

void print_radio_hweui() {
  //print out the HWEUI so that we can register it via ttnctl
  Serial.println("When using OTAA, register this DevEUI: ");
  Serial.println(myLora.hweui());
  Serial.println("RN2483 firmware version:");
  Serial.println(myLora.sysver());
}

void join_TTN() {

  //OTAA: initOTAA(String AppEUI, String AppKey);
  Serial.println("Joining TTN with:");
  Serial.print("Dev EUI: "); Serial.println(myLora.hweui());
  Serial.print("App EUI: "); Serial.println(RADIO_APPEUI);
  Serial.print("App Key: "); Serial.println(RADIO_APPKEY);
  
  digitalWrite(LED_PIN, HIGH);
  bool join_result = myLora.initOTAA(RADIO_APPEUI, RADIO_APPKEY);
  
  while(!join_result) {
    Serial.println("Join failed. Retry in one minute. Are your keys correct, and do you have TTN coverage?");

    for (int i=0; i<150; i++) {
      digitalWrite(LED_PIN, LOW);
      delay(200); //delay a minute before retry
      digitalWrite(LED_PIN, HIGH);
      delay(200); //delay a minute before retry
    }
    join_result = myLora.init();
  }
  
  Serial.println("Successfully joined TTN."); 
  digitalWrite(LED_PIN, LOW);
}

// the loop routine runs over and over again forever:
void send_to_TTN(String data)  {
  digitalWrite(LED_PIN, HIGH);
  
{'fraction_non_alphanumeric': 0.12054739384181928, 'fraction_numerical': 0.027168444355001008, 'mean_word_length': 4.2592592592592595, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6401024', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1718, 'n_words': 480}