end node on synchronous star LoRa network.

Dependencies:   SX127x sx12xx_hal TSL2561

radio chip selection

Radio chip driver is not included, allowing choice of radio device.
If you're using SX1272 or SX1276, then import sx127x driver into your program.
if you're using SX1261 or SX1262, then import sx126x driver into your program.
if you're using SX1280, then import sx1280 driver into your program.
If you're using NAmote72 or Murata discovery, then you must import only sx127x driver.

This project for use with LoRaWAN_singlechannel_gateway project.

Alternately gateway running on raspberry pi can be used as gateway.

LoRaWAN on single radio channel

Network description is at gateway project page. Synchronous star network.

Hardware Support

This project supports SX1276 and SX1272, sx126x kit, sx126x shield, and sx128x 2.4GHz. The ST board B-L072Z-LRWAN1 is also supported (TypeABZ module). When B-L072Z-LRWAN1 target is selected, TARGET_DISCO_L072CZ_LRWAN1 is defined by tools, allowing correct radio driver configuration for this platform. Alternately, any mbed board that can use LoRa radio shield board should work, but NUCLEO boards are tested.

End-node Unique ID

DevEUI is created from CPU serial number. AppEUI and AppKey are declared as software constants.

End-node Configuration

Data rate definition LORAMAC_DEFAULT_DATARATE configured in LoRaMac-definitions.h. See gateway project page for configuration of gateway.
LoRaWAN addressing is configured in Comissioning.h; only OTA mode is functional.
Header file board/lora_config.h, selects application layer options (i.e. sensors) to be compiled in.

Serial Interface

Serial port operates at 115200bps.
Application layer single_us915_main.cpp User button triggers uplink (i.e. blue button on nucleo board), or jumper enables continuously sends repeated uplink packets. The MAC layer holds each uplink request until the allocated timeslot.

commandargumentsdescription
?-print available commands
. (period)-print status (DevEUI, DevAddr, etc)
ullength integerset payload length of test uplink packets

sensor demo

Selected grove sensors may be plugged into SX1272 shield.
To enable, edit lora_config.h to define SENSORS.

Sensor connections on SX1272MB2xAS:

D8 D9: buttonRX TX: (unused)A3 A4: Rotary Angle Sensor
D6 D7: RGB LEDSCL SDA: digital light sensorA1 A2: Rotary Angle Sensor

Digital input pin, state reported via uplink: PC8
Digital output pin, controlled via downlink: PC6
PWM out: PB_10

Jumper enables auto-repeated transmit: PC10 and PC12 on NUCLEO board, located on end of morpho headers nearby JP4.

Revision:
23:a862b5601663
Parent:
22:999a7e7698a8
Child:
24:94ea42eb6b9e
--- a/app/single_us915_main.cpp	Mon Aug 07 13:01:48 2017 -0700
+++ b/app/single_us915_main.cpp	Tue Aug 08 15:16:37 2017 -0700
@@ -20,26 +20,44 @@
 #include "Commissioning.h"
 #include "commands.h"
 
-#if defined(ENABLE_SX1272) && defined(SENSORS)
-    #include "ChainableLED.h"
+#ifdef ENABLE_LUMINOSITY
     #include "TSL2561.h"
-    InterruptIn user_button(USER_BUTTON);
-    #define RED_LED_RATE_US     333333  /* third of second */
-    uint32_t button_cnt;
-    ChainableLED rgb(D6, D7, 1); // https://developer.mbed.org/components/Grove-Chainable-RGB-LED/
-    AnalogIn a1(A1); // https://developer.mbed.org/teams/Seeed/wiki/Potentiometer
-    AnalogIn a3(A3); // https://developer.mbed.org/teams/Seeed/wiki/Potentiometer
-    DigitalIn pc8_in(PC_8);
-    DigitalOut pc6_out(PC_6);   
     //TSL2561 tsl2561(TSL2561_ADDR_FLOAT); // https://developer.mbed.org/components/Grove-Digital-Light-Sensor/ 
     TSL2561 tsl2561(TSL2561_ADDR_LOW);
-    PwmOut pwm(PB_11);
+#endif
+
+#ifdef ENABLE_RGB
+    #include "ChainableLED.h"
+    ChainableLED rgb(D6, D7, 1); // https://developer.mbed.org/components/Grove-Chainable-RGB-LED/
 #endif
 
+#ifdef SENSORS
+    InterruptIn user_button(USER_BUTTON);
+    uint32_t button_cnt;
+    #ifdef TYPE_ABZ /* DISCO_L072CZ_LRWAN1 */
+        PwmOut pwm(PB_5);
+        DigitalIn pc8_in(PB_13);
+        DigitalOut pc6_out(PB_14);   
+        AnalogIn a0(PA_0);
+        AnalogIn a2(PA_4);
+    #else
+        PwmOut pwm(PB_11);
+        DigitalIn pc8_in(PC_8);
+        DigitalOut pc6_out(PC_6);   
+        AnalogIn a1(A1); // https://developer.mbed.org/teams/Seeed/wiki/Potentiometer
+        AnalogIn a3(A3); // https://developer.mbed.org/teams/Seeed/wiki/Potentiometer
+    #endif
+#endif /* SENSORS */
+
 DigitalOut pc2(PC_2);
 
-DigitalOut jumper_out(PC_10);
-InterruptIn jumper_in(PC_12);
+#if defined(TARGET_DISCO_L072CZ_LRWAN1) || ( defined(TARGET_NUCLEO_L073RZ) && defined(TYPE_ABZ) )
+    DigitalOut jumper_out(PA_11);
+    InterruptIn jumper_in(PA_12);
+#else
+    DigitalOut jumper_out(PC_10);
+    InterruptIn jumper_in(PC_12);
+#endif /* murata */
 
 char pcbuf[128];
 int pcbuf_len;
@@ -100,7 +118,7 @@
 /*!
  * Application port
  */
-#if defined(SENSORS) && defined(ENABLE_SX1272)
+#if defined(SENSORS)
     static uint8_t AppPort = SENSOR_PORT;
 #else
     static uint8_t AppPort = LORAWAN_APP_PORT;
@@ -209,12 +227,20 @@
             }
         }
         break;
-#if defined(SENSORS) && defined(ENABLE_SX1272)
+#if defined(SENSORS)
     case SENSOR_PORT:
         {
-            uint16_t x = tsl2561.getLuminosity(TSL2561_VISIBLE);
+            uint16_t x = 0;
+#ifdef ENABLE_LUMINOSITY
+            x = tsl2561.getLuminosity(TSL2561_VISIBLE);
+#endif
+#ifdef TYPE_ABZ
+            uint16_t a_1 = a0.read_u16();
+            uint16_t a_3 = a2.read_u16();
+#else
             uint16_t a_1 = a1.read_u16();
             uint16_t a_3 = a3.read_u16();
+#endif
             uint8_t status;
             status = pc8_in.read();
             status <<= 1;
@@ -230,7 +256,7 @@
             //printf("visible:%u\r\n", x);
         }
         break;
-#endif /* SENSORS && ENABLE_SX1272 */
+#endif /* SENSORS */
     default:
         break;
     }
@@ -573,7 +599,7 @@
         switch (mcpsIndication->Buffer[0]) {
             default:
             case CMD_NONE: break;
-#if defined(SENSORS) && defined(ENABLE_SX1272)        
+#if defined (ENABLE_RGB)
             case CMD_LED_RGB:
                 rgb.setColorRGB(0, 
                     mcpsIndication->Buffer[1],  // R
@@ -586,6 +612,8 @@
                     mcpsIndication->Buffer[3]
                 );
                 break;
+#endif /* ENABLE_RGB */
+#if defined(SENSORS)
             case CMD_GPIO_OUT:
                 pc6_out = mcpsIndication->Buffer[1];
                 isr_printf("gpo %d\r\n", mcpsIndication->Buffer[1]);
@@ -595,7 +623,7 @@
                 pwm.write(mcpsIndication->Buffer[2] / 255.0);
                 isr_printf("pwm %u %u\r\n", mcpsIndication->Buffer[1], mcpsIndication->Buffer[2]);
                 break;
-#endif /* SENSORS && ENABLE_SX1272 */
+#endif /* SENSORS */
             case CMD_TX_POWER:
                 isr_printf("txp %u\r\n", mcpsIndication->Buffer[1]);
                 mibReq.Type = MIB_CHANNELS_TX_POWER;
@@ -753,8 +781,12 @@
     LoRaMacMibGetRequestConfirm( &mibReq );         
     isr_printf(", DevAddr:%x\r\n", mibReq.Param.DevAddr);
     
-#if defined(SENSORS) && defined(ENABLE_SX1272)
-    isr_printf("a1:%u a3:%u\r\n", a1.read_u16(), a3.read_u16());
+#if defined(SENSORS)
+    #ifdef TYPE_ABZ
+        isr_printf("a0:%u a2:%u\r\n", a0.read_u16(), a2.read_u16());
+    #else
+        isr_printf("a1:%u a3:%u\r\n", a1.read_u16(), a3.read_u16());
+    #endif
     isr_printf("button:%d,%u ", user_button.read(), button_cnt);
 #endif
     isr_printf("DEVICE_STATE_");
@@ -781,7 +813,7 @@
     isr_printf("uplink_length:%u\r\n", uplink_length);
 }
 
-#if defined(SENSORS) && defined(ENABLE_SX1272)
+#if defined(ENABLE_RGB)
 void cmd_rgb(uint8_t idx)
 {
     int r, g, b;
@@ -789,7 +821,9 @@
     rgb.setColorRGB(0, r, g, b);
     isr_printf("\r\nrgb: %d %d %d\r\n", r, g, b);
 }
+#endif /* ENABLE_RGB */
 
+#if defined(SENSORS)
 void cmd_pwm(uint8_t idx)
 {
     float period, duty;
@@ -839,10 +873,12 @@
     { ".", cmd_status, "","print status"}, 
     { "ul", cmd_uplink_length, "%u","set uplink payload length"}, 
     { "ctxp", cmd_ChannelsTxPower, "%u","get/set ChannelsTxPower"},
-#if defined(SENSORS) && defined(ENABLE_SX1272)
+#if defined(ENABLE_RGB)
     { "rgb", cmd_rgb, "%d %d %d", "set led R G B"},
+#endif
+#if defined(SENSORS)
     { "p", cmd_pwm, "%u %u", "set pwm period, duty"},
-#endif
+#endif /* SENSORS */
     { NULL, NULL, NULL, NULL }
 };
 
@@ -932,7 +968,7 @@
 }
 
 
-#if defined(SENSORS) && defined(ENABLE_SX1272)
+#if defined(SENSORS)
 void button_isr()
 {
     button_cnt++;
@@ -960,13 +996,13 @@
 
     DeviceState = DEVICE_STATE_INIT;
     
-#if defined(SENSORS) && defined(ENABLE_SX1272)
     while (!user_button) {
         printf("button-lo\r\n");
         wait(0.01);
     }
     user_button.fall(&button_isr);
     
+#ifdef ENABLE_LUMINOSITY
     isr_printf("TSL2561 Sensor ");
     if (tsl2561.begin()) {    
         isr_printf("Found\r\n");        
@@ -983,7 +1019,7 @@
     //tsl2561.setTiming(TSL2561_INTEGRATIONTIME_13MS);  // shortest integration time (bright tsl2561)
     //tsl2561.setTiming(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium tsl2561)
     tsl2561.setTiming(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim tsl2561)    
-#endif /* SENSORS && ENABLE_SX1272 */
+#endif /* ENABLE_LUMINOSITY */
 
     jumper_out = 1;
     jumper_in.mode(PullDown);
@@ -998,7 +1034,7 @@
             case DEVICE_STATE_INIT:
             {
                 isr_printf("DEVICE_STATE_INIT\r\n");
-#if defined(SENSORS) && defined(ENABLE_SX1272)
+#if defined(SENSORS)
                 uplink_length = 7;
 #else                
                 uplink_length = 2;