Lora

Dependents:   STEM_2019 STEM_2020

Revision:
0:8f220b16e069
diff -r 000000000000 -r 8f220b16e069 LoRaWAN.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LoRaWAN.cpp	Tue Jan 28 09:55:09 2020 +0000
@@ -0,0 +1,48 @@
+#include "LoRaWAN.h"
+
+LoRaWAN::LoRaWAN() : serial_lora(UART_TX,UART_RX) {}
+LoRaWAN::LoRaWAN(PinName USART_TX, PinName USART_RX) : serial_lora(USART_TX,USART_RX) {}
+
+bool LoRaWAN::init(){
+    serial_lora.baud(9600);
+    if(!sendMessage(reboot)){
+        return false;
+    }
+    wait(2);
+    if(!sendMessage(appEUI)){
+        return false;
+    }
+    wait(0.5);
+    if(!sendMessage(appKEY)){
+        return false;
+    }
+    wait(0.5);
+    if(!sendMessage(join)){
+        return false;
+    }
+    wait(4);
+    return true;
+}   
+    
+bool LoRaWAN::sendMessage(char *data_buf)
+{
+    serial_lora.printf("%s\r\n",data_buf);
+    return true;
+}
+
+void LoRaWAN::recieveData(char *data_buf, int numchar)
+{
+    int count=0;
+    if(numchar == 0) {
+        numchar = sizeof(data_buf);
+    }
+    while(numchar!=count) {
+        if(serial_lora.readable()) {
+            *data_buf = serial_lora.getc();
+            data_buf+=1;
+            count++;
+        }
+    }
+}
+
+