first commit

This commit is contained in:
2021-05-11 20:43:42 +03:00
commit 9f3ffaba30
381 changed files with 69596 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 05/11/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - The program transmits a packet without using a processor buffer, the LoRa device
internal buffer is filled direct with variables. The program is a simulation of the type of packet
that might be sent from a GPS tracker. Note that in this example a buffer of text is part of the
transmitted packet.
The matching receiving program '9_LoRa_LowMemory_RX' can be used to receive and display the packet
The contents of the packet received, and printed to serial monitor, should be;
TR1 (buffer) - trackerID
51.23456 (float) - latitude
-3.12345 (float) - longitude
199 (uint16_t) - altitude
8 (uint8_t) - number of satellites
3999 (uint16_t) - battery voltage
-9 (int8_t) - temperature
Memory use on an Arduino Pro Mini;
Sketch uses 4958 bytes (15%) of program storage space.
Global variables use 224 bytes (10%) of dynamic memory, leaving 1824 bytes for local variables.
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#include <Arduino.h>
#include <SPI.h>
#include <SX127XLT.h>
#include "Settings.h"
SX127XLT LoRa;
void loop()
{
//The SX12XX buffer is filled with variables of a known type and order. Make sure the receiver
//uses the same variable type and order to read variables out of the receive buffer.
char trackerID[] = "TR1";
float latitude = 51.23456;
float longitude = -3.12345;
uint16_t altitude = 199;
uint8_t satellites = 8;
uint16_t voltage = 3999;
int16_t temperature = 9;
uint8_t TXPacketL = 0;
uint8_t BytesSent = 0;
LoRa.startWriteSXBuffer(0); //start the write at SX12XX internal buffer location 0
LoRa.writeBufferChar(trackerID, sizeof(trackerID)); //+4 bytes (3 characters plus null (0) at end)
LoRa.writeFloat(latitude); //+4 = 8 bytes
LoRa.writeFloat(longitude); //+4 = 12 bytes
LoRa.writeUint16(altitude); //+2 = 14 bytes
LoRa.writeUint8(satellites); //+1 = 15 bytes
LoRa.writeUint16(voltage); //+2 = 17 bytes
LoRa.writeInt8(temperature); //+1 = 18 bytes total to send
TXPacketL = LoRa.endWriteSXBuffer(); //closes packet write and returns the length of the packet to send
BytesSent = LoRa.transmitSXBuffer(0, TXPacketL, 5000, TXpower, WAIT_TX); //set a TX timeout of 5000mS
if (BytesSent == 0) //if bytessent is 0, there has been a error
{
Serial.print(F("Send Error"));
}
else
{
Serial.print(BytesSent);
Serial.print(F(" Bytes Sent"));
}
Serial.println();
delay(packet_delay);
}
void setup()
{
Serial.begin(9600);
SPI.begin();
if (!LoRa.begin(NSS, NRESET, DIO0, LORA_DEVICE))
{
Serial.println(F("Device error"));
while (1);
}
LoRa.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate, Optimisation);
Serial.flush();
}

View File

@@ -0,0 +1,30 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 05/11/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
//******* Setup hardware pin definitions here ! ***************
//These are the pin definitions for one of my own boards, the Easy Pro Mini,
//be sure to change the definitions to match your own setup.
#define NSS 10 //select on LoRa device
#define NRESET 9 //reset on LoRa device
#define DIO0 3 //DIO0 on LoRa device, used for RX and TX done
#define LORA_DEVICE DEVICE_SX1278 //this is the device we are using
//LoRa Modem Parameters
const uint32_t Frequency = 434000000; //frequency of transmissions
const uint32_t Offset = 0; //offset frequency for calibration purposes
const uint8_t Bandwidth = LORA_BW_125; //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF7; //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5; //LoRa coding rate
const uint8_t Optimisation = LDRO_AUTO; //low data rate optimisation setting
const int8_t TXpower = 10; //LoRa TX power in dBm
const uint16_t packet_delay = 1000; //mS delay between packets

View File

@@ -0,0 +1,168 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 05/11/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - The program receives a packet without using a memory buffer, the LoRa device
internal buffer is read direct for variables. The program is a simulation of the type of packet
that might be received from a GPS tracker. Note that in this example a buffer of text is part of the
received packet.
The matching transmitter program '8_LoRa_LowMemory_TX' is used to transmit the packet.
The contents of the packet received, and printed to serial monitor, should be;
TR1 (buffer) - trackerID
51.23456 (float) - latitude
-3.12345 (float) - longitude
199 (uint16_t) - altitude
8 (uint8_t) - number of satellites
3999 (uint16_t) - battery voltage
-9 (int8_t) - temperature
Memory use on an Arduino Pro Mini;
Sketch uses 6290 bytes (19%) of program storage space.
Global variables use 237 bytes (11%) of dynamic memory, leaving 1811 bytes for local variables.
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#include <SPI.h>
#include <SX127XLT.h>
#include "Settings.h"
SX127XLT LoRa;
void loop()
{
uint8_t RXPacketL;
RXPacketL = LoRa.receiveSXBuffer(0, 0, WAIT_RX); //returns 0 if packet error of some sort, no timeout
if (RXPacketL == 0)
{
packet_is_Error();
}
else
{
packet_is_OK();
}
Serial.println();
}
uint8_t packet_is_OK()
{
char receivebuffer[4]; //create receive buffer, make sure this is big enough for buffer sent !!!
float latitude;
float longitude;
uint16_t altitude;
uint8_t satellites;
uint16_t voltage;
int8_t temperature;
uint8_t RXPacketL;
static uint8_t RXpacketCount;
//packet has been received, now read from the SX12xx Buffer using the same variable type and
//order as the transmit side used.
RXpacketCount++;
Serial.print(RXpacketCount);
Serial.print(F(" "));
LoRa.startReadSXBuffer(0); //start buffer read at location 0
LoRa.readBufferChar(receivebuffer); //read in the character buffer
latitude = LoRa.readFloat(); //read in the latitude
longitude = LoRa.readFloat(); //read in the longitude
altitude = LoRa.readUint16(); //read in the altitude
satellites = LoRa.readUint8(); //read in the number of satellites
voltage = LoRa.readUint16(); //read in the voltage
temperature = LoRa.readInt8(); //read in the temperature
RXPacketL = LoRa.endReadSXBuffer(); //finish packet read, get received packet length
Serial.print(receivebuffer); //print the received character buffer
Serial.print(F(","));
Serial.print(latitude, 5);
Serial.print(F(","));
Serial.print(longitude, 5);
Serial.print(F(","));
Serial.print(altitude);
Serial.print(F("m,"));
Serial.print(satellites);
Serial.print(F("sats,"));
Serial.print(voltage);
Serial.print(F("mV,"));
Serial.print(temperature);
Serial.print(F("c "));
printpacketDetails();
return RXPacketL;
}
void packet_is_Error()
{
uint16_t IRQStatus;
IRQStatus = LoRa.readIrqStatus();
if (IRQStatus & IRQ_RX_TIMEOUT)
{
Serial.print(F("RXTimeout"));
}
else
{
Serial.print(F("PacketError"));
printpacketDetails();
Serial.print(F("IRQreg,"));
Serial.print(IRQStatus, HEX);
}
}
void printpacketDetails()
{
int16_t PacketRSSI; //RSSI of received packet
int8_t PacketSNR; //signal to noise ratio of received packet
PacketRSSI = LoRa.readPacketRSSI();
PacketSNR = LoRa.readPacketSNR();
Serial.print(F(" RSSI,"));
Serial.print(PacketRSSI);
Serial.print(F("dBm,SNR,"));
Serial.print(PacketSNR);
Serial.print(F("dB"));
}
void setup()
{
Serial.begin(9600);
SPI.begin();
if (LoRa.begin(NSS, NRESET, DIO0, LORA_DEVICE))
{
Serial.println(F("Device OK"));
}
else
{
Serial.println(F("Device error"));
while (1);
}
Serial.flush();
LoRa.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate, Optimisation);
}

View File

@@ -0,0 +1,28 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 05/11/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
//******* Setup hardware pin definitions here ! ***************
//These are the pin definitions for one of my own boards, the Easy Pro Mini,
//be sure to change the definitions to match your own setup.
#define NSS 10 //select on LoRa device
#define NRESET 9 //reset on LoRa device
#define DIO0 3 //DIO0 on LoRa device, used for RX and TX done
#define LORA_DEVICE DEVICE_SX1278 //this is the device we are using
//LoRa Modem Parameters
const uint32_t Frequency = 434000000; //frequency of transmissions
const uint32_t Offset = 0; //offset frequency for calibration purposes
const uint8_t Bandwidth = LORA_BW_125; //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF7; //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5; //LoRa coding rate
const uint8_t Optimisation = LDRO_AUTO; //low data rate optimisation setting
const int8_t TXpower = 10; //LoRa TX power in dBm
const uint16_t packet_delay = 1000; //mS delay between packets