application layer with: button, LED, pot, tempSense
Fork of LoRaWAN-demo-72-bootcamp by
Use with sx1272 shield with grove peripherals connected:
D8 D9: Button | RX TX | A3 A4: TempSense |
D6 D7: | SCL SDA : LED | A1 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
Diff: app/main.cpp
- Revision:
- 13:f88dd77772b6
- Parent:
- 12:662ff73ce484
- Child:
- 14:f8c7c85fc8e8
--- a/app/main.cpp Mon Feb 12 11:25:50 2018 -0800 +++ b/app/main.cpp Wed Feb 14 14:03:42 2018 -0800 @@ -307,15 +307,21 @@ return true; } // ..SendFrame() +char statusTxt[64]; +DigitalOut jumper_out(PC_10); +InterruptIn jumper_in(PC_12); TimerEvent_t event; #define TX_INTERVAL_MS 15000 void autoUplink() { - DeviceState = DEVICE_STATE_SEND; + if (jumper_in.read()) + DeviceState = DEVICE_STATE_SEND; + else { + TimerStop(&event); + sprintf(statusTxt, "timer off"); + } } -char statusTxt[64]; - uint8_t c_ch; void SerialRxProcess( void ) @@ -399,9 +405,9 @@ volatile TimerTime_t buttonStartAt; DigitalIn d8(D8); -DigitalIn userBut(USER_BUTTON); DigitalOut extLed(D15); PwmOut pwm(PB_11); + volatile int cayenne_ack_ch; /*! * \brief Prepares the payload of the frame @@ -884,7 +890,7 @@ { float R, temp; uint16_t u16; - static unsigned prevBut = 1; + static unsigned prevJump = 0; vt.SetCursorPos( 43, 1 ); @@ -894,7 +900,7 @@ temp = 1.0/(log(R/R0)/B+1/298.15)-273.15; vt.printf("%u d8:%u,%u (%03x %03x %03x %03x) %.2fC\e[K", DeviceState, - d8.read(), userBut.read(), + d8.read(), jumper_in.read(), a1.read_u16() >> 4, a2.read_u16() >> 4, a3.read_u16() >> 4, a4.read_u16(), temp); if (statusTxt[0] != 0) { @@ -903,14 +909,14 @@ statusTxt[0] = 0; } - if (prevBut == 0 && userBut.read() == 1) { + if (prevJump == 0 && jumper_in.read() == 1) { /* user button release */ TimerInit(&event, autoUplink); TimerSetValue(&event, TX_INTERVAL_MS); TimerStart(&event); sprintf(statusTxt, "timer on %u", TX_INTERVAL_MS); } - prevBut = userBut.read(); + prevJump = jumper_in.read(); } const LoRaMacPrimitives_t LoRaMacPrimitives = { @@ -930,6 +936,9 @@ { MibRequestConfirm_t mibReq; + jumper_out = 1; + jumper_in.mode(PullDown); + BoardInit( ); SerialDisplayInit( );