This is an example application based on Mbed-OS LoRaWAN protocol APIs. The Mbed-OS LoRaWAN stack implementation is compliant with LoRaWAN v1.0.2 specification.

Dependencies:   Lorawan_Version_0_1

Dependents:   Lorawan_Version_0_1

Revision:
71:ca2425c0a864
Parent:
70:65b2f1cc2859
Child:
72:67c5bce77999
--- a/main.cpp	Tue Jan 21 13:20:59 2020 +0000
+++ b/main.cpp	Fri Jan 24 07:32:42 2020 +0000
@@ -1,47 +1,22 @@
-/**
- * Copyright (c) 2017, Arm Limited and affiliates.
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 #include <stdio.h>
-
 #include "Watchdog.h"
 #include "events/EventQueue.h"
-
-// Application helpers
 #include "trace_helper.h"
-
 #include <mbed.h>
 #include "mbed_stats.h"
 #include "Light.h"
 #include "GPS.h"
 #include "Lora.h"
 
-
 #define MAX_NUMBER_OF_EVENTS            20
 static EventQueue ev_queue(MAX_NUMBER_OF_EVENTS *EVENTS_EVENT_SIZE);
 
 
-DigitalIn USERButton(PB_15);
-
-bool GPS_activ,LORA_activ,AtHome;
-
+uint32_t TickCounter;
+uint32_t TickTime=3000;
+uint32_t LoraTickCounter;
+uint32_t LoraTickTime=15000; //15000
 
-uint32_t TickCounter;
-uint32_t TickTime=1000;
-uint32_t LoraTickCounter;
-uint32_t LoraTickTime=15000;
 
 bool IsLoading;
 AnalogIn LadeSpannung(PB_0); // 1/11 der gleichgerichteten Spannung am Dynamo
@@ -51,32 +26,26 @@
 DigitalOut LichtHell(PC_9);
 Light light(&ev_queue,&LichtAus,&LichtHell);
 
+//Userbutton
+DigitalIn USERButton(PB_15);
+
 //GPS
 DigitalOut GPSdisable(PC_6);
 GPS GPS_modul(PC_4, PC_5, 9600,&GPSdisable);
 uint32_t TimeWithoutMoving;
 
+//Lora
 Lora lora(&ev_queue, &light, &GPS_modul);
 
+//Im LifeTicker wird geprüft ob das Fahrrad in Bewegung ist
+static void LifeTicker()
+{   
 
-/**
- * Event handler.
- *
- * This will be passed to the LoRaWAN stack to queue events for the
- * application which in turn drive the application.
- */
-
-static void LifeTicker()
-{
-//Watchdog
-    Watchdog &watchdog = Watchdog::get_instance();    
-    Watchdog::get_instance().kick(); // kick the Watchdog before the timeout
-        
 //Lifetick
     TickCounter=TickCounter+1;
     printf("\n[LiveTick] --- [%i] ", TickCounter);
     
-//Dynamo - Fahrrad in Bewegung
+//Dynamo - Fahrrad in Bewegung - Licht einschalten
    if(LadeSpannung.read()*3.3f*11 > 5) {     
         IsLoading = 1;
         TimeWithoutMoving =0 ;
@@ -88,17 +57,26 @@
      }        
     light.adjust(IsLoading,TimeWithoutMoving);
     
+// User Button - Manuelles Tracking
      if (!USERButton){
-         light.Blinken_ein(4000);
-         GPS_modul.set_manual_tracking(true); 
-         };           
+         if (GPS_modul.manual_tracking){
+             GPS_modul.set_manual_tracking(false); 
+             light.Blinken_ein(1000);
+             }
+         else {
+             GPS_modul.set_manual_tracking(true); 
+             light.Blinken_ein(400);
+             }
+     }              
 }
 
-
+// Im LoraTicker wird Lora und GPS Zyklen verwaltet
 static void LoraTicker()
-{
-    
-    
+{   
+//Watchdog
+    Watchdog &watchdog = Watchdog::get_instance();    
+    Watchdog::get_instance().kick(); // kick the Watchdog before the timeout
+        
 //Lora Lifetick
     LoraTickCounter=LoraTickCounter+1;
     printf("\n\n[LoraTick] --- [%i]", LoraTickCounter);
@@ -108,11 +86,11 @@
    mbed_stats_cpu_get(&stats);
    printf("\n[SYSTEM] Uptime: %llu Idle: %llu Sleep: %llu Deep: %llu", stats.uptime / 1000 , stats.idle_time / 1000, stats.sleep_time / 1000,stats.deep_sleep_time / 1000);
     
-//GPS
-    GPS_modul.idle(TimeWithoutMoving>300000);
+//GPS wird ausgemacht wenn das Fahrrad lange steht
+    GPS_modul.idle(TimeWithoutMoving>=300000);
     GPS_modul.GPS_aktiv();   
     
-//LORA    
+//LORA 
     lora.send_Position_to_Lora(0x01, GPS_modul.time,GPS_modul.longitude,GPS_modul.latitude);           
 }
 
@@ -123,24 +101,19 @@
  */
 int main(void)
 { 
-    Watchdog &watchdog = Watchdog::get_instance();
-    
-    watchdog.start(30000);
+    Watchdog &watchdog = Watchdog::get_instance();    
+    watchdog.start(30000); //30s ohne kick im Ticker wird die CPU neu gestartet    
     uint32_t watchdog_timeout = watchdog.get_timeout();
     printf("Watchdog initialized to %iu ms.\r\n", watchdog_timeout);
            
-    ev_queue.call_every(TickTime,LifeTicker);
-    ev_queue.call_every(LoraTickTime,LoraTicker);
- 
+    ev_queue.call_every(TickTime,LifeTicker); //Zyklus um Dynamoaktivitäten zu prüfen
+    ev_queue.call_every(LoraTickTime,LoraTicker); //Zyklus zum senden über Lora     
     
-    // setup tracing
-    setup_trace();
+    setup_trace(); // setup tracing für mehr Infos im log über lora    
     
-    lora.Lora_init();
+    lora.Lora_init(); // Lora initialisieren
     
-    // make your event queue dispatching events forever
-    ev_queue.dispatch_forever();
-    
+    ev_queue.dispatch_forever();// make your event queue dispatching events forever
     return 0;
 }