Lora interface demo

Dependencies:   LM005A-driver

modular2 is an modular computer run Mbed OS ,this is LoRa LM005A test demo

Files at this revision

API Documentation at this revision

Comitter:
yao6116601
Date:
Thu Apr 19 13:18:02 2018 +0000
Commit message:
new LoRa

Changed in this revision

LM005A-driver.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 4c0aba0c6eb1 LM005A-driver.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LM005A-driver.lib	Thu Apr 19 13:18:02 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/yao6116601/code/LM005A-driver/#5b5a1b5f1ae4
diff -r 000000000000 -r 4c0aba0c6eb1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Apr 19 13:18:02 2018 +0000
@@ -0,0 +1,105 @@
+#include "mbed.h"
+#include "UDPSocket.h"
+#include "LM005A.h"
+DigitalOut myled(PF_12);
+LM005A Lora(PB_6,PB_7,true);
+DigitalOut Enable(PD_13);
+DigitalOut RST(PD_12);
+#define ECHO_SERVER_PORT   5683
+#define SERVER_ADDR "180.101.147.115"
+Thread recvThread;
+Mutex s;
+int mIndex=0;
+void receive()
+{ char rbuf[32];
+ char sbuf[64];
+int len;
+bool result; 
+    while(true)
+    {
+     s.lock();
+     len=Lora.recv(2,rbuf,2);
+     s.unlock();
+     if (len>0)
+     {
+      printf("receive %d :%0.*s\n",len,len,rbuf); 
+       
+    len= sprintf(sbuf,"Hello guodong Server %d\n",mIndex);mIndex++;
+      s.lock();
+    result= Lora.send(2,1,sbuf,len);
+    s.unlock();
+    if (result)
+       printf("Send successful\n");
+       else
+      printf("send error\n");   
+      }
+    }
+}
+int main() {
+          char buffer[64];
+      int val; 
+      int len;
+      bool result; 
+      const char * ss;  
+      char temp[4];
+       Enable=1;
+      RST=0;
+      RST=1;
+          printf("LM005A LoRa Demo Waiting For boot up ... \n");
+      Lora.setTimeout(55000);    
+     result=Lora.init();  
+     if (result)
+        printf("Lora Modular BootUp\n");
+          ss=Lora.get_firmware_version();
+     printf("firmware  version =%s\n",ss);
+      ss=Lora.getDeviceAddress();
+     printf("device address=%s\n",ss);
+        ss=Lora.getEUI(0);
+     printf("get DEVEUI=%s\n",ss);
+          ss=Lora.getEUI(1);
+     printf("get APPEUI=%s\n",ss);
+        val=Lora.set_mode(0);
+      printf("set Mode %d\n" ,val); 
+         val=Lora.set_class(1);
+      printf("set class %d\n" ,val);  
+          val=Lora.set_power(20);
+      printf("set power %d\n" ,val);
+   //         val=Lora.set_band(0,4715);
+   //   printf("set Fixed band %d\n" ,val);
+   //      Lora.reset();
+       result=Lora.join();
+      if (result)
+       printf("join the network\n");
+     len=  sprintf(buffer,"Hello guodong server " );
+    result= Lora.send(2,0,buffer,len);
+    if (result)
+      printf("send Data\n");
+      else
+      printf("send Data ERROR\n");  
+      myled = 1; 
+      recvThread.start(&receive); 
+    while(1) {
+          wait(20);
+   /*      buffer[0]=0x01; 
+        float a=12.4;
+       memcpy(&temp[0],&a,4);
+       buffer[1]=temp[3];buffer[2]=temp[2];buffer[3]=temp[1];buffer[4]=temp[0];
+        buffer[5]=1;
+        a=2.22;
+        memcpy(&temp[0],&a,4);
+        buffer[6]=temp[3];buffer[7]=temp[2];buffer[8]=temp[1];buffer[9]=temp[0];
+        buffer[10]=2;
+        Lora.send(0x00,0x00,buffer,10);*/
+       // LED is ON
+    /*    s.lock();
+     sprintf(buffer,"HeartBeat\n");
+    result= Lora.send(2,0,buffer,10);
+    s.unlock();
+    if (result)
+       printf("send Data\n");
+       else
+      printf("send Data ERROR\n");  */
+        myled = !myled; // LED is OFF
+       
+    }
+}
diff -r 000000000000 -r 4c0aba0c6eb1 mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Thu Apr 19 13:18:02 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#2b4ff78ab0a52ef1dc3f2998908453c595e2b2c0
\ No newline at end of file