Help please to send two integers via Nano and RFM69HW, updated with code..

Hello Forum. My second post on this subject due to not having code to hand the first time… ooops!
I am trying to send two integers via the Nano and RFM69HW transceiver in one transmission and display them individually on the receiving Nano LCD. I can transmit and read one integer ok so half way there at the moment. Thanks in advance for any help.
Code for Tx first, Rx as follows further down.

Tx code so far…

#include <RFM69.h>
#include <RFM69_ATC.h>
 
#include <RFM69.h>
#include <SPI.h>
 
#define NETWORKID     100  // The same on all nodes that talk to each other
#define NODEID        1    // The unique identifier of this node
#define RECEIVER      99   // Recipient of packets, set up the BASE STATION as 99 (was 1)
#define RFM69_CS      10
#define RFM69_IRQ     2
#define RFM69_IRQN    0  // Pin 2 is IRQ 0!
char buff[60];

unsigned int in1 = 456;
unsigned int in2 = 789;


RFM69 radio = RFM69(RFM69_CS, RFM69_IRQ, true, RFM69_IRQN);
 
void setup() 
{
  Serial.begin(9600);
  
  // Hard Reset the RFM module
  pinMode(9, OUTPUT);
  digitalWrite(9, HIGH);
  delay(100);
  digitalWrite(9, LOW);
  delay(100);
 
  // Initialize radio
  radio.initialize(RF69_433MHZ,NODEID,NETWORKID);
  radio.setHighPower();    // Only for RFM69HCW & HW!
  radio.setPowerLevel(31); // power output ranges from 0 (5dBm) to 31 (20dBm)
  radio.encrypt("Encrypt999999999"); // 16 characters must match
  
  pinMode(13, OUTPUT);
}
void loop() 
{
  delay(1000);  // Wait 1 second between transmits

  sprintf(buff, "In1:%05.0hu",out); // Prints characters In1: and then the value of In1 on display 

  byte buffLen = strlen(buff);
    
  if (radio.sendWithRetry(99, buff, buffLen)) 
 
  radio.receiveDone();
  Serial.flush();
}

Rx code is below…

#include <Wire.h>
#include <RFM69.h>
#include <SPI.h>

 
#define NETWORKID     100  //the same on all nodes that talk to each other
#define NODEID        99   //BASE STATION is 99, all others are 1,2,3 etc
#define RFM69_CS      10
#define RFM69_IRQ     2
#define RFM69_IRQN    0  // Pin 2 is IRQ 0!
 

unsigned int in1 = 0;
unsigned int in2 = 0;

 
RFM69 radio = RFM69(RFM69_CS, RFM69_IRQ, true, RFM69_IRQN);
 
void setup() 
{
  Wire.begin();
  Serial.begin(9600);
  Serial.print("\e[2J");  //Clears Screen
  delay(50);
  
  // Hard Reset the RFM module
  pinMode(9, OUTPUT);
  digitalWrite(9, HIGH);
  delay(100);
  digitalWrite(9, LOW);
  delay(100);
  
  // Initialize radio
   radio.initialize(RF69_433MHZ,NODEID,NETWORKID);
   radio.setHighPower();
   radio.setPowerLevel(31);
   radio.encrypt("Encrypt999999999"); // 16 characters must match
  
   pinMode(13, OUTPUT);
   pinMode(8, OUTPUT);   
}
 
void loop() 
{
  if (radio.receiveDone())  //check if something was received
  {
       Serial.print("\e[1;0H"); 
       Serial.print((char*)radio.DATA);
       delay(50);
 
  
        digitalWrite(8,HIGH);  // flash red led on pin 8 for received
        delay(50);
        digitalWrite(8,LOW);   
  }
 
  radio.receiveDone();
  Serial.flush();
}

Well the sending part is this:

  sprintf(buff, "In1:%05.0hu",out); // Prints characters In1: and then the value of In1 on display 
  byte buffLen = strlen(buff);
  if (radio.sendWithRetry(99, buff, buffLen)) 
...

you should read the doc to understand sprintf([color=blue]buff[/color], "In1:[color=purple]%05.0hu[/color]",[color=red]out[/color]);

buff is the destination buffer, where you will build up the string to send
"In1:%05.0hu" is how the string will be built. things starting with % something will be replaced by parameters that are after that string

out that's the weird piece in your code.. I thought you want to send In1... not sure what out is...

for example

int in1 = 10;
int in2 = 100;
sprintf(buff, "in1 = %d and in2 = %d", in1, in2);

would build the string "in1 = 10 and in2 = 100" into buff.

that's how you would go to send your 2 infos.

Thanks J-M-L.

The sprintf line help is what I needed, couldnt work that bit out.

Also sorry for the ‘out’ confusion, that was from an earlier trial which I should have written as in1.

Just hope its as simple deciphering at the receiver :slight_smile:

Right, off to play…

Once again thank you.

Kind Regards. Pete

Well my view is that you should not make it too verbose... Why would a computer taking to a computer make nice long sentences?

Just have the emitter send just the two values, no "crap" around it and have the receiver just read those two values... This way no real parsing to do...