LoRa Access Point 1.5.2018

Dependencies:   mbed ds3231 SX1276Lib_LoRa_Access_Point

Committer:
lukas_formanek
Date:
Sat May 08 16:23:46 2021 +0000
Revision:
11:376bfcdda0d4
Parent:
8:5d99fbf255d6
LoRa_Access_Point

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lukas_formanek 0:ea088908ad26 1 #ifndef RFM95W_H
lukas_formanek 0:ea088908ad26 2 #define RFM95W_H
lukas_formanek 0:ea088908ad26 3
lukas_formanek 0:ea088908ad26 4 #include "mbed.h"
lukas_formanek 0:ea088908ad26 5 #include "sx1276-hal.h"
lukas_formanek 0:ea088908ad26 6 #include "ESP8266.h"
lukas_formanek 1:7543af31b91f 7 #include "Board.h"
lukas_formanek 8:5d99fbf255d6 8 #include "SD.h"
lukas_formanek 0:ea088908ad26 9
lukas_formanek 5:19b34c4d27a1 10 #define GATEWAY_ID 1 // Adresa Access pointu
lukas_formanek 0:ea088908ad26 11
lukas_formanek 0:ea088908ad26 12 ////////////////////////////////////////////////////////////////////////////////
lukas_formanek 0:ea088908ad26 13
lukas_formanek 0:ea088908ad26 14 /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */
lukas_formanek 0:ea088908ad26 15 #define USE_MODEM_LORA 1
lukas_formanek 0:ea088908ad26 16 #define USE_MODEM_FSK !USE_MODEM_LORA
lukas_formanek 0:ea088908ad26 17
lukas_formanek 0:ea088908ad26 18 #define RF_FREQUENCY 869525000 //868000000 // Hz
lukas_formanek 0:ea088908ad26 19 #define TX_OUTPUT_POWER 20 // 20 dBm
lukas_formanek 0:ea088908ad26 20
lukas_formanek 0:ea088908ad26 21 #if USE_MODEM_LORA == 1
lukas_formanek 5:19b34c4d27a1 22 // Max range, slow data rate = BW=125, CR=4/5, SF=12
lukas_formanek 5:19b34c4d27a1 23 #define LORA_BANDWIDTH 1 // [0: 125 kHz,
lukas_formanek 5:19b34c4d27a1 24 // 1: 250 kHz,
lukas_formanek 5:19b34c4d27a1 25 // 2: 500 kHz,
lukas_formanek 5:19b34c4d27a1 26 // 3: Reserved]
lukas_formanek 5:19b34c4d27a1 27 #define LORA_SPREADING_FACTOR 12 // [SF7..SF12]
lukas_formanek 5:19b34c4d27a1 28 #define LORA_CODINGRATE 1 // [1: 4/5,
lukas_formanek 5:19b34c4d27a1 29 // 2: 4/6,
lukas_formanek 5:19b34c4d27a1 30 // 3: 4/7,
lukas_formanek 5:19b34c4d27a1 31 // 4: 4/8]
lukas_formanek 5:19b34c4d27a1 32 #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
lukas_formanek 5:19b34c4d27a1 33 #define LORA_SYMBOL_TIMEOUT 5 // Symbols
lukas_formanek 5:19b34c4d27a1 34 #define LORA_FIX_LENGTH_PAYLOAD_ON false
lukas_formanek 5:19b34c4d27a1 35 #define LORA_FHSS_ENABLED false
lukas_formanek 5:19b34c4d27a1 36 #define LORA_NB_SYMB_HOP 4
lukas_formanek 5:19b34c4d27a1 37 #define LORA_IQ_INVERSION_ON false
lukas_formanek 5:19b34c4d27a1 38 #define LORA_CRC_ENABLED true
lukas_formanek 0:ea088908ad26 39
lukas_formanek 0:ea088908ad26 40 #elif USE_MODEM_FSK == 1
lukas_formanek 0:ea088908ad26 41
lukas_formanek 5:19b34c4d27a1 42 #define FSK_FDEV 25000 // Hz
lukas_formanek 5:19b34c4d27a1 43 #define FSK_DATARATE 19200 // bps
lukas_formanek 5:19b34c4d27a1 44 #define FSK_BANDWIDTH 50000 // Hz
lukas_formanek 5:19b34c4d27a1 45 #define FSK_AFC_BANDWIDTH 83333 // Hz
lukas_formanek 5:19b34c4d27a1 46 #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx
lukas_formanek 5:19b34c4d27a1 47 #define FSK_FIX_LENGTH_PAYLOAD_ON false
lukas_formanek 5:19b34c4d27a1 48 #define FSK_CRC_ENABLED true
lukas_formanek 0:ea088908ad26 49
lukas_formanek 0:ea088908ad26 50 #else
lukas_formanek 5:19b34c4d27a1 51 #error "Please define a modem in the compiler options."
lukas_formanek 0:ea088908ad26 52 #endif
lukas_formanek 0:ea088908ad26 53
lukas_formanek 0:ea088908ad26 54 #define RX_TIMEOUT_VALUE 2500000 // in us // 3500000
lukas_formanek 0:ea088908ad26 55 #define BUFF_SIZE 255 // Define the payload size here // 32
lukas_formanek 2:0499e1d037a5 56 #define MAX_DEVICES 255
lukas_formanek 4:e20eb5efd859 57 #define MAX_RESENDS 4
lukas_formanek 0:ea088908ad26 58 //------------------------------------------------------------------------------
lukas_formanek 0:ea088908ad26 59
lukas_formanek 0:ea088908ad26 60 class RFM95W
lukas_formanek 0:ea088908ad26 61 {
lukas_formanek 0:ea088908ad26 62 private:
lukas_formanek 0:ea088908ad26 63 RadioEvents_t radioEvents; /**< Radio events function pointer */
lukas_formanek 0:ea088908ad26 64 SX1276MB1xAS radio; /**< Radiovy modul */
lukas_formanek 0:ea088908ad26 65 DigitalOut indicationLed; /**< Indikacna led */
lukas_formanek 5:19b34c4d27a1 66 AnalogIn noise;
lukas_formanek 0:ea088908ad26 67 Ticker ledTicker;
lukas_formanek 3:7a3ddda464bf 68 Ticker sendTicker;
lukas_formanek 3:7a3ddda464bf 69 Ticker ackTicker;
lukas_formanek 3:7a3ddda464bf 70
lukas_formanek 1:7543af31b91f 71 uint8_t receivedMessage[BUFF_SIZE];
lukas_formanek 3:7a3ddda464bf 72 uint8_t sendBuffer[BUFF_SIZE];
lukas_formanek 3:7a3ddda464bf 73 uint8_t ack[3];
lukas_formanek 0:ea088908ad26 74 volatile uint8_t messageNumbers[MAX_DEVICES];
lukas_formanek 3:7a3ddda464bf 75 volatile uint8_t messageNumber; /**< My message number */
lukas_formanek 0:ea088908ad26 76 volatile uint8_t ledState;
lukas_formanek 0:ea088908ad26 77 volatile float timeOnAirSec;
lukas_formanek 3:7a3ddda464bf 78 volatile bool receivedAck;
lukas_formanek 3:7a3ddda464bf 79 volatile bool sendingAck;
lukas_formanek 3:7a3ddda464bf 80 volatile uint8_t sendCounter;
lukas_formanek 8:5d99fbf255d6 81 volatile bool writeDataToSD;
lukas_formanek 5:19b34c4d27a1 82
lukas_formanek 3:7a3ddda464bf 83 float CalculateRandomTime();
lukas_formanek 3:7a3ddda464bf 84 void InitRandom();
lukas_formanek 0:ea088908ad26 85 void OnLedTick();
lukas_formanek 3:7a3ddda464bf 86 void SendMessage();
lukas_formanek 0:ea088908ad26 87 void SendAck(uint8_t addr, uint8_t messageNumber);
lukas_formanek 3:7a3ddda464bf 88 void OnCheckAck();
lukas_formanek 3:7a3ddda464bf 89 void OnSendAgain();
lukas_formanek 0:ea088908ad26 90 public:
lukas_formanek 0:ea088908ad26 91 RFM95W();
lukas_formanek 0:ea088908ad26 92 void Init();
lukas_formanek 0:ea088908ad26 93 void OnTxDone( void );
lukas_formanek 0:ea088908ad26 94 void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
lukas_formanek 0:ea088908ad26 95 void OnTxTimeout( void );
lukas_formanek 0:ea088908ad26 96 void OnRxTimeout( void );
lukas_formanek 0:ea088908ad26 97 void OnRxError( void );
lukas_formanek 5:19b34c4d27a1 98 void OnCadDone( bool channelActivityDetected );
lukas_formanek 3:7a3ddda464bf 99 void SendValue(uint8_t addr, float value);
lukas_formanek 4:e20eb5efd859 100 void SendValue(uint8_t addr, int value);
lukas_formanek 4:e20eb5efd859 101 void SendMessage(char* message);
lukas_formanek 8:5d99fbf255d6 102
lukas_formanek 8:5d99fbf255d6 103 void WriteDataToSDcard();
lukas_formanek 11:376bfcdda0d4 104 bool ReceivedMessage();
lukas_formanek 0:ea088908ad26 105 };
lukas_formanek 0:ea088908ad26 106 extern RFM95W rfm;
lukas_formanek 0:ea088908ad26 107
lukas_formanek 0:ea088908ad26 108 #endif