[rak4631]
extends = nrf52_base
board = rak4631
board_check = true
board_build.ldscript = boards/nrf52840_s140_v6.ld
extra_scripts = ${nrf52_base.extra_scripts}
  post:variants/rak4631/fix_bsec_lib.py
  post:tools/mota/pio_endf.py            ; EndF trailer for OTA self-identity (all RAK4631 roles)
build_flags = ${nrf52_base.build_flags}
  ${sensor_base.build_flags}
  -I variants/rak4631
  -D RAK_4631
  -D RAK_BOARD
;  -D NRF52_POWER_MANAGEMENT
  -D MOTA_HW_ID='"RAK4631"'               ; OTA hardware tag (apply refuses a .mota for different hw)
  -D PIN_BOARD_SCL=14
  -D PIN_BOARD_SDA=13
  -D PIN_GPS_TX=PIN_SERIAL1_RX
  -D PIN_GPS_RX=PIN_SERIAL1_TX
  -D PIN_GPS_EN=-1
  -D PIN_OLED_RESET=-1
  -D USE_SX1262
  -D RADIO_CLASS=CustomSX1262
  -D WRAPPER_CLASS=CustomSX1262Wrapper
  -D LORA_TX_POWER=22
  -D SX126X_CURRENT_LIMIT=140
  -D SX126X_RX_BOOSTED_GAIN=1
  -D ENV_INCLUDE_RAK12035=1
  -UENV_INCLUDE_BME680
  -D ENV_INCLUDE_BME680_BSEC=1
  -D ENABLE_OTA=1                        ; LoRa OTA on every RAK4631 role (single-slot, bootloader-applied)
  -D OTA_FLASH_STORE=1                   ; stage the received .mota in flash (survives reboot into the bootloader)
  -D OTA_FOLDER_SERIAL                   ; `ota folder on` relays a host folder of .mota over the USB console (no extra HW)
build_src_filter = ${nrf52_base.build_src_filter}
  +<../variants/rak4631>
  +<helpers/sensors>
  +<helpers/ui/SSD1306Display.cpp>
  +<helpers/ui/MomentaryButton.cpp>
  +<helpers/ota/*.cpp>
lib_deps =
  ${nrf52_base.lib_deps}
  ${sensor_base.lib_deps}
  adafruit/Adafruit SSD1306 @ ^2.5.13
  sparkfun/SparkFun u-blox GNSS Arduino Library@^2.2.27
  boschsensortec/BSEC Software Library @ ^1.8.1492

[env:RAK_4631_repeater]
extends = rak4631
build_flags =
  ${rak4631.build_flags}
  -UENABLE_OTA
  -D DISABLE_LORA_OTA=1                  ; Cascade repeater image exceeds the safe nRF52 in-place OTA ceiling
  -D DISPLAY_CLASS=SSD1306Display
  -D ADVERT_NAME='"RAK4631 Repeater"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D MAX_NEIGHBOURS=50
;  -D OTA_DEBUG=1                        ; bring-up: trace OTA fetch (REQ / block / page-flush) over Serial
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1
build_src_filter = ${rak4631.build_src_filter}
  +<helpers/ui/SSD1306Display.cpp>
  ; Shared sources remain inherited, but ENABLE_OTA is explicitly undefined for this oversized role.
  +<../examples/simple_repeater>

; Lean OTA target for space-constrained RAK4631 repeaters. This removes only optional external
; environmental/GPS sensor packages. RAK4631Board::getBattMilliVolts(), repeater telemetry, and
; battery.alert remain part of the board/repeater sources below.
[env:RAK_4631_repeater_lora_ota_no_external_sensors]
extends = rak4631
extra_scripts = ${nrf52_lora_ota.extra_scripts}
build_flags =
  ${rak4631.build_flags}
  ${nrf52_no_external_sensors.build_flags}
  -D DISPLAY_CLASS=SSD1306Display
  -D ADVERT_NAME='"RAK4631 LoRa OTA No Ext Sensors"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D MAX_NEIGHBOURS=50
build_src_filter = ${nrf52_lora_ota.build_src_filter}
  +<../variants/rak4631>
  +<helpers/sensors/EnvironmentSensorManager.cpp>
  +<helpers/ui/SSD1306Display.cpp>
  +<helpers/ui/MomentaryButton.cpp>
  +<../examples/simple_repeater>
lib_deps =
  ${nrf52_lora_ota.lib_deps}
  adafruit/Adafruit SSD1306 @ ^2.5.13

[env:RAK_4631_repeater_ethernet]
extends = rak4631
build_flags =
  ${rak4631.build_flags}
  -UENABLE_OTA
  -D DISABLE_LORA_OTA=1                  ; Ethernet image exceeds the safe nRF52 in-place OTA ceiling
  -D DISPLAY_CLASS=SSD1306Display
  -D ADVERT_NAME='"RAK4631 Repeater"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D MAX_NEIGHBOURS=50
  -D ETHERNET_ENABLED=1
;  -D MESH_DEBUG=1
build_src_filter = ${rak4631.build_src_filter}
  +<helpers/ui/SSD1306Display.cpp>
  +<../examples/simple_repeater>
lib_deps =
  ${rak4631.lib_deps}
  https://github.com/RAKWireless/RAK13800-W5100S/archive/1.0.2.zip

[env:RAK_4631_repeater_bridge_rs232_serial1]
extends = rak4631
build_flags =
  ${rak4631.build_flags}
  -UENABLE_OTA
  -D DISABLE_LORA_OTA=1                  ; Full external-sensor build exceeds the in-place OTA ceiling
  -D DISPLAY_CLASS=SSD1306Display
  -D ADVERT_NAME='"RS232 Bridge"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D MAX_NEIGHBOURS=50
  -D WITH_RS232_BRIDGE=Serial1
  -D WITH_RS232_BRIDGE_RX=PIN_SERIAL1_RX
  -D WITH_RS232_BRIDGE_TX=PIN_SERIAL1_TX
  -UENV_INCLUDE_GPS
;  -D BRIDGE_DEBUG=1
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1
;  -D CORE_DEBUG_LEVEL=3
build_src_filter = ${rak4631.build_src_filter}
  +<helpers/ui/SSD1306Display.cpp>
  +<helpers/bridges/RS232Bridge.cpp>
  +<../examples/simple_repeater>

; Explicit lean alternative to the full-sensor, non-OTA Serial1 bridge above.
[env:RAK_4631_repeater_bridge_rs232_serial1_lora_ota_no_external_sensors]
extends = rak4631
build_flags =
  ${rak4631.build_flags}
  ${nrf52_no_external_sensors.build_flags}
  -D DISPLAY_CLASS=SSD1306Display
  -D ADVERT_NAME='"RS232 Bridge"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D MAX_NEIGHBOURS=50
  -D WITH_RS232_BRIDGE=Serial1
  -D WITH_RS232_BRIDGE_RX=PIN_SERIAL1_RX
  -D WITH_RS232_BRIDGE_TX=PIN_SERIAL1_TX
build_src_filter = ${rak4631.build_src_filter}
  +<helpers/ui/SSD1306Display.cpp>
  +<helpers/bridges/RS232Bridge.cpp>
  +<../examples/simple_repeater>
lib_deps =
  ${nrf52_lora_ota.lib_deps}
  adafruit/Adafruit SSD1306 @ ^2.5.13

[env:RAK_4631_repeater_bridge_rs232_serial2]
extends = rak4631
build_flags =
  ${rak4631.build_flags}
  -UENABLE_OTA
  -D DISABLE_LORA_OTA=1                  ; Full external-sensor build exceeds the in-place OTA ceiling
  -D DISPLAY_CLASS=SSD1306Display
  -D ADVERT_NAME='"RS232 Bridge"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D MAX_NEIGHBOURS=50
  -D WITH_RS232_BRIDGE=Serial2
  -D WITH_RS232_BRIDGE_RX=PIN_SERIAL2_RX
  -D WITH_RS232_BRIDGE_TX=PIN_SERIAL2_TX
  -UENV_INCLUDE_GPS
;  -D BRIDGE_DEBUG=1
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1
;  -D CORE_DEBUG_LEVEL=3
build_src_filter = ${rak4631.build_src_filter}
  +<helpers/ui/SSD1306Display.cpp>
  +<helpers/bridges/RS232Bridge.cpp>
  +<../examples/simple_repeater>

; Explicit lean alternative to the full-sensor, non-OTA Serial2 bridge above.
[env:RAK_4631_repeater_bridge_rs232_serial2_lora_ota_no_external_sensors]
extends = rak4631
build_flags =
  ${rak4631.build_flags}
  ${nrf52_no_external_sensors.build_flags}
  -D DISPLAY_CLASS=SSD1306Display
  -D ADVERT_NAME='"RS232 Bridge"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D MAX_NEIGHBOURS=50
  -D WITH_RS232_BRIDGE=Serial2
  -D WITH_RS232_BRIDGE_RX=PIN_SERIAL2_RX
  -D WITH_RS232_BRIDGE_TX=PIN_SERIAL2_TX
build_src_filter = ${rak4631.build_src_filter}
  +<helpers/ui/SSD1306Display.cpp>
  +<helpers/bridges/RS232Bridge.cpp>
  +<../examples/simple_repeater>
lib_deps =
  ${nrf52_lora_ota.lib_deps}
  adafruit/Adafruit SSD1306 @ ^2.5.13

[env:RAK_4631_room_server]
extends = rak4631
build_flags =
  ${rak4631.build_flags}
  -UENABLE_OTA
  -D DISABLE_LORA_OTA=1                  ; Full external-sensor build exceeds the in-place OTA ceiling
  -D DISPLAY_CLASS=SSD1306Display
  -D ADVERT_NAME='"Test Room"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D ROOM_PASSWORD='"hello"'
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1
build_src_filter = ${rak4631.build_src_filter}
  +<helpers/ui/SSD1306Display.cpp>
  +<../examples/simple_room_server>

; Explicit lean alternative to the full-sensor, non-OTA room server above.
[env:RAK_4631_room_server_lora_ota_no_external_sensors]
extends = rak4631
build_flags =
  ${rak4631.build_flags}
  ${nrf52_no_external_sensors.build_flags}
  -D DISPLAY_CLASS=SSD1306Display
  -D ADVERT_NAME='"Test Room"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D ROOM_PASSWORD='"hello"'
build_src_filter = ${rak4631.build_src_filter}
  +<helpers/ui/SSD1306Display.cpp>
  +<../examples/simple_room_server>
lib_deps =
  ${nrf52_lora_ota.lib_deps}
  adafruit/Adafruit SSD1306 @ ^2.5.13

[env:RAK_4631_room_server_ethernet]
extends = rak4631
build_flags =
  ${rak4631.build_flags}
  -UENABLE_OTA
  -D DISABLE_LORA_OTA=1                  ; Ethernet image exceeds the safe nRF52 in-place OTA ceiling
  -D DISPLAY_CLASS=SSD1306Display
  -D ADVERT_NAME='"RAK4631 Room Server"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D ROOM_PASSWORD='"hello"'
  -D ETHERNET_ENABLED=1
;  -D MESH_DEBUG=1
build_src_filter = ${rak4631.build_src_filter}
  +<helpers/ui/SSD1306Display.cpp>
  +<../examples/simple_room_server>
lib_deps =
  ${rak4631.lib_deps}
  https://github.com/RAKWireless/RAK13800-W5100S/archive/1.0.2.zip

[env:RAK_4631_companion_radio_usb]
extends = rak4631
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
  ${rak4631.build_flags}
  -D RAK4631_COMPANION_FORCE_LDO=1
  -I examples/companion_radio/ui-new
  -D PIN_USER_BTN=9
  -D PIN_USER_BTN_ANA=31
  -D DISPLAY_CLASS=SSD1306Display
  -D MAX_CONTACTS=350
  -D MAX_GROUP_CHANNELS=40
; NOTE: DO NOT ENABLE -->  -D MESH_PACKET_LOGGING=1
; NOTE: DO NOT ENABLE -->  -D MESH_DEBUG=1
build_src_filter = ${rak4631.build_src_filter}
  +<../examples/companion_radio/*.cpp>
  +<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
  ${rak4631.lib_deps}
  densaugeo/base64 @ ~1.4.0


[env:RAK_4631_companion_radio_ethernet]
extends = rak4631
board_build.ldscript = boards/nrf52840_s140_v6.ld
board_upload.maximum_size = 712704
build_unflags =
  -D EXTRAFS=1
build_flags =
  ${rak4631.build_flags}
  -D RAK4631_COMPANION_FORCE_LDO=1
  -I examples/companion_radio/ui-new
  -D PIN_USER_BTN=9
  -D PIN_USER_BTN_ANA=31
  -D DISPLAY_CLASS=SSD1306Display
  -D MAX_CONTACTS=350
  -D MAX_GROUP_CHANNELS=40
  -D ETHERNET_ENABLED=1
; NOTE: DO NOT ENABLE -->  -D MESH_PACKET_LOGGING=1
; NOTE: DO NOT ENABLE -->  -D MESH_DEBUG=1
;  -D ETHERNET_DEBUG_LOGGING=1
build_src_filter = ${rak4631.build_src_filter}
  +<../examples/companion_radio/*.cpp>
  +<../examples/companion_radio/ui-new/*.cpp>
  +<helpers/nrf52/SerialEthernetInterface.cpp>
lib_deps =
  ${rak4631.lib_deps}
  densaugeo/base64 @ ~1.4.0
  https://github.com/RAKWireless/RAK13800-W5100S/archive/1.0.2.zip


[env:RAK_4631_companion_radio_ble]
extends = rak4631
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
  ${rak4631.build_flags}
  -D RAK4631_COMPANION_FORCE_LDO=1
  -I examples/companion_radio/ui-new
  -D PIN_USER_BTN=9
  -D PIN_USER_BTN_ANA=31
  -D DISPLAY_CLASS=SSD1306Display
  -D MAX_CONTACTS=350
  -D MAX_GROUP_CHANNELS=40
  -D BLE_PIN_CODE=123456
  -D BLE_DEBUG_LOGGING=1
  -D OFFLINE_QUEUE_SIZE=256
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1
build_src_filter = ${rak4631.build_src_filter}
  +<helpers/nrf52/SerialBLEInterface.cpp>
  +<../examples/companion_radio/*.cpp>
  +<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
  ${rak4631.lib_deps}
  densaugeo/base64 @ ~1.4.0

[env:RAK_4631_terminal_chat]
extends = rak4631
build_flags =
  ${rak4631.build_flags}
  -D PIN_USER_BTN=9
  -D PIN_USER_BTN_ANA=31
  -D MAX_CONTACTS=100
  -D MAX_GROUP_CHANNELS=1
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1
build_src_filter = ${rak4631.build_src_filter}
  +<../examples/simple_secure_chat/main.cpp>
lib_deps =
  ${rak4631.lib_deps}
  densaugeo/base64 @ ~1.4.0

[env:RAK_4631_sensor]
extends = rak4631
build_flags =
  ${rak4631.build_flags}
  -UENABLE_OTA
  -D DISABLE_LORA_OTA=1                  ; Full sensor image exceeds the safe nRF52 in-place OTA ceiling
  -D DISPLAY_CLASS=SSD1306Display
  -D ADVERT_NAME='"RAK4631 Sensor"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
;  -D MESH_PACKET_LOGGING=1
  -D MESH_DEBUG=1
build_src_filter = ${rak4631.build_src_filter}
  +<helpers/ui/SSD1306Display.cpp>
  +<../examples/simple_sensor>

[env:RAK_4631_kiss_modem]
extends = rak4631
build_flags =
  ${rak4631.build_flags}
build_src_filter = ${rak4631.build_src_filter}
  +<../examples/kiss_modem/>
lib_deps =
  ${rak4631.lib_deps}
