Lora Duplex

With the help I received from the forum I eventually got my little "project" working.

The project turns pumps on and off at the correct time and so far has worked just fine.

My problem now is to get the RX unit to send info back to the TX unit. (I believe its called "Duplex").

The example Duplex in the Lora (Sanddeep) library works just fine with strings, but I face my old enemy, using Integers instead of Strings.

I have enclosed my own attempts to modify my original code to endeavour to transmit the integers

but alas it does not work.

I once again would appreciate any help in getting it to "duplex" integers.

  //                                       ...LoRa Duplex communication...
#include <SPI.h>              // include libraries
  #include <LoRa.h>

  byte localAddress = 0xBB;     // address of this device
byte destination = 0xFF;      // destination to send to
  int staT = 0;
  int onofF = 0;
  int staT2 = 0;
  int onofF2 = 0;

void setup() {
  Serial.begin(9600);                   // initialize serial
  pinMode(7,OUTPUT);
  digitalWrite(7,LOW);
  pinMode(8,OUTPUT);
  digitalWrite(8,LOW);
  while (!Serial);

  Serial.println("LoRa Duplex");


  if (!LoRa.begin(915E6)) {             // initialize ratio at 915 MHz
    Serial.println("LoRa init failed. Check your connections.");
    while (true);                       // if failed, do nothing
  }

  Serial.println("LoRa init succeeded.");
  }
  void TX() {
  Serial.println("Sending packet: ");
  Serial.println(staT);
  Serial.println(onofF);
  // Serial.println(timE);// NOT USED YET


  //........................................TX SEND LOOP...........................
  // send packets
  LoRa.beginPacket();
  LoRa.print("T");
  LoRa.print(staT);
  LoRa.print("F");
  LoRa.print(onofF);
  //LoRa.print("E");//NOT USED YET
  //LoRa.print(timE);//NOT USED YET
  LoRa.endPacket();
}
void RX() {

  digitalWrite(7, HIGH);
  char variable = LoRa.read(); // Read first char
  // char variable = Serial.read(); // Read first char

  switch (variable)
  {
    case 'T':
      staT2 = LoRa.parseInt();
      // staT = Serial.parseInt();
      break;

    case 'F':
      onofF2 = LoRa.parseInt();
      // onofF = Serial.parseInt();
      break;

      // case 'E':              //.....NOT USED YET
      //timE = LoRa.parseInt();
      // timE = Serial.parseInt();
      //break;


  }
  Serial.print(" Received  "); Serial.print(staT2); Serial.print(" ... "); Serial.println(onofF2);

  digitalWrite (7, LOW);
}

  void loop() {
  
 staT = 22;
    onofF = 0;
    digitalWrite(22, LOW);
    TX();
    delay (5000);
     if (LoRa.parsePacket())
    // if(Serial.available())
    delay(100);
  while (LoRa.available())
    // while(Serial.available())

    RX();

    delay(2000);
  }
LoRa Duplex communication wth callback

  Sends a message every half second, and uses callback
  for new incoming messages. Implements a one-byte addressing scheme,
  with 0xFF as the broadcast address.

  Note: while sending, LoRa radio is not listening for incoming messages.
  Note2: when using the callback method, you can't use any of the Stream
  functions that rely on the timeout, such as readString, parseInt(), etc.

  created 28 April 2017
  by Tom Igoe
*/
#include <SPI.h>              // include libraries
#include <LoRa.h>

#ifdef ARDUINO_SAMD_MKRWAN1300
#error "This example is not compatible with the Arduino MKR WAN 1300 board!"
#endif

byte localAddress = 0xFF;     // address of this device
byte destination = 0xBB;      // destination to send to
int staT = 0;
int onofF = 0;
int staT1 = 0;
int onofF1 = 0;

void setup() {
  Serial.begin(9600);                   // initialize serial
  pinMode(7, OUTPUT);
  digitalWrite(7, LOW);
  while (!Serial);

  Serial.println("LoRa Duplex with callback");



  if (!LoRa.begin(915E6)) {             // initialize ratio at 915 MHz
    Serial.println("LoRa init failed. Check your connections.");
    while (true);                       // if failed, do nothing
  }

  // LoRa.onReceive(onReceive);
  LoRa.receive();
  Serial.println("LoRa init succeeded.");
}
void RX() {

  digitalWrite(7, HIGH);
  char variable = LoRa.read(); // Read first char
  // char variable = Serial.read(); // Read first char

  switch (variable)
  {
    case 'T':
      staT = LoRa.parseInt();
      // staT = Serial.parseInt();
      break;

    case 'F':
      onofF = LoRa.parseInt();
      // onofF = Serial.parseInt();
      break;

      // case 'E':              //.....NOT USED YET
      //timE = LoRa.parseInt();
      // timE = Serial.parseInt();
      //break;


  }
  Serial.print(" Received  "); Serial.print(staT); Serial.print(" ... "); Serial.println(onofF);

  digitalWrite (7, LOW);
}
void TX() {
  //Serial.print("Sending :   ");Serial.print(staT1);Serial.print("  and  ");Serial.println(onofF1);
  // Serial.println(timE);// NOT USED YET


  //........................................TX SEND LOOP...........................
  // send packets
  LoRa.beginPacket();
  LoRa.print("T");
  LoRa.print(staT1);
  LoRa.print("F");
  LoRa.print(onofF1);
  //LoRa.print("E");//NOT USED YET
  //LoRa.print(timE);//NOT USED YET
  LoRa.endPacket();
  Serial.print(" Sent Back  "); Serial.print(staT1); Serial.print(" and  "); Serial.println(onofF1);
  delay(2000);
}
void loop() {

  //LoRa.receive();                     // go back into receive mode
  if (LoRa.parsePacket())
    // if(Serial.available())
    delay(100);
  while (LoRa.available())
    // while(Serial.available())
  {
    RX();

    delay(2000);


    staT1 = 50;
    onofF1 = 13;
    TX();




  }





}