Project

General

Profile

More data trough the rf communication

Added by spikie about 4 years ago

Greetings all,

I’m trying to work out my own project and there it is needed to go over the 255 value i can max send with the RFmode i use..
When i go over that number it start counting from 0 again. ( 355 = 99 in my receiver..)

Maybe i made a rookie mistake but it will help me alot if someone could tell me whats going wrong or this is the max i can get..

My code: for sending:

void RFSend(int i,int j){
  rf12_recvDone();
  if ( rf12_canSend()) {
    rf12_sendStart(RF12_HDR_DST | i, &j, sizeof j);
  }
}

Replies (16)

RE: More data trough the rf communication - Added by JohnO about 4 years ago

Could you not use a different group number? If you have an RFM69x as your central node, set it to group 0.

RE: More data trough the rf communication - Added by spikie about 4 years ago

I’ve got an rfm12b at the moment both sides.
But i guess i need to change my code if im going to use diffrent groups..?

RE: More data trough the rf communication - Added by JohnO about 4 years ago

I’m sorry, it must have been the champagne talking earlier. I thought you were asking about using a node number greater than 255…

I now realise that you are transmitting an integer and would like to decode this at your receiver. I’m not sure how you are looking at your received payload, it might be good see to the received packet using RF12Demo, perhaps you could post the result.

Using your example: 355 = 99

I would expect the received data to be two bytes, “99 01” since an integer is two bytes. There is some endian business going on (http://en.wikipedia.org/wiki/Endianness) that means that the lower eight bits are transmitted first, “99” (decimal), immediately followed by the eight high order bits “01” (decimal) in this case. As a number in binary this would look like this:

0000000101100011 == 355

in hex 0163 == 355

Reference the binary example adding one to 255 overflows the 8 bits and moves a 1 into the second byte of the integer.

RE: More data trough the rf communication - Added by spikie about 4 years ago

I was already thinking That was happening..
But is it to do to go over that number. ? Cause i need transmit more than 255 numbers haha.

GreetZ
Spikie

RE: More data trough the rf communication - Added by JohnO about 4 years ago

You could use long integer if 65535 isn’t enough. It is the receiving end that is awkward, mapping the received value bytes and reassembling them byte by byte into an appropriatly sized variable.

RE: More data trough the rf communication - Added by JohnO about 4 years ago

Umh, assuming you use unsigned.

RE: More data trough the rf communication - Added by spikie about 4 years ago

Thanks for your time john ;)

i will post part of my send and receive code. hopefully you see the problem..
what i tried was use for all parts long, or byte or word.. and everytime same thing happens..

sorry for the dutch parts…

receive

int Ontvangen(){
  if ( rf12_recvDone()){
    if ((rf12_crc == 0) && rf12_hdr == (RF12_HDR_DST | NodeId) ){       // kijken of het zonder error's aangekomen is, en of de node id overeenkomt met wat aangegeven is. 
      lastSeq = rf12_data[0];                                           // data omzetten naar int. 

    }
  }
  return lastSeq;
}

my while code:

//Node id eerst en dan melding erin verwerken. 
#include 
#include 


//Meldingen
// raamvoor 
const int NodeArduino = 1;
const int RaamVoorOpen = 101;
const int RaamVoorGesloten = 102;
const int PingRaamVoor = 155;    
// RaamAchter 
const int NodeSchakel = 2;
const int PingRaamAchter = 255; 
// RaamTest
const int NodeTest = 3;
const int PingRaamTest = 400;  

//Eindmeldingen.

// Counters
int I2cStatus = 0;

int Raam = 0;

// Eind Counters

// Setup Data
byte outData = 3;
int led = 6;
int led2 = 5;
int led3 = 4;
int NodeId = 30;
int lastSeq;


// Eind Setup Data

void setup() {
  digitalWrite(led,HIGH);
  rf12_initialize(NodeId, RF12_868MHZ, 88);
  pinMode(6,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(4,OUTPUT);
  Wire.begin(NodeId);
}

void loop() {

  monitoring();
  Wire.onReceive(Transmit);
  Wire.onRequest(StatusReport);

}



void monitoring(){
Raam = Monitor();
I2cStatus = Raam;
  for(long x = 0; x < 60000; x++){
    Raam = Monitor();
    switch(Raam){
    case RaamVoorOpen:
        //I2cStatus = 101;

    break;
    case RaamVoorGesloten:
        //I2cStatus = 102;
    break;
   case PingRaamVoor:
        // I2cStatus = PingRaamVoor;
    break;
    case PingRaamAchter:
        //I2cStatus = PingRaamAchter;
     // PingCountRaamAchter = 1;
    break;
    case PingRaamTest:

      //I2cStatus = 123;
    break;

    }
    delay(1);

  }
I2cStatus = 1;

}
//Read out
int Monitor(){
  int x; 
  x = Ontvangen();
  return x;
}

//RF commands
int Ontvangen(){
  if ( rf12_recvDone()){
    if ((rf12_crc == 0) && rf12_hdr == (RF12_HDR_DST | NodeId) ){       // kijken of het zonder error's aangekomen is, en of de node id overeenkomt met wat aangegeven is. 
      lastSeq = rf12_data[0];                                           // data omzetten naar int. 

    }
  }
  return lastSeq;
}

void RFSend(int i,int j){
  rf12_recvDone();
  if ( rf12_canSend()) {
    rf12_sendStart(RF12_HDR_DST | i, &j, sizeof j);
  }
}

//i2c commands
void StatusReport(){
  Wire.write(I2cStatus);

}
void Transmit(int command){
  int x;
  x = Wire.read();
    if(x == 1){
        RFSend(NodeSchakel,1);          //node 2, data = 1
//      I2cStatus = 4;
  }
    if(x == 2){
        RFSend(NodeSchakel,2);         // node 2, data = 2
  }
    if(x == 3){
        RFSend(NodeArduino,1);
    }
    if(x == 4){
        RFSend(NodeArduino,2);
    }
    if(x == 5){
        RFSend(NodeTest,1);
    }
    if(x == 6){
        RFSend(NodeTest,2);
    }


  }

RE: More data trough the rf communication - Added by JohnO about 4 years ago

Does this compile and make any sense?

int Ontvangen(){
  if ( rf12_recvDone()){
    if ((rf12_crc == 0) && rf12_hdr == (RF12_HDR_DST | NodeId) ){       // kijken of het zonder error's aangekomen is, en of de node id overeenkomt met wat aangegeven is. 
      lastSeq = (rf12_data[1] << 8) + rf12_data[0];                                           // data omzetten naar int. 

    }
  }
  return lastSeq;
}

RE: More data trough the rf communication - Added by spikie about 4 years ago

@johnO

nope that does nothing diffrent..

more searching here and still if i change numbers it roll over to next number. in case i take the number 356, my transceiver sends out a 100 to my i2c network..

RE: More data trough the rf communication - Added by JohnO about 4 years ago

I think we need to find a common understanding of the things you are currently calling numbers. 100 is a number and has three digits, 356 has three digits too but the 100 and 356 numbers are different internally to a computer in the the amount of memory required to store or transmit them. Values between 0 and 255, conventional numbers to you and I require as a minimum one byte in a computer to store or transmit via radio or i2c. Numbers between 256 and 65535, assuming they are to be handled unsigned require two bytes internally for a computer. Similarly two bytes is required to transmit or receive them via radio or i2c.

How are you with this concept?

RE: More data trough the rf communication - Added by spikie about 4 years ago

haha sorry,

what you are telling me is right. sorry that i was confusing you.

what i mean with 99 and 100. is what i guess is happening. because i go over the 255 for 1 byte. and then it place the rest of the number in the same byte again so i lose 255 and the rest value is displayed to my i2c. but what i understand out of your text is that when i change the int to unsigned int. it should be over?

i will try that out tomorrow morning.

Greets,

spikie
p.s. sorry for the n00b talking.

RE: More data trough the rf communication - Added by JohnO about 4 years ago

I still don’t understand what the issue is and I’m afraid to don’t see that unsigned will change this conundrum.

RE: More data trough the rf communication - Added by spikie about 4 years ago

Maybe this will help.

my idea was:
my transceiver know alot of numbers.
that is based on the node number and a command.

like:
node 1. command 55( this means a ping command to a slave)
the transceiver sends then:
155 to the node.
and then node 1 knows that is for him and 55 is for the command.

so on:
node 2 command 55 ( ping)
255 to the node.

and this goes very well.
but then node 3.
node 3 command 55 (ping)
355 to node.

but what happens on the node 3:
receiving 99.

after some thinking i found out that it is: 355-256= 99.
so it overrules the first 256 digits.

and now i need to find out how i can get on the node instead of 99, the 355 digit.

hopefully you understand what i mean now.

greets,

spikie
btw thanks for the help thinking.

RE: More data trough the rf communication - Added by spikie about 4 years ago

happy new year for all ;)

some one maybe could help me? or is it something without fix and i need to change my plans?

greetz
spikie

RE: More data trough the rf communication - Added by JohnO about 4 years ago

Happy New Year spikie,

A quick recap for me. An unsigned integer is 16 bits long which is two bytes and if you count up to 255 only the first of the two bytes is used. As soon as you count past 255 then the second byte comes into action. The first byte is not “over ruled” it continues to be used as the count progresses such the the value 257 looks like this: 0x0101 in hexadecimal.

Now, going back to what you are trying to do:
Instead of duplicating the target node number in the packet payload you could send a packet directed to Node2 containing your command, 55 in your example. This would save the complications of the second byte for you.

    (1-16/16)