Lora
Dependents: STEM_2019 STEM_2020
LoRaWAN.cpp@0:8f220b16e069, 2020-01-28 (annotated)
- Committer:
- dsubotic
- Date:
- Tue Jan 28 09:55:09 2020 +0000
- Revision:
- 0:8f220b16e069
LoRaWAN driver
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dsubotic | 0:8f220b16e069 | 1 | #include "LoRaWAN.h" |
dsubotic | 0:8f220b16e069 | 2 | |
dsubotic | 0:8f220b16e069 | 3 | LoRaWAN::LoRaWAN() : serial_lora(UART_TX,UART_RX) {} |
dsubotic | 0:8f220b16e069 | 4 | LoRaWAN::LoRaWAN(PinName USART_TX, PinName USART_RX) : serial_lora(USART_TX,USART_RX) {} |
dsubotic | 0:8f220b16e069 | 5 | |
dsubotic | 0:8f220b16e069 | 6 | bool LoRaWAN::init(){ |
dsubotic | 0:8f220b16e069 | 7 | serial_lora.baud(9600); |
dsubotic | 0:8f220b16e069 | 8 | if(!sendMessage(reboot)){ |
dsubotic | 0:8f220b16e069 | 9 | return false; |
dsubotic | 0:8f220b16e069 | 10 | } |
dsubotic | 0:8f220b16e069 | 11 | wait(2); |
dsubotic | 0:8f220b16e069 | 12 | if(!sendMessage(appEUI)){ |
dsubotic | 0:8f220b16e069 | 13 | return false; |
dsubotic | 0:8f220b16e069 | 14 | } |
dsubotic | 0:8f220b16e069 | 15 | wait(0.5); |
dsubotic | 0:8f220b16e069 | 16 | if(!sendMessage(appKEY)){ |
dsubotic | 0:8f220b16e069 | 17 | return false; |
dsubotic | 0:8f220b16e069 | 18 | } |
dsubotic | 0:8f220b16e069 | 19 | wait(0.5); |
dsubotic | 0:8f220b16e069 | 20 | if(!sendMessage(join)){ |
dsubotic | 0:8f220b16e069 | 21 | return false; |
dsubotic | 0:8f220b16e069 | 22 | } |
dsubotic | 0:8f220b16e069 | 23 | wait(4); |
dsubotic | 0:8f220b16e069 | 24 | return true; |
dsubotic | 0:8f220b16e069 | 25 | } |
dsubotic | 0:8f220b16e069 | 26 | |
dsubotic | 0:8f220b16e069 | 27 | bool LoRaWAN::sendMessage(char *data_buf) |
dsubotic | 0:8f220b16e069 | 28 | { |
dsubotic | 0:8f220b16e069 | 29 | serial_lora.printf("%s\r\n",data_buf); |
dsubotic | 0:8f220b16e069 | 30 | return true; |
dsubotic | 0:8f220b16e069 | 31 | } |
dsubotic | 0:8f220b16e069 | 32 | |
dsubotic | 0:8f220b16e069 | 33 | void LoRaWAN::recieveData(char *data_buf, int numchar) |
dsubotic | 0:8f220b16e069 | 34 | { |
dsubotic | 0:8f220b16e069 | 35 | int count=0; |
dsubotic | 0:8f220b16e069 | 36 | if(numchar == 0) { |
dsubotic | 0:8f220b16e069 | 37 | numchar = sizeof(data_buf); |
dsubotic | 0:8f220b16e069 | 38 | } |
dsubotic | 0:8f220b16e069 | 39 | while(numchar!=count) { |
dsubotic | 0:8f220b16e069 | 40 | if(serial_lora.readable()) { |
dsubotic | 0:8f220b16e069 | 41 | *data_buf = serial_lora.getc(); |
dsubotic | 0:8f220b16e069 | 42 | data_buf+=1; |
dsubotic | 0:8f220b16e069 | 43 | count++; |
dsubotic | 0:8f220b16e069 | 44 | } |
dsubotic | 0:8f220b16e069 | 45 | } |
dsubotic | 0:8f220b16e069 | 46 | } |
dsubotic | 0:8f220b16e069 | 47 | |
dsubotic | 0:8f220b16e069 | 48 |