application layer with: button, LED, pot, tempSense

Dependencies:   mbed SX1272Lib

Fork of LoRaWAN-demo-72-bootcamp by Semtech

Use with sx1272 shield with grove peripherals connected:

D8 D9: ButtonRX TXA3 A4: TempSense
D6 D7:SCL SDA : LEDA1 A2: Pot

Button

Sends to different payloads: short press (under 1 sec)
long press: held down > 1 sec.

serial console keys

115200bps, 8N1
Enter key not used
Keys '0' to '3': cayenne channel number
'0': pot (rotary sensor)
'1': temperature
' 2': digital out
'3': analog out

Files at this revision

API Documentation at this revision

Comitter:
Wayne Roberts
Date:
Tue Feb 20 22:16:57 2018 +0000
Parent:
13:f88dd77772b6
Commit message:
add frame count to digital input

Changed in this revision

app/main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/app/main.cpp	Wed Feb 14 14:03:42 2018 -0800
+++ b/app/main.cpp	Tue Feb 20 22:16:57 2018 +0000
@@ -226,6 +226,12 @@
 void LoRaMacStatus_toString(LoRaMacStatus_t s, char* out)
 {
     switch (s) {
+        case LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR:
+            strcpy(out, "MAC_CMD_LENGTH_ERROR");
+            break;
+        case LORAMAC_STATUS_LENGTH_ERROR:
+            strcpy(out, "LENGTH_ERROR");
+            break;
         case LORAMAC_STATUS_PARAMETER_INVALID:
             strcpy(out, "PARAMTER_INVALID");
             break;
@@ -251,7 +257,8 @@
     McpsReq_t mcpsReq;
     LoRaMacTxInfo_t txInfo;
 
-    if( LoRaMacQueryTxPossible( len, &txInfo ) != LORAMAC_STATUS_OK ) {
+    status = LoRaMacQueryTxPossible( len, &txInfo );
+    if (status != LORAMAC_STATUS_OK) {
         // Send empty frame in order to flush MAC commands
         mcpsReq.Type = MCPS_UNCONFIRMED;
         mcpsReq.Req.Unconfirmed.fBuffer = NULL;
@@ -263,6 +270,11 @@
         LoRaMacUplinkStatus.Buffer = NULL;
         LoRaMacUplinkStatus.BufferSize = 0;
         SerialDisplayUpdateFrameType( false );
+
+
+        vt.SetCursorPos( 41, 1 );
+        LoRaMacStatus_toString(status, str);
+        vt.printf("%s\e[K", str);
     } else {
         LoRaMacUplinkStatus.Acked = false;
         LoRaMacUplinkStatus.Port = AppPort;
@@ -290,7 +302,7 @@
     status = LoRaMacMcpsRequest( &mcpsReq );
     if (status == LORAMAC_STATUS_OK) {
         vt.SetCursorPos( 44, 1 );
-        vt.printf("%u sendFrame() OK\e[K", sendCnt);
+        vt.printf("%u sendFrame() OK %u\e[K", sendCnt, len);
         SerialDisplayUpdateUplink(
             LoRaMacUplinkStatus.Acked,
             LoRaMacUplinkStatus.Datarate,
@@ -394,6 +406,7 @@
 #define CAYENNE_CH_AOUT     3
 #define CAYENNE_CH_TEMP     0
 #define CAYENNE_CH_POT      1
+#define CAYENNE_CH_DIN      4
 AnalogIn a1(A1);
 AnalogIn a2(A2);
 AnalogIn a3(A3);
@@ -406,6 +419,7 @@
 volatile TimerTime_t buttonStartAt;
 DigitalIn d8(D8);
 DigitalOut extLed(D15);
+volatile bool extLedSet;
 PwmOut pwm(PB_11);
 
 volatile int cayenne_ack_ch;
@@ -416,6 +430,7 @@
 {
     uint16_t u16, rot;
     float t, f, R;
+    static uint8_t seq;
 
     if (c_ch != 0xff) {
         gAppDataSize = 0;
@@ -501,11 +516,20 @@
             AppData[gAppDataSize++] = rot >> 8;
             AppData[gAppDataSize++] = rot;
 
-            AppData[gAppDataSize++] = CAYENNE_CH_DOUT;
-            AppData[gAppDataSize++] = LPP_DIGITAL_OUTPUT;
-            AppData[gAppDataSize++] = extLed.read();
+
+            if (extLedSet) {
+                AppData[gAppDataSize++] = CAYENNE_CH_DOUT;
+                AppData[gAppDataSize++] = LPP_DIGITAL_OUTPUT;
+                AppData[gAppDataSize++] = extLed.read();
+                extLedSet = false;
+            } else {
+                AppData[gAppDataSize++] = CAYENNE_CH_DIN;
+                AppData[gAppDataSize++] = LPP_DIGITAL_INPUT;
+                AppData[gAppDataSize++] = seq++;
+            }
             vt.SetCursorPos( 41, 1 );
-            vt.printf("u16:%u, f:%f, rot:%u t:%.1f\e[K", u16, f, rot, t);
+
+            vt.printf("u16:%u, f:%f, rot:%u t:%.1f (%u)\e[K", u16, f, rot, t, seq);
             break;
         case 224:
             if( ComplianceTest.LinkCheck == true ) {
@@ -691,6 +715,7 @@
             switch (mcpsIndication->Buffer[n]) {
                 case CAYENNE_CH_DOUT:
                     extLed.write(val);
+                    extLedSet = true;
                     break;
                 case CAYENNE_CH_AOUT:
                     pwm.write(val / 100.0);