USIWP1Module / USI_I-NUCLEO-LRWAN1

31 stars 19 forks source link

Can not get a buffer bigger than 4 bytes at the reception #10

Open adrienDLCT opened 6 years ago

adrienDLCT commented 6 years ago

Hello,

I am working with a stm32l053R8 and a I-NUCLEO-LRWAN1. I've got a problem with my buffer at the reception in fact when i read it, every time i see only the first 4 bytes and after nothing. So I verified if the data are well transmitted and indeed on the TX-Uart pin of the LoRa shield i can read in Hexa that the message is correct. So the problem come from the function that read these data an put it in the buffer; LoraRadio.read() If you have an idea how to solve this problem, I would be greatfull to have the solution. Thank you.

USI-ShellyWu commented 6 years ago

Please kindly tell what function you verified and detailed step and the final fail log.

adrienDLCT commented 6 years ago

_uint8_t rcvData[20];
bool next = true; if ( init_buff == true) { for (int i=0; i<20; i++) { rcvData[i] = '0'; } Serial.print("buffer initialized"); initbuff = false; } if(loraRadio.read(rcvData) > 0 && next == true) { //loraRadio.read(rcvData); Serial.print("buffer : "); Serial.println((char*)rcvData); next = false; }

This code display me the 4 first bytes received, and after there are the '0' I put to initialize the buffer.

PS: When I am watching the information received on the TX pin of the LoRa shield with a logic analizer, i can see the full message of 20 bytes.

USI-ShellyWu commented 6 years ago

As talked with other engineer, sorry for not understanding your problem. We must know the function you tested and the detailed test steps and the modification you have made before.

adrienDLCT commented 6 years ago

So, this is the entire code, I want to send the data sensore in line in the buffer and then at the reception, separate everything, but at the reception the buffer is badly fill. Sorry if my explanations are not clear to you.

**#include // Library of temperature and humidity sensor

include "LoRaRadio.h"

include "lora_driver.h"

//Define

define I2C2_SCL PB8 // Define of I2C clock pin

define I2C2_SDA PB9 // Define of I2C data pin

//#define gateway // Here we define the Node we want to program Master or Slave

define node1

//#define node2

HardwareSerial SerialLora(PC_11, PC_10);

HTS221Sensor HumTemp; TwoWire dev_i2c; uint8_t Msg1[] = "temp"; //Declaration of humidity message uint8_t Msg2[] = "humi"; //Declaration of temperature message uint8_t Node1[] = "A"; // ID Node 1 size = 2 bytes uint8_t Node2[] = "B"; //ID Node 2 size = 2 bytes

void ShiftLeft(uint8_t Oldbyte[], uint8_t Newbyte[], int nbr_shift, int size_oldB) { for (int i = 0; i<4; i++) { Newbyte[i]=Oldbyte[i+nbr_shift]; } } void ShiftRight(uint8_t Oldbyte[], uint8_t Newbyte[], int nbr_shift, int size_oldB) { for (int i = 0; i<size_oldB; i++) { Newbyte[i+nbr_shift]=Oldbyte[i]; } }

void readbuffer(uint8_t rcvData[64], bool next) // Function that read data of the buffer { Serial.print("dans fonction buffer \n");

uint8_t Sens_temp[5];
uint8_t Data_sens_temp[4];
uint8_t Sens_humi[5];
uint8_t Data_sens_humi[4];

for(int i=1; i<6; i++) 
{
  Sens_temp[i-1] = rcvData[i];
}
Serial.println((char *)Sens_temp);
for(int i=5; i<10; i++)
{
   Data_sens_temp[i-5] = rcvData[i];
}
float data = (float)*Data_sens_temp;
Serial.println(data);

for(int i=10; i<15; i++) 
{
  Sens_humi[i-10] = rcvData[i];
}
Sens_humi[4] = '\0';
Serial.println((char *)Sens_humi);
for(int i=15; i<19; i++)
{
   Data_sens_humi[i-15] = rcvData[i];
}
data = (float)*Data_sens_humi;
Serial.println(data);
next = false;

}

/MASTER1/

ifdef node1

void setup() { Serial.begin(9600); //Initialisation of the LoRa module
Serial.println("-- LoRa Ping Pong sketch --"); while(!loraRadio.begin(&SerialLora)) { Serial.println("LoRa module not ready"); delay(10000); } Serial.println("LoRa module ready\n"); pinMode(LED_BUILTIN, OUTPUT); // Init Led like output. Serial.begin(9600); // Initialize serial for output.

dev_i2c = new TwoWire(I2C2_SDA, I2C2_SCL); // Initialize I2C bus. dev_i2c->begin();

HumTemp = new HTS221Sensor (dev_i2c); // Initlialize components. HumTemp->Enable(); }

void loop() { uint8_t End_Sens[18];

union                                                        // Convert a float into 4 uint8_t

{float humidity; uint8_t humi[4]; }; union // Convert a float into 4 uint8_t {float temperature; uint8_t temp[4]; };

HumTemp->GetHumidity(&humidity); // Get value of humidity sensor HumTemp->GetTemperature(&temperature); // Get value of temperature sensor

End_Sens[0] = Node1[0]; ShiftRight(Msg1,End_Sens,1,5); ShiftRight(temp,End_Sens,6,4); ShiftRight(Msg2,End_Sens,10,5); ShiftRight(humi,End_Sens,15,4);

Serial.println((char)End_Sens[0]); //A

Serial.println((char)End_Sens[1]); //t
Serial.println((char)End_Sens[2]); //e
Serial.println((char)End_Sens[3]); //m
Serial.println((char)End_Sens[4]); //p
Serial.println((char)End_Sens[5]); //\0

Serial.println((char)End_Sens[6]); //
Serial.println((char)End_Sens[7]); //
Serial.println((char)End_Sens[8]); //
Serial.println((char)End_Sens[9]);  //

Serial.println((char)End_Sens[10]); //h
Serial.println((char)End_Sens[11]); //u
Serial.println((char)End_Sens[12]); //m
Serial.println((char)End_Sens[13]); //i
Serial.println((char)End_Sens[14]); //\0

Serial.println((char)End_Sens[15]); //
Serial.println((char)End_Sens[16]); //
Serial.println((char)End_Sens[17]); //
Serial.println((char)End_Sens[18]); //

/EndHumi[0] = Node1[0]; ShiftRight(Msg2,EndHumi,1,4); ShiftRight(humi,EndHumi,5,4); EndHumi[9] = '\0';/

Serial.print("Hum[%]: "); // Send on serial port Hum: Serial.print(humidity, 2); // Send on serial port humidity value loraRadio.write(End_Sens,18); // Send msg1 with LoRa module

Serial.print(" | Temp[C]: "); // Send on serial port Temp: Serial.println(temperature, 2); // Send on serial port temperature value delay(10000); /loraRadio.write(EndTemp,10); // Send msg2 with LoRa module / }

endif

/SLAVE/

ifdef gateway

void setup() { Serial.begin(9600); // Initialisation of the LoRa module
Serial.println("-- LoRa Ping Pong sketch --"); while(!loraRadio.begin(&SerialLora)) { Serial.println("LoRa module not ready"); delay(10000); } Serial.println("LoRa module ready\n"); pinMode(LED_BUILTIN, OUTPUT); // Init Led like output. } bool init_buff = true; void loop() { uint8_t rcvData[20];
bool next = true; if ( init_buff == true) { for (int i=0; i<20; i++) { rcvData[i] = '0'; } Serial.print("buffer initialized"); init_buff = false; } /while (LoraRadio.available()) { Serial.println((char)LoraRadio.read()); }/ if(loraRadio.read(rcvData) > 0 && next == true) { loraRadio.read(rcvData); Serial.print("buffer : "); Serial.println((char*)rcvData); Serial.println((char)rcvData[4]); digitalWrite(LED_BUILTIN, HIGH); // Turn on the internal LED if((char)rcvData[0] == 'A') { Serial.print("data node 1 : "); // Send on serial port Hum: readbuffer( rcvData, next); // cf : readbuffer function next = false; } if((char)rcvData[0] == 'B') { Serial.print("data node 2 : "); // Send on serial port Hum: readbuffer( rcvData, next); // cf : readbuffer function next = false; } } digitalWrite(LED_BUILTIN, LOW); // Turn on the internal LED }

endif**

USI-ShellyWu commented 6 years ago

Please try to configure UART to be 115200 firstly, and try USI FW supports AT CMD to confirm work normally.

cstratton commented 3 years ago

Likely your loraRadio.read(rcvData) method is faulty but since you have not provided it no one can really know.

You also appear to be calling it twice which is probably a mistake...