Lora

Dependents:   STEM_2019 STEM_2020

Files at this revision

API Documentation at this revision

Comitter:
dsubotic
Date:
Tue Jan 28 09:55:09 2020 +0000
Commit message:
LoRaWAN driver

Changed in this revision

LoRaWAN.cpp Show annotated file Show diff for this revision Revisions of this file
LoRaWAN.h Show annotated file Show diff for this revision Revisions of this file
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++;
+        }
+    }
+}
+
+
diff -r 000000000000 -r 8f220b16e069 LoRaWAN.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LoRaWAN.h	Tue Jan 28 09:55:09 2020 +0000
@@ -0,0 +1,37 @@
+#ifndef MBED_LoRaWAN_H
+#define MBED_LoRaWAN_H
+
+#include "mbed.h"
+
+#define UART_RX            PD_2 
+#define UART_TX            PC_12 
+
+#define appEUI       "AT+APPEUI=70B3D57ED0029683"
+#define appKEY       "AT+APPKEY=7383F39F198AF48F47406485AB28AF5D"
+#define join         "AT+JOIN"
+#define reboot       "AT+NRB"
+
+class LoRaWAN {
+    private:
+        Serial serial_lora;
+        
+    public:
+        /** Initialize object with default uart pins */
+        LoRaWAN();
+        
+        /** Initialize object with specific uart pins */
+        LoRaWAN(PinName USART_TX, PinName USART_RX);
+        
+        /** Boot up the communication and checks if acking */
+        bool init();
+        
+        /** Send LoraWAN message */
+        bool sendMessage(char *data_buf);
+        
+        /** recieve data from the LoRaWAN module */
+        void recieveData(char *data_buf, int numchar);
+        
+        
+};
+
+#endif
\ No newline at end of file