I'm so new on LoRa programming, i'm trying to send 2 data byte and receive them, but i don't know how exactly LoRA.read works, if you have some informations gonna be so useful for me and thanks.
Transmitter Code :
#include <SPI.h>
#include <Wire.h>
#include <LoRa.h>
int counter = 0;
byte Data[2]={};
void convertIntToByte(int number)
{
if (sizeof(number) > 2)
{
Data[0] = 0xFF;
Data[1] = 0xFF;
}
else
{
Data[0] = (number >> 8) & 0xFF;
Data[1] = number & 0xFF;
}
}
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Sender");
if (!LoRa.begin(868E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop()
{
Serial.print("Sending packet: ");
Serial.println(counter);
int valeur = 150;
convertIntToByte(valeur);
// send packet
LoRa.beginPacket();
/*
LoRa.print("hello ");
LoRa.print(counter);
*/
LoRa.print(Data[0]);
LoRa.print(Data[1]);
LoRa.endPacket();
counter++;
delay(5000);
}
Receiver Code :
#include <SPI.h>
#include <LoRa.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define WIRE Wire
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE);//check resolution
float convertBytetoInt(byte strongByte, byte lightByte )
{
float val=strongByte*256+lightByte;
return val;
}
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // check Address on screen backside
Serial.println("OLED begun");
display.display();
delay(1000);
// Clear the buffer.
display.clearDisplay();
display.display();
while (!Serial);
Serial.println("LoRa Receiver");
if (!LoRa.begin(868E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
bool refresh_screen = false;
void loop() {
int packetSize = LoRa.parsePacket();
//int finalevalue;
if (packetSize) {
//String msg;
while (LoRa.available()){
byte byteHigh=LoRa.read();
byte byteLow=LoRa.read();
float valeur=convertBytetoInt(byteHigh,byteLow);
//finalevalue = round(valeur);
//msg+=(char)i;
//Serial.print((char)i);
Serial.print(round(valeur));
refresh_screen = true;
}
Serial.print(" with RSSI ");
Serial.println(LoRa.packetRssi());
Serial.println();
if(refresh_screen == true){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
//display.print());
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,10);
display.print(" with RSSI: ");
display.setCursor(70,10);
display.print(LoRa.packetRssi());
display.display();
refresh_screen = false;
}
}
}
The variable "valeur" it's a current sensor valeu to set later
the simplest thing is to put you data in a structure and transmit/receive the complete structure - see post decimals-strings-and-lora
what Lora boards are you using?
i'm uisng MKR WAN 1310
I have used a number of Lora boards in particular Adafruit 32u4 Lora, UNO Lora shields, Microchip PicTailPlus Lora and purpose built PCBs
not used the MKR WAN 1310 Lora board but have used the MKRFOX 1200 on various projects - never had an problems with MKR series connecting sensors etc
aaam goood !! For me, it's the first time using those LoRa boards.
I resolved the problem, i just convert the byte data in to integer and send it normally.
But to send more data, i don't know gonna be other thing.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.