configGway.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. // 1-channel LoRa Gateway for ESP32 and ESP8266
  2. // Copyright (c) Maarten Westenberg 2016-2020
  3. // Specify the correct version and date of your gateway here.
  4. // Normally it is provided with the GitHub version
  5. #define VERSION "V.6.2.0.E.EU868; 200129b"
  6. //
  7. // Based on work done by Thomas Telkamp for Raspberry PI 1ch gateway and many others.
  8. // Contibutions of Dorijan Morelj and Andreas Spies for OLED support.
  9. //
  10. // All rights reserved. This program and the accompanying materials
  11. // are made available under the terms of the MIT License
  12. // which accompanies this distribution, and is available at
  13. // https://opensource.org/licenses/mit-license.php
  14. //
  15. // NO WARRANTY OF ANY KIND IS PROVIDED
  16. //
  17. // Author: Maarten Westenberg (mw12554@hotmail.com)
  18. //
  19. // This file contains a number of compile-time settings that can be set on (=1) or off (=0)
  20. // The disadvantage of compile time is minor compared to the memory gain of not having
  21. // too much code compiled and loaded on your ESP device.
  22. //
  23. // NOTE:
  24. // If version is for ESP32 Heltec board, compile with ESP32 setting and board
  25. // "ESP32 Dev Module" or "Heltec WiFi Lora 32"
  26. //
  27. // For ESP8266 Wemos: compile with "Wemos R1 D1" and choose
  28. // the right _PIN_OUT below. Selecting OLED while that is not connected does not
  29. // really matter (so you can leave that in).
  30. //
  31. // ========================================================================================
  32. // Define whether we should do a formatting of SPIFFS when starting the gateway
  33. // This is usually a good idea if the webserver is interrupted halfway a writing
  34. // operation. Also to be used when software is upgraded
  35. // Normally, value 0 is a good default and should not be changed.
  36. #define _SPIFFS_FORMAT 0
  37. // Allows configuration through WifiManager AP setup. Must be 0 or 1
  38. #define _WIFIMANAGER 0
  39. // Debug message will be put on Serial is this one is set.
  40. // If set to 0, no printing to USB devices is done.
  41. // Set to 1 it will print all user level messages (with correct debug set)
  42. // If set to 2 it will also print interrupt messages (not recommended)
  43. #define _DUSB 1
  44. // Define the monitor screen. When it is greater than 0 then logging is displayed in
  45. // the special screen at the GUI.
  46. // If _DUSB is also set to 1 then most messages will also be copied to USB devices.
  47. #define _MONITOR 1
  48. // Gather statistics on sensor and Wifi status
  49. // 0= No statistics
  50. // 1= Keep track of messages statistics, number determined by _MAXSTAT
  51. // 2= Option 1 + Keep track of messages received PER each SF (default)
  52. // 3= See Option 2, but with extra channel info (Not used when Hopping is not selected)
  53. #define _STATISTICS 3
  54. // Define the frequency band the gateway will listen on. Valid options are
  55. // EU863_870 Europe
  56. // US902_928 North America
  57. // AU925_928 Australia
  58. // CN470_510 China
  59. // IN865_867 India
  60. // CN779-787 (Not Used!)
  61. // EU433 Europe
  62. // AS923 (Not Used)
  63. // You can find the definitions in "loraModem.h" and frequencies in
  64. // See https://www.thethingsnetwork.org/docs/lorawan/frequency-plans.html
  65. #define EU863_870 1
  66. // Define the CLASS mode of the gateway
  67. // A: Baseline Class
  68. // B: Beacon/Battery Class
  69. // C: Continuous Listen Class
  70. #define _CLASS "A"
  71. // Define whether to use the old Semtech gateway API, which is still supported by TTN,
  72. // but is more lightweight than the new TTN tcp based protocol.
  73. // NOTE: Only one of the two should be defined! TTN Router project has stopped
  74. //
  75. #define _UDPROUTER 1
  76. //#define _TTNROUTER 1
  77. // The spreading factor is the most important parameter to set for a single channel
  78. // gateway. It specifies the speed/datarate in which the gateway and node communicate.
  79. // As the name says, in principle the single channel gateway listens to one channel/frequency
  80. // and to one spreading factor only.
  81. // This parameters contains the default value of SF, the actual version can be set with
  82. // the webserver and it will be stored in SPIFF
  83. // NOTE: The frequency is set in the loraModem.h file and is default 868.100000 MHz.
  84. #define _SPREADING SF9
  85. // Channel Activity Detection
  86. // This function will scan for valid LoRa headers and determine the Spreading
  87. // factor accordingly. If set to 1 we will use this function which means the
  88. // 1-channel gateway will become even more versatile. If set to 0 we will use the
  89. // continuous listen mode.
  90. // Using this function means that we HAVE to use more dio pins on the RFM95/sx1276
  91. // device and also connect enable dio1 to detect this state.
  92. #define _CAD 1
  93. // CRCCHECK
  94. // Defines whether we should check on the CRC of RXDONE messages (see stateMachine.ino)
  95. // This should prevent us from getting a lot os stranges messgages of unknown nodes.
  96. // Note: DIO3 must be connected for this to work (Heltec and later Wemos gateways).
  97. #define _CRCCHECK 1
  98. // Definitions for the admin webserver.
  99. // A_SERVER determines whether or not the admin webpage is included in the sketch.
  100. // Normally, leave it in!
  101. #define A_SERVER 1 // Define local WebServer only if this define is set
  102. #define A_REFRESH 1 // Allow the webserver refresh or not?
  103. #define A_SERVERPORT 80 // Local webserver port (normally 80)
  104. #define A_MAXBUFSIZE 192 // Must be larger than 128, but small enough to work
  105. // Definitions for over the air updates. At the moment we support OTA with IDE
  106. // Make sure that tou have installed Python version 2.7 and have Bonjour in your network.
  107. // Bonjour is included in iTunes (which is free) and OTA is recommended to install
  108. // the firmware on your router witout having to be really close to the gateway and
  109. // connect with USB.
  110. #define A_OTA 1
  111. // We support a few pin-out configurations out-of-the-box: HALLARD, COMPRESULT and TTGO ESP32.
  112. // If you use one of these two, just set the parameter to the right value.
  113. // If your pin definitions are different, update the loraModem.h file to reflect these settings.
  114. // 1: HALLARD
  115. // 2: COMRESULT pin out
  116. // 3: ESP32, Wemos pin out (Not used)
  117. // 4: ESP32, Heltec and TTGO pin out (should work for Heltec, 433 and OLED too).
  118. // 5: Other, define your own in loraModem.h (does not include GPS Code)
  119. #define _PIN_OUT 4
  120. // Single channel gateways if they behave strict should only use one frequency
  121. // channel and one, or in case _CAD all, spreading factors.
  122. // The TTN backend replies on RX1 timeslot for spreading factors SF9-SF12.
  123. // If the 1ch gateway is working in and for nodes that ONLY transmit and receive on the set
  124. // and agreed frequency and spreading factor. make sure to set STRICT to 1.
  125. // In this case, the frequency and spreading factor for downlink messages is adapted by this
  126. // gateway
  127. // NOTE: If your node has only one frequency enabled and one SF, you must set this to 1
  128. // in order to receive downlink messages. This is the default mode.
  129. // NOTE: In all other cases, value 0 works for most gateways with CAD enabled
  130. #define _STRICT_1CH 1
  131. //
  132. // Also, normally the server will respond with SF12 in the RX2 timeslot.
  133. // For TTN, thr RX2 timeslot is SF9, and we should use that one for TTN
  134. #define _RX2_SF 9
  135. // This section defines whether we use the gateway as a repeater
  136. // For his, we use another output channel as the channel (default==0) we are
  137. // receiving the messages on.
  138. #define _REPEATER 0
  139. // Will we use Mutex or not?
  140. // +SPI is input for SPI, SPO is output for SPI
  141. #define _MUTEX 0
  142. // Define if OLED Display is connected to I2C bus. Note that defining an OLED display does not
  143. // impact performance very much, certainly if no OLED is connected. Wrong OLED will not show
  144. // sensible results on display
  145. // OLED==0; No OLED display connected
  146. // OLED==1; 0.9 Oled Screen based on SSD1306
  147. // OLED==2; 1"3 Oled screens for Wemos, 128x64 SH1106
  148. #define OLED 1
  149. // Define whether we want to manage the gateway over UDP (next to management
  150. // thru webinterface).
  151. // This will allow us to send messages over the UDP connection to manage the gateway
  152. // and its parameters. Sometimes the gateway is not accesible from remote,
  153. // in this case we would allow it to use the SERVER UDP connection to receive
  154. // messages as well.
  155. // NOTE: Be aware that these messages are NOT LoRa and NOT LoRa Gateway spec compliant.
  156. // However that should not interfere with regular gateway operation but instead offer
  157. // functions to set/reset certain parameters from remote.
  158. #define _GATEWAYMGT 0
  159. // Do extensive logging
  160. // Use the ESP8266 SPIFS filesystem to do extensive logging.
  161. // We must take care that the filesystem never(!) is full, and for that purpose we
  162. // rather have new records/line of statistics than very old.
  163. // Of course we must store enough records to make the filesystem work
  164. #define _STAT_LOG 1
  165. // Set the Server Settings (IMPORTANT)
  166. #define _LOCUDPPORT 1700 // UDP port of gateway! Often 1700 or 1701 is used for upstream comms
  167. // Timing
  168. #define _MSG_INTERVAL 15 // Reset timer in seconds
  169. #define _PULL_INTERVAL 55 // PULL_DATA messages to server to get downstream in milliseconds
  170. #define _STAT_INTERVAL 120 // Send a 'stat' message to server
  171. #define _NTP_INTERVAL 3600 // How often do we want time NTP synchronization
  172. #define _WWW_INTERVAL 60 // Number of seconds before we refresh the WWW page
  173. // This defines whether or not we would use the gateway as
  174. // as sort of backend decoding system for local sensors which decodes
  175. // 1: _LOCALSERVER is used
  176. // 0: Do not use _LOCALSERVER
  177. #define _LOCALSERVER 1 // See server definitions for decodes
  178. // Gateway Ident definitions. Where is the gateway located?
  179. #define _DESCRIPTION "ESP Gateway" // Name of the gateway
  180. #define _EMAIL "mw12554@hotmail.com" // Owner
  181. #define _PLATFORM "ESP8266"
  182. #define _LAT 52.237367
  183. #define _LON 5.978654
  184. #define _ALT 14 // Altitude
  185. // ntp
  186. // Please add daylight saving time to NTP_TIMEZONES when desired
  187. #define NTP_TIMESERVER "nl.pool.ntp.org" // Country and region specific
  188. #define NTP_TIMEZONES 1 // How far is our Timezone from UTC (excl daylight saving/summer time)
  189. #define SECS_IN_HOUR 3600
  190. #define NTP_INTR 0 // Do NTP processing with interrupts or in loop();
  191. // lora sensor code definitions
  192. // Defines whether the gateway will also report sensor/status value on MQTT
  193. // (such as battery and GPS)
  194. // after all, a gateway can be a node to the system as well. Some sensors like GPS can be
  195. // sent to the backend as a parameter, some (like humidity for example) can only be sent
  196. // as a regular sensor value.
  197. // Set its LoRa address and key below in this file, See spec. para 4.3.2
  198. // NOTE: The node is switched off by default. Switch it on in the GUI
  199. #define _GATEWAYNODE 0
  200. // We can put the gateway in such a mode that it will (only) recognize
  201. // nodes that are put in a list of trusted nodes
  202. // Values:
  203. // 0: Do not use names for trusted Nodes
  204. // 1: Use the nodes as a translation table for hex codes to names (in TLN)
  205. // 2: Same as 1, but is nodes NOT in the nodes list below they are NOT shown
  206. // NOTE: We probably will make this list dynamic!
  207. #define _TRUSTED_NODES 1
  208. #define _TRUSTED_DECODE 1
  209. // ========================================================================
  210. // DO NOT CHANGE BELOW THIS LINE
  211. // Probably do not change items below this line, only if lists or
  212. // configurations on configNode.h are not large enough for example.
  213. // ========================================================================
  214. // Maximum number of Message History statistics records gathered. 20 is a good maximum
  215. // (memory intensive). For ESP32 maybe 30 could be used as well
  216. #define _MAXSTAT 20
  217. // Define the maximum amount of itemas we monitor on the screen
  218. #define _MAXMONITOR 20
  219. // We will log a list of LoRa nodes that was forwarded using this gateway.
  220. // For eacht node we record:
  221. // - node Number, or known node name
  222. // - Last seen 'seconds since 1/1/1970'
  223. // - SF seen (8-bit integer with SF per bit)
  224. // The initial version _NUMMAX stores max this many nodes, please make
  225. // _MAXSEEN==0 when not used
  226. #define _MAXSEEN 20
  227. #define _SEENFILE "/gwayNum.txt"
  228. // Name of he configfile in SPIFFs filesystem
  229. // In this file we store the configuration and other relevant info that should
  230. // survive a reboot of the gateway
  231. #define CONFIGFILE "/gwayConfig.txt"
  232. // Define the correct radio type that you are using
  233. #define CFG_sx1276_radio
  234. //#define CFG_sx1272_radio
  235. // Serial Port speed
  236. #define _BAUDRATE 115200 // Works for debug messages to serial momitor
  237. // MQTT definitions, these settings should be standard for TTN
  238. // and need no changing
  239. #define _TTNSERVER "router.eu.thethings.network"
  240. #define _TTNPORT 1700 // Standard port for TTN