xreef / LoRa_E32_Series_Library

Arduino LoRa EBYTE E32 device library complete and tested with Arduino, esp8266, esp32, STM32 and Raspberry Pi Pico (rp2040 boards). sx1278/sx1276
https://www.mischianti.org
Other
348 stars 72 forks source link

two nodes send same time message to one receiver #50

Closed fixajteknik closed 1 year ago

fixajteknik commented 1 year ago

well if there are 2 or more nodes sending data to only one center. whene same time nodes send data only one of them can read only from receiver. Because receviver read a struct dan free() other so second nodes datas are losted. but if I use this code and see whatever coming without split or any orhet else,

while (FixajSS.available() > 1) { ResponseContainer rs = FixajSS.receiveMessage(); String typeStr = rs.data; Serial.println(typeStr); }

my nodes data structs is

struct Signal { char sifre[15] = "Fixaj.com"; char konum[15]; byte nem; //0-100 arası bir değer olduğu için byte id; //0-250 arası bir değer yeterli şimdilik byte temp[4]; // float tipinde 29.5 gibi bir değer atacak } data;

the Output is this

16:00:14.286 -> Fixaj.comMutfak3���AFixaj.comKumes+��A 16:00:16.479 -> Fixaj.comMutfak3���AFixaj.comKumes+@ �A`

Mutfak is a node and Kumes is another node. So datas are coming but how get all nodes data without losting any data?

in my opinion there should be add a new method which is ResponseStructContainer LoRa_E32::receiveMessageUntil(char delimiter)

if I changed the library like this

ResponseStructContainer LoRa_E32::receiveMessage(const uint8_t size){
    ResponseStructContainer rc;

    rc.data = malloc(size);
    rc.status.code = this->receiveStruct((uint8_t *)rc.data, size);
    //this->cleanUARTBuffer();
    if (rc.status.code!=E32_SUCCESS) {
        return rc;
    }

    return rc;
}

and changing my code like this:

void loop() {
  while (FixajSS.available() > 1) {

    ResponseStructContainer rss = FixajSS.receiveMessage(sizeof(Signal));
    struct Signal data = *(Signal*)rss.data; 

    if (strcmp(data.sifre, "Fixaj.com") == 0) {
      //Serial.println("Sifre dogru");
      Serial.print("Konum1: ");
      Serial.print(data.konum);
      Serial.print("\t id: ");
      Serial.print(data.id);
      Serial.print("\t sicaklik: ");
      Serial.print(*(float*)(data.temp), 2);  // float tipinde olduğu için cast etmem lazım
      Serial.print("\t Nem: ");
      Serial.println(data.nem);

      //while (FixajSS.available() > 1) {
        rss = FixajSS.receiveMessage(sizeof(Signal));
        struct Signal data = *(Signal*)rss.data;

        if (strcmp(data.sifre, "Fixaj.com") == 0) {
          //Serial.println("Sifre dogru");
          Serial.print("Konum2: ");
          Serial.print(data.konum);
          Serial.print("\t id: ");
          Serial.print(data.id);
          Serial.print("\t sicaklik: ");
          Serial.print(*(float*)(data.temp), 2);  // float tipinde olduğu için cast etmem lazım
          Serial.print("\t Nem: ");
          Serial.println(data.nem);
       // }
      }
    }

    rss.close();
  }

the OUTPUT look nice but sometimes read only 1 node esspecially if a node very close to receiver.

17:01:59.679 -> Konum1: Mutfak   id: 2   sicaklik: 21.72     Nem: 46
17:02:00.206 -> Konum2: Kumes    id: 1   sicaklik: 22.44     Nem: 49
17:02:01.878 -> Konum1: Mutfak   id: 2   sicaklik: 21.73     Nem: 46
17:02:02.415 -> Konum2: Kumes    id: 1   sicaklik: 22.43     Nem: 49
17:02:04.047 -> Konum1: Mutfak   id: 2   sicaklik: 21.69     Nem: 46
17:02:04.622 -> Konum2: Kumes    id: 1   sicaklik: 22.44     Nem: 49
17:02:06.268 -> Konum1: Mutfak   id: 2   sicaklik: 21.72     Nem: 46
xreef commented 1 year ago

Hi, yes It's possible. The sender and the receiver can't stay too close. You must add some distance from the devices.

Yes, I think the free must be optional. I'm going to think about that.

Bye Renzo