lorawan.h 1.33 KB
Newer Older
1
2
#ifndef AMPEL_LORAWAN_H_
#define AMPEL_LORAWAN_H_
Eric Duminil's avatar
Eric Duminil committed
3
4
5

#include "config.h"

6
#if defined(AMPEL_LORAWAN) && defined(ESP32)
7
#include <Arduino.h>
Eric Duminil's avatar
Notes    
Eric Duminil committed
8
9
// Requires "MCCI LoRaWAN LMIC library", which will be automatically used with PlatformIO but should be added in "Arduino IDE".
// Tested successfully with v3.2.0 and connected to a thethingsnetwork.org app.
10
11
#include <lmic.h>
#include <hal/hal.h>
Eric Duminil's avatar
Eric Duminil committed
12
#include <arduino_lmic_hal_boards.h>
13
#include <SPI.h>
Eric Duminil's avatar
Note    
Eric Duminil committed
14

15
#include "led_effects.h"
16
#include "sensor_console.h"
17
18
#include "util.h"

Eric Duminil's avatar
Eric Duminil committed
19
20
21
22
namespace config {
  extern uint16_t lorawan_sending_interval; // [s]
}

Eric Duminil's avatar
Eric Duminil committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#if defined(CFG_eu868)
#  define LMIC_FREQUENCY_PLAN "Europe 868"
#elif defined(CFG_us915)
#  define LMIC_FREQUENCY_PLAN "US 915"
#elif defined(CFG_au915)
#  define LMIC_FREQUENCY_PLAN "Australia 915"
#elif defined(CFG_as923)
#  define LMIC_FREQUENCY_PLAN "Asia 923"
#elif defined(CFG_kr920)
#  define LMIC_FREQUENCY_PLAN "Korea 920"
#elif defined(CFG_in866)
#  define LMIC_FREQUENCY_PLAN "India 866"
#else
#  error "Region should be specified"
#endif

39
40
namespace lorawan {
  extern bool waiting_for_confirmation;
Eric Duminil's avatar
Eric Duminil committed
41
  extern bool connected;
42
  extern char last_transmission[];
43
44
  void initialize();
  void process();
Eric Duminil's avatar
Eric Duminil committed
45
  void preparePayloadIfTimeHasCome(const int16_t &co2, const float &temp, const float &hum);
Eric Duminil's avatar
Eric Duminil committed
46
47

  void setLoRaInterval(int32_t sending_interval);
48
49
50
}

#endif
51
#endif