Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 27:f024c8c51c6e, committed 2019-04-25
- Comitter:
- amirchaudhary
- Date:
- Thu Apr 25 15:41:02 2019 +0000
- Parent:
- 26:2cdfd2d309a6
- Child:
- 28:eca152c69c9b
- Commit message:
- Implemented LED Indicator Patterns ;
Changed in this revision
| app/Commissioning.h | Show annotated file Show diff for this revision Revisions of this file |
| app/main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/app/Commissioning.h Wed Apr 03 11:30:23 2019 +0000
+++ b/app/Commissioning.h Thu Apr 25 15:41:02 2019 +0000
@@ -35,17 +35,17 @@
/*!
* Mote device IEEE EUI (big endian)
*/
-#define LORAWAN_DEVICE_EUI { 0x00, 0x52, 0xF7, 0x41, 0x06, 0x67, 0xB2, 0xEE }
+#define LORAWAN_DEVICE_EUI { 0x00, 0x52, 0xF7, 0x41, 0x06, 0x67, 0xB1, 0x0E }
/*!
* Application IEEE EUI (big endian)
*/
-#define LORAWAN_APPLICATION_EUI { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x01, 0x4D, 0xD1 }
+#define LORAWAN_APPLICATION_EUI { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x01, 0x9D, 0xAC }
/*!
* AES encryption/decryption cipher application key
*/
-#define LORAWAN_APPLICATION_KEY { 0xC3, 0x65, 0xF6, 0xEF, 0xA0, 0x90, 0x71, 0x16, 0x83, 0x9A, 0x16, 0xC4, 0xF5, 0xF3, 0x20, 0xC7 }
+#define LORAWAN_APPLICATION_KEY { 0x76, 0x81, 0xF3, 0xD9, 0x30, 0x1D, 0xCE, 0xAE, 0x2F, 0x58, 0x3E, 0xD0, 0xF2, 0x53, 0x94, 0x11 }
/*!
* Current network ID
--- a/app/main.cpp Wed Apr 03 11:30:23 2019 +0000
+++ b/app/main.cpp Thu Apr 25 15:41:02 2019 +0000
@@ -149,6 +149,14 @@
AnalogIn RH_PIN(PC_2);
AnalogIn VCE_PIN(PB_1);
+/*
+D7 == Green
+D8 == Blue
+ */
+
+DigitalOut myGreenLed(D7); // ON = Lora Connected
+DigitalOut myBlueLed(D8); // Blink twice = Sends data or increments counter value Pelase proceed
+
InterruptIn button1(USER_BUTTON);
volatile bool button1_pressed = false; // Used in the main loop
volatile bool button1_enabled = true; // Used for debouncing
@@ -201,6 +209,77 @@
volatile bool Led2State = false;
volatile bool Led2StateChanged = false;
+enum GreenLedState_e{
+ GREEN_LED_STATE_INIT=0,
+ GREEN_LED_STATE_JOINING,
+ GREEN_LED_STATE_JOINED
+}GreenLedState;
+volatile uint32_t GreenLedTickCounter=0;
+
+volatile bool BatteryLowFlag = true;
+
+volatile uint32_t GreenLedJoiningCounter=0;
+
+static TimerEvent_t GreenLedTimer;
+static void OnGreenLedTimerEvent( void )
+{
+ MibRequestConfirm_t mibReq;
+ LoRaMacStatus_t status;
+
+ if(BatteryLowFlag == true)
+ {
+ myGreenLed = 0; // OFF
+ }
+ else
+ {
+ // battery ok
+ GreenLedTickCounter++;
+ switch(GreenLedState)
+ {
+ case GREEN_LED_STATE_INIT:
+ {
+ GreenLedState = GREEN_LED_STATE_JOINING;
+ }
+ break;
+
+ case GREEN_LED_STATE_JOINING:
+ {
+ GreenLedJoiningCounter++;
+ if((GreenLedJoiningCounter % 2) == 0)
+ {
+ GreenLedJoiningCounter = 0;
+ myGreenLed = !myGreenLed; // toggle
+
+ // check if we have joined the network
+ mibReq.Type = MIB_NETWORK_JOINED;
+ status = LoRaMacMibGetRequestConfirm( &mibReq );
+ if( status == LORAMAC_STATUS_OK )
+ {
+ if( mibReq.Param.IsNetworkJoined == true )
+ {
+ GreenLedState = GREEN_LED_STATE_JOINED;
+ }
+ }
+ }
+ }
+ break;
+
+ case GREEN_LED_STATE_JOINED:
+ {
+ myGreenLed = 1;
+ }
+ break;
+ }
+ }
+}
+
+static TimerEvent_t BatteryCheckTimer;
+volatile bool BatteryCheckFlag=false;
+static void OnBatteryCheckTimerEvent( void )
+{
+ BatteryCheckFlag = true;
+}
+
/*!
* Indicates if a new packet can be sent
*/
@@ -209,6 +288,14 @@
/*!
* Device states
*/
+
+
+ // Application Globals
+
+
+
+
+
static enum eDeviceState
{
DEVICE_STATE_INIT,
@@ -911,7 +998,7 @@
measurements[3] = (uint8_t) light_2_reading/2;
measurements[4] = (uint8_t) rh_reading/2;
- // End test
+ // End test //
relayPin = 0;
AppLedStateOn = 0;
Led3StateChanged = true;
@@ -1013,8 +1100,6 @@
}
-
-
int main( void )
{
pc.printf("mbed-os-rev: %d.%d.%d lib-rev: %d\r\n", \
@@ -1056,6 +1141,16 @@
button1.fall(callback(button1_onpressed_cb)); // Attach ISR to handle button press event
AppLedStateOn = 0;
Led3StateChanged = true;
+
+ myGreenLed = 0; // INITIAL OFF
+ GreenLedState = GREEN_LED_STATE_INIT;
+ TimerInit( &GreenLedTimer, OnGreenLedTimerEvent );
+ TimerSetValue( &GreenLedTimer, 100 );
+ TimerStart( &GreenLedTimer );
+
+ TimerInit( &BatteryCheckTimer, OnBatteryCheckTimerEvent );
+ TimerSetValue( &BatteryCheckTimer, 100 ); // 100msec
+ TimerStart( &BatteryCheckTimer );
while( 1 )
{
@@ -1095,6 +1190,24 @@
SerialDisplayUpdateDownlink( LoRaMacDownlinkStatus.RxData, LoRaMacDownlinkStatus.Rssi, LoRaMacDownlinkStatus.Snr, LoRaMacDownlinkStatus.DownlinkCounter, LoRaMacDownlinkStatus.Port, LoRaMacDownlinkStatus.Buffer, LoRaMacDownlinkStatus.BufferSize );
}
+ if( BatteryCheckFlag == true)
+ {
+ BatteryCheckFlag = false;
+
+ // Measure voltage preval
+ float battery_reading = BAT_PIN.read()*3300*2;
+ // pc.printf("VBAT= %d", (int)battery_reading);
+
+ if((battery_reading < 2000)||(battery_reading > 4450)) // set max voltage 4.55V
+ {
+ BatteryLowFlag = true;
+ }
+ else
+ {
+ BatteryLowFlag = false;
+ }
+ }
+
switch( DeviceState )
{
case DEVICE_STATE_INIT: