老 姚
/
LoRaTest
Lora interface demo
modular2 is an modular computer run Mbed OS ,this is LoRa LM005A test demo
main.cpp
- Committer:
- yao6116601
- Date:
- 2018-04-19
- Revision:
- 0:4c0aba0c6eb1
File content as of revision 0:4c0aba0c6eb1:
#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 } }