Send DHT11 & SHT10 sensors data through LoRa SX1272 board.

Dependencies:   DHT11 SHTx SX1272Lib mbed

Fork of SX1272-Transmitter by Antoine Boisadam

Committer:
Antoine38
Date:
Mon Mar 13 14:25:24 2017 +0000
Revision:
15:24dc42e5d7bf
Parent:
14:62c3fd006150
Child:
16:80f027a8b2bc
removing useless state declarations

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GregCr 0:1ed39951ab7b 1 #include "mbed.h"
GregCr 4:5ece30264cd9 2 #include "main.h"
GregCr 13:edb9b443c1dd 3 #include "sx1272-hal.h"
GregCr 8:f956dee63a56 4 #include "debug.h"
GregCr 0:1ed39951ab7b 5
GregCr 0:1ed39951ab7b 6 /* Set this flag to '1' to display debug messages on the console */
GregCr 13:edb9b443c1dd 7 #define DEBUG_MESSAGE 1
GregCr 0:1ed39951ab7b 8
GregCr 0:1ed39951ab7b 9
Antoine38 14:62c3fd006150 10 #define RF_FREQUENCY 868000000 // Hz
Antoine38 14:62c3fd006150 11 #define TX_OUTPUT_POWER 14 // 14 dBm
GregCr 0:1ed39951ab7b 12
Antoine38 14:62c3fd006150 13 #define LORA_BANDWIDTH 2 // [0: 125 kHz,
Antoine38 15:24dc42e5d7bf 14 // 1: 250 kHz,
Antoine38 15:24dc42e5d7bf 15 // 2: 500 kHz,
Antoine38 15:24dc42e5d7bf 16 // 3: Reserved]
Antoine38 15:24dc42e5d7bf 17
Antoine38 14:62c3fd006150 18 #define LORA_SPREADING_FACTOR 7 // [SF7..SF12]
Antoine38 14:62c3fd006150 19 #define LORA_CODINGRATE 1 // [1: 4/5,
Antoine38 15:24dc42e5d7bf 20 // 2: 4/6,
Antoine38 15:24dc42e5d7bf 21 // 3: 4/7,
Antoine38 15:24dc42e5d7bf 22 // 4: 4/8]
Antoine38 15:24dc42e5d7bf 23
Antoine38 14:62c3fd006150 24 #define LORA_PREAMBLE_LENGTH 8
Antoine38 14:62c3fd006150 25 #define LORA_SYMBOL_TIMEOUT 5 // Symbols
Antoine38 14:62c3fd006150 26 #define LORA_FIX_LENGTH_PAYLOAD_ON false
Antoine38 14:62c3fd006150 27 #define LORA_FHSS_ENABLED false
Antoine38 14:62c3fd006150 28 #define LORA_NB_SYMB_HOP 4
Antoine38 14:62c3fd006150 29 #define LORA_IQ_INVERSION_ON false
Antoine38 14:62c3fd006150 30 #define LORA_CRC_ENABLED true
GregCr 0:1ed39951ab7b 31
Antoine38 14:62c3fd006150 32 #define BUFFER_SIZE 32 // Define the payload size here
GregCr 0:1ed39951ab7b 33
GregCr 3:8b9e2a4df4b5 34 DigitalOut led(LED1);
GregCr 3:8b9e2a4df4b5 35
mluis 10:7af820d1e1df 36 /*!
mluis 10:7af820d1e1df 37 * Radio events function pointer
mluis 10:7af820d1e1df 38 */
mluis 10:7af820d1e1df 39 static RadioEvents_t RadioEvents;
mluis 10:7af820d1e1df 40
mluis 10:7af820d1e1df 41 /*
mluis 10:7af820d1e1df 42 * Global variables declarations
mluis 10:7af820d1e1df 43 */
GregCr 13:edb9b443c1dd 44 SX1272MB2xAS Radio( NULL );
GregCr 0:1ed39951ab7b 45
Antoine38 15:24dc42e5d7bf 46 const uint8_t msg[] = "Temp=184.26 \r\nHumi=423.99 \r\n";
GregCr 0:1ed39951ab7b 47
GregCr 0:1ed39951ab7b 48 uint16_t BufferSize = BUFFER_SIZE;
GregCr 0:1ed39951ab7b 49 uint8_t Buffer[BUFFER_SIZE];
GregCr 0:1ed39951ab7b 50
GregCr 5:f2431c4fe3bb 51 int16_t RssiValue = 0.0;
GregCr 5:f2431c4fe3bb 52 int8_t SnrValue = 0.0;
GregCr 0:1ed39951ab7b 53
Antoine38 14:62c3fd006150 54 int main()
GregCr 0:1ed39951ab7b 55 {
GregCr 0:1ed39951ab7b 56 uint8_t i;
Antoine38 14:62c3fd006150 57
Antoine38 14:62c3fd006150 58 debug( "\n\n\r iGreenhouse Application - Transmitter \n\n\r" );
mluis 10:7af820d1e1df 59
mluis 10:7af820d1e1df 60 // Initialize Radio driver
mluis 10:7af820d1e1df 61 RadioEvents.TxDone = OnTxDone;
mluis 10:7af820d1e1df 62 RadioEvents.TxTimeout = OnTxTimeout;
mluis 10:7af820d1e1df 63 Radio.Init( &RadioEvents );
Antoine38 14:62c3fd006150 64
GregCr 7:c1bbd6c56979 65 // verify the connection with the board
Antoine38 14:62c3fd006150 66 while( Radio.Read( REG_VERSION ) == 0x00 ) {
GregCr 7:c1bbd6c56979 67 debug( "Radio could not be detected!\n\r", NULL );
GregCr 7:c1bbd6c56979 68 wait( 1 );
GregCr 2:59e108728d71 69 }
Antoine38 14:62c3fd006150 70
GregCr 13:edb9b443c1dd 71 debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1272MB2XAS ) ) , "\n\r > Board Type: SX1272MB2xAS < \n\r" );
GregCr 0:1ed39951ab7b 72
Antoine38 14:62c3fd006150 73 Radio.SetChannel( RF_FREQUENCY );
Antoine38 14:62c3fd006150 74
Antoine38 14:62c3fd006150 75
GregCr 7:c1bbd6c56979 76 debug_if( LORA_FHSS_ENABLED, "\n\n\r > LORA FHSS Mode < \n\n\r");
GregCr 7:c1bbd6c56979 77 debug_if( !LORA_FHSS_ENABLED, "\n\n\r > LORA Mode < \n\n\r");
GregCr 7:c1bbd6c56979 78
GregCr 0:1ed39951ab7b 79 Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
Antoine38 14:62c3fd006150 80 LORA_SPREADING_FACTOR, LORA_CODINGRATE,
Antoine38 14:62c3fd006150 81 LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
Antoine38 14:62c3fd006150 82 LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
Antoine38 14:62c3fd006150 83 LORA_IQ_INVERSION_ON, 2000000 );
GregCr 0:1ed39951ab7b 84
Antoine38 14:62c3fd006150 85 debug_if( DEBUG_MESSAGE, "Starting sending loop\r\n" );
GregCr 0:1ed39951ab7b 86
GregCr 3:8b9e2a4df4b5 87 led = 0;
Antoine38 14:62c3fd006150 88
Antoine38 14:62c3fd006150 89 while( 1 ) {
Antoine38 14:62c3fd006150 90 debug("\r\n========\r\nSending a new Packet\r\n========\r\n");
Antoine38 15:24dc42e5d7bf 91 strcpy( ( char* )Buffer, ( char* )msg );
Antoine38 14:62c3fd006150 92 // We fill the buffer with numbers for the payload
Antoine38 14:62c3fd006150 93 for( i = 4; i < BufferSize; i++ ) {
Antoine38 14:62c3fd006150 94 Buffer[i] = i - 4;
Antoine38 14:62c3fd006150 95 }
Antoine38 14:62c3fd006150 96 wait_ms( 10 );
Antoine38 14:62c3fd006150 97 Radio.Send( Buffer, BufferSize );
Antoine38 15:24dc42e5d7bf 98 wait(3);
GregCr 0:1ed39951ab7b 99 }
GregCr 0:1ed39951ab7b 100 }
GregCr 0:1ed39951ab7b 101
GregCr 0:1ed39951ab7b 102 void OnTxDone( void )
GregCr 0:1ed39951ab7b 103 {
GregCr 5:f2431c4fe3bb 104 Radio.Sleep( );
GregCr 7:c1bbd6c56979 105 debug_if( DEBUG_MESSAGE, "> OnTxDone\n\r" );
GregCr 0:1ed39951ab7b 106 }
GregCr 0:1ed39951ab7b 107
GregCr 0:1ed39951ab7b 108 void OnTxTimeout( void )
GregCr 0:1ed39951ab7b 109 {
GregCr 0:1ed39951ab7b 110 Radio.Sleep( );
GregCr 7:c1bbd6c56979 111 debug_if( DEBUG_MESSAGE, "> OnTxTimeout\n\r" );
GregCr 0:1ed39951ab7b 112 }
GregCr 0:1ed39951ab7b 113