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
main.cpp@71:ca2425c0a864, 2020-01-24 (annotated)
- Committer:
- jacktractive
- Date:
- Fri Jan 24 07:32:42 2020 +0000
- Revision:
- 71:ca2425c0a864
- Parent:
- 70:65b2f1cc2859
- Child:
- 72:67c5bce77999
GPS und Lora funktioniert.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jacktractive | 66:a11c79073f1f | 1 | #include <stdio.h> |
jacktractive | 66:a11c79073f1f | 2 | #include "Watchdog.h" |
jacktractive | 66:a11c79073f1f | 3 | #include "events/EventQueue.h" |
mbed_official | 0:7037ed05f54f | 4 | #include "trace_helper.h" |
jacktractive | 66:a11c79073f1f | 5 | #include <mbed.h> |
jacktractive | 65:3061ea235a0c | 6 | #include "mbed_stats.h" |
jacktractive | 69:316fee01f5d9 | 7 | #include "Light.h" |
jacktractive | 69:316fee01f5d9 | 8 | #include "GPS.h" |
jacktractive | 69:316fee01f5d9 | 9 | #include "Lora.h" |
jacktractive | 63:2bfceda4c30c | 10 | |
jacktractive | 69:316fee01f5d9 | 11 | #define MAX_NUMBER_OF_EVENTS 20 |
jacktractive | 69:316fee01f5d9 | 12 | static EventQueue ev_queue(MAX_NUMBER_OF_EVENTS *EVENTS_EVENT_SIZE); |
jacktractive | 69:316fee01f5d9 | 13 | |
jacktractive | 66:a11c79073f1f | 14 | |
jacktractive | 71:ca2425c0a864 | 15 | uint32_t TickCounter; |
jacktractive | 71:ca2425c0a864 | 16 | uint32_t TickTime=3000; |
jacktractive | 71:ca2425c0a864 | 17 | uint32_t LoraTickCounter; |
jacktractive | 71:ca2425c0a864 | 18 | uint32_t LoraTickTime=15000; //15000 |
jacktractive | 66:a11c79073f1f | 19 | |
jacktractive | 69:316fee01f5d9 | 20 | |
jacktractive | 63:2bfceda4c30c | 21 | bool IsLoading; |
jacktractive | 63:2bfceda4c30c | 22 | AnalogIn LadeSpannung(PB_0); // 1/11 der gleichgerichteten Spannung am Dynamo |
jacktractive | 70:65b2f1cc2859 | 23 | |
jacktractive | 70:65b2f1cc2859 | 24 | //Light |
jacktractive | 70:65b2f1cc2859 | 25 | DigitalOut LichtAus(PC_12); |
jacktractive | 70:65b2f1cc2859 | 26 | DigitalOut LichtHell(PC_9); |
jacktractive | 70:65b2f1cc2859 | 27 | Light light(&ev_queue,&LichtAus,&LichtHell); |
jacktractive | 70:65b2f1cc2859 | 28 | |
jacktractive | 71:ca2425c0a864 | 29 | //Userbutton |
jacktractive | 71:ca2425c0a864 | 30 | DigitalIn USERButton(PB_15); |
jacktractive | 71:ca2425c0a864 | 31 | |
jacktractive | 70:65b2f1cc2859 | 32 | //GPS |
jacktractive | 70:65b2f1cc2859 | 33 | DigitalOut GPSdisable(PC_6); |
jacktractive | 70:65b2f1cc2859 | 34 | GPS GPS_modul(PC_4, PC_5, 9600,&GPSdisable); |
jacktractive | 70:65b2f1cc2859 | 35 | uint32_t TimeWithoutMoving; |
jacktractive | 66:a11c79073f1f | 36 | |
jacktractive | 71:ca2425c0a864 | 37 | //Lora |
jacktractive | 69:316fee01f5d9 | 38 | Lora lora(&ev_queue, &light, &GPS_modul); |
mbed_official | 0:7037ed05f54f | 39 | |
jacktractive | 71:ca2425c0a864 | 40 | //Im LifeTicker wird geprüft ob das Fahrrad in Bewegung ist |
jacktractive | 71:ca2425c0a864 | 41 | static void LifeTicker() |
jacktractive | 71:ca2425c0a864 | 42 | { |
mbed_official | 0:7037ed05f54f | 43 | |
jacktractive | 68:41fff9c3fb4f | 44 | //Lifetick |
jacktractive | 68:41fff9c3fb4f | 45 | TickCounter=TickCounter+1; |
jacktractive | 69:316fee01f5d9 | 46 | printf("\n[LiveTick] --- [%i] ", TickCounter); |
jacktractive | 69:316fee01f5d9 | 47 | |
jacktractive | 71:ca2425c0a864 | 48 | //Dynamo - Fahrrad in Bewegung - Licht einschalten |
jacktractive | 70:65b2f1cc2859 | 49 | if(LadeSpannung.read()*3.3f*11 > 5) { |
jacktractive | 69:316fee01f5d9 | 50 | IsLoading = 1; |
jacktractive | 69:316fee01f5d9 | 51 | TimeWithoutMoving =0 ; |
jacktractive | 69:316fee01f5d9 | 52 | printf("[SYSTEM] Akku laden mit: %fV", LadeSpannung.read()*3.3f*11); |
jacktractive | 69:316fee01f5d9 | 53 | }else { |
jacktractive | 69:316fee01f5d9 | 54 | IsLoading = 0; |
jacktractive | 69:316fee01f5d9 | 55 | TimeWithoutMoving=TimeWithoutMoving+TickTime; |
jacktractive | 69:316fee01f5d9 | 56 | printf("[SYSTEM] Fahrrad steht seit: %is", TimeWithoutMoving/1000); |
jacktractive | 69:316fee01f5d9 | 57 | } |
jacktractive | 69:316fee01f5d9 | 58 | light.adjust(IsLoading,TimeWithoutMoving); |
jacktractive | 69:316fee01f5d9 | 59 | |
jacktractive | 71:ca2425c0a864 | 60 | // User Button - Manuelles Tracking |
jacktractive | 70:65b2f1cc2859 | 61 | if (!USERButton){ |
jacktractive | 71:ca2425c0a864 | 62 | if (GPS_modul.manual_tracking){ |
jacktractive | 71:ca2425c0a864 | 63 | GPS_modul.set_manual_tracking(false); |
jacktractive | 71:ca2425c0a864 | 64 | light.Blinken_ein(1000); |
jacktractive | 71:ca2425c0a864 | 65 | } |
jacktractive | 71:ca2425c0a864 | 66 | else { |
jacktractive | 71:ca2425c0a864 | 67 | GPS_modul.set_manual_tracking(true); |
jacktractive | 71:ca2425c0a864 | 68 | light.Blinken_ein(400); |
jacktractive | 71:ca2425c0a864 | 69 | } |
jacktractive | 71:ca2425c0a864 | 70 | } |
jacktractive | 69:316fee01f5d9 | 71 | } |
jacktractive | 69:316fee01f5d9 | 72 | |
jacktractive | 71:ca2425c0a864 | 73 | // Im LoraTicker wird Lora und GPS Zyklen verwaltet |
jacktractive | 69:316fee01f5d9 | 74 | static void LoraTicker() |
jacktractive | 71:ca2425c0a864 | 75 | { |
jacktractive | 71:ca2425c0a864 | 76 | //Watchdog |
jacktractive | 71:ca2425c0a864 | 77 | Watchdog &watchdog = Watchdog::get_instance(); |
jacktractive | 71:ca2425c0a864 | 78 | Watchdog::get_instance().kick(); // kick the Watchdog before the timeout |
jacktractive | 71:ca2425c0a864 | 79 | |
jacktractive | 69:316fee01f5d9 | 80 | //Lora Lifetick |
jacktractive | 69:316fee01f5d9 | 81 | LoraTickCounter=LoraTickCounter+1; |
jacktractive | 69:316fee01f5d9 | 82 | printf("\n\n[LoraTick] --- [%i]", LoraTickCounter); |
jacktractive | 66:a11c79073f1f | 83 | |
jacktractive | 68:41fff9c3fb4f | 84 | //Sleep Statistik |
jacktractive | 68:41fff9c3fb4f | 85 | mbed_stats_cpu_t stats; |
jacktractive | 68:41fff9c3fb4f | 86 | mbed_stats_cpu_get(&stats); |
jacktractive | 69:316fee01f5d9 | 87 | 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); |
jacktractive | 66:a11c79073f1f | 88 | |
jacktractive | 71:ca2425c0a864 | 89 | //GPS wird ausgemacht wenn das Fahrrad lange steht |
jacktractive | 71:ca2425c0a864 | 90 | GPS_modul.idle(TimeWithoutMoving>=300000); |
jacktractive | 70:65b2f1cc2859 | 91 | GPS_modul.GPS_aktiv(); |
jacktractive | 68:41fff9c3fb4f | 92 | |
jacktractive | 71:ca2425c0a864 | 93 | //LORA |
jacktractive | 70:65b2f1cc2859 | 94 | lora.send_Position_to_Lora(0x01, GPS_modul.time,GPS_modul.longitude,GPS_modul.latitude); |
jacktractive | 63:2bfceda4c30c | 95 | } |
jacktractive | 63:2bfceda4c30c | 96 | |
jacktractive | 66:a11c79073f1f | 97 | |
jacktractive | 66:a11c79073f1f | 98 | |
jacktractive | 66:a11c79073f1f | 99 | /** |
jacktractive | 66:a11c79073f1f | 100 | * Entry point for application |
jacktractive | 66:a11c79073f1f | 101 | */ |
mbed_official | 46:a124538e2891 | 102 | int main(void) |
jacktractive | 64:85fa08519e1e | 103 | { |
jacktractive | 71:ca2425c0a864 | 104 | Watchdog &watchdog = Watchdog::get_instance(); |
jacktractive | 71:ca2425c0a864 | 105 | watchdog.start(30000); //30s ohne kick im Ticker wird die CPU neu gestartet |
jacktractive | 66:a11c79073f1f | 106 | uint32_t watchdog_timeout = watchdog.get_timeout(); |
jacktractive | 67:7bb75ed97500 | 107 | printf("Watchdog initialized to %iu ms.\r\n", watchdog_timeout); |
jacktractive | 68:41fff9c3fb4f | 108 | |
jacktractive | 71:ca2425c0a864 | 109 | ev_queue.call_every(TickTime,LifeTicker); //Zyklus um Dynamoaktivitäten zu prüfen |
jacktractive | 71:ca2425c0a864 | 110 | ev_queue.call_every(LoraTickTime,LoraTicker); //Zyklus zum senden über Lora |
jacktractive | 67:7bb75ed97500 | 111 | |
jacktractive | 71:ca2425c0a864 | 112 | setup_trace(); // setup tracing für mehr Infos im log über lora |
jacktractive | 61:2b30d8e75fe7 | 113 | |
jacktractive | 71:ca2425c0a864 | 114 | lora.Lora_init(); // Lora initialisieren |
jacktractive | 69:316fee01f5d9 | 115 | |
jacktractive | 71:ca2425c0a864 | 116 | ev_queue.dispatch_forever();// make your event queue dispatching events forever |
jacktractive | 68:41fff9c3fb4f | 117 | return 0; |
jacktractive | 68:41fff9c3fb4f | 118 | } |
jacktractive | 68:41fff9c3fb4f | 119 | |
jacktractive | 66:a11c79073f1f | 120 | // EOF |