Committer:
gov1
Date:
Tue Jul 31 16:36:17 2018 +0000
Revision:
0:b24cccf38c35
LoRa/WiFi Gateway Code, MAX32620FTHR Side

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gov1 0:b24cccf38c35 1 #include "mbed.h"
gov1 0:b24cccf38c35 2 #include "LoRa.h"
gov1 0:b24cccf38c35 3 #include "UARTSerial.h"
gov1 0:b24cccf38c35 4
gov1 0:b24cccf38c35 5 DigitalOut idle(LED2);
gov1 0:b24cccf38c35 6 DigitalOut receiving(LED1);
gov1 0:b24cccf38c35 7
gov1 0:b24cccf38c35 8 Serial pc(USBTX, USBRX);
gov1 0:b24cccf38c35 9 Serial _serial(P3_1, P3_0,9600);
gov1 0:b24cccf38c35 10
gov1 0:b24cccf38c35 11
gov1 0:b24cccf38c35 12 int counter = 0;
gov1 0:b24cccf38c35 13
gov1 0:b24cccf38c35 14 void onReceive(int packetSize);
gov1 0:b24cccf38c35 15
gov1 0:b24cccf38c35 16 main()
gov1 0:b24cccf38c35 17 {
gov1 0:b24cccf38c35 18 // setup
gov1 0:b24cccf38c35 19 pc.printf("LoRa Callback Rx . . .\n");
gov1 0:b24cccf38c35 20 if (!LoRa.begin(915E6))
gov1 0:b24cccf38c35 21 {
gov1 0:b24cccf38c35 22 pc.printf("LoRa Radio not Found!\n");
gov1 0:b24cccf38c35 23 } else {
gov1 0:b24cccf38c35 24 pc.printf("LoRa Radio Started.\n");
gov1 0:b24cccf38c35 25 }
gov1 0:b24cccf38c35 26 idle = true;
gov1 0:b24cccf38c35 27 LoRa.onReceive(onReceive);
gov1 0:b24cccf38c35 28 LoRa.receive();
gov1 0:b24cccf38c35 29
gov1 0:b24cccf38c35 30 //loop
gov1 0:b24cccf38c35 31 while(1)
gov1 0:b24cccf38c35 32 {
gov1 0:b24cccf38c35 33 // do nothing
gov1 0:b24cccf38c35 34 }
gov1 0:b24cccf38c35 35 }
gov1 0:b24cccf38c35 36
gov1 0:b24cccf38c35 37 void onReceive(int packetSize)
gov1 0:b24cccf38c35 38 {
gov1 0:b24cccf38c35 39 idle = false;
gov1 0:b24cccf38c35 40 char msg[45];
gov1 0:b24cccf38c35 41 pc.printf("PACKET RECEIVED, SIZE:%d \n", packetSize);
gov1 0:b24cccf38c35 42 // pc.printf("MSG[0]: %c \n", msg[0]);
gov1 0:b24cccf38c35 43 // pc.printf("MSG[1]: %c \n", msg[1]);
gov1 0:b24cccf38c35 44 // pc.printf("MSG[2]: %c \n", msg[2]);
gov1 0:b24cccf38c35 45 // pc.printf("MSG[3]: %c \n", msg[3]);
gov1 0:b24cccf38c35 46 // pc.printf("MSG[4]: %c \n", msg[4]);
gov1 0:b24cccf38c35 47 for (int i = 0; i<packetSize; i++)
gov1 0:b24cccf38c35 48 {
gov1 0:b24cccf38c35 49 if ( i < 45)
gov1 0:b24cccf38c35 50 {
gov1 0:b24cccf38c35 51 msg[i] = (char)LoRa._getc();
gov1 0:b24cccf38c35 52 }
gov1 0:b24cccf38c35 53 receiving = !receiving;
gov1 0:b24cccf38c35 54 }
gov1 0:b24cccf38c35 55 if (msg[0] == '1')
gov1 0:b24cccf38c35 56 {
gov1 0:b24cccf38c35 57 // indicates this message comes from the canary!
gov1 0:b24cccf38c35 58 pc.printf("received from 0\n");
gov1 0:b24cccf38c35 59 _serial.printf("%s\n", msg);
gov1 0:b24cccf38c35 60 }
gov1 0:b24cccf38c35 61 else {
gov1 0:b24cccf38c35 62 pc.printf("dont know who this was from\n");
gov1 0:b24cccf38c35 63 }
gov1 0:b24cccf38c35 64 pc.printf("MSG: %s, ",msg);
gov1 0:b24cccf38c35 65 pc.printf("RSSI: %d\n", LoRa.packetRssi());
gov1 0:b24cccf38c35 66 // _serial.printf("%s\n", msg);
gov1 0:b24cccf38c35 67 receiving = false;
gov1 0:b24cccf38c35 68 idle = true;
gov1 0:b24cccf38c35 69 }
gov1 0:b24cccf38c35 70