Files
leehughesandClaude Opus 4.5 5554341b49 Add LoRa sensor network support
- Design LoRa packet protocol with CRC16 validation
- Add protocol header files (lora_protocol.h, lora_packet.h)
- Create battery-powered remote node firmware template
  - Support for DHT22, BME680, DS18B20 sensors
  - Deep sleep for battery conservation
  - Automatic gateway registration
- Add LoRa receive to gateway firmware
  - RadioLib SX1262 integration
  - Node registry for tracking up to 16 nodes
  - HTTP forwarding of received readings
  - ACK responses to remote nodes
- Create comprehensive setup guide with wiring diagrams

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 17:50:53 -06:00

155 lines
4.6 KiB
C

/**
* ZNET LoRa Remote Sensor Node Configuration
*
* Edit these values for your specific node deployment.
*/
#ifndef CONFIG_H
#define CONFIG_H
// ============================================================================
// NODE IDENTIFICATION
// ============================================================================
// Unique node ID (see docs/LORA_PROTOCOL.md for ID ranges)
// - 0x0100-0x01FF: Ambient sensors (DHT22)
// - 0x0200-0x02FF: Environmental (BME680)
// - 0xFFFF: Request auto-assignment from gateway
#ifndef NODE_ID
#define NODE_ID 0xFFFF // Auto-assign
#endif
// Human-readable node name (max 8 chars)
#ifndef NODE_NAME
#define NODE_NAME "Remote1"
#endif
// Firmware version
#define FW_VERSION_MAJOR 1
#define FW_VERSION_MINOR 0
// ============================================================================
// SENSOR CONFIGURATION
// ============================================================================
// Sensor type is set by platformio.ini build flags:
// -DSENSOR_TYPE_DHT22 or -DSENSOR_TYPE_BME680
// DHT22 data pin (if not set by build flags)
#ifndef DHT_PIN
#define DHT_PIN 7
#endif
// BME680 I2C address (0x76 or 0x77)
#ifndef BME680_I2C_ADDR
#define BME680_I2C_ADDR 0x76
#endif
// DS18B20 1-Wire pin (if using DS18B20 variant)
#ifndef ONEWIRE_PIN
#define ONEWIRE_PIN 7
#endif
// ============================================================================
// TIMING CONFIGURATION
// ============================================================================
// Report interval in seconds (default: 60 sec)
// Can be overridden by gateway via CONFIG_RESP packet
#ifndef REPORT_INTERVAL_SEC
#define REPORT_INTERVAL_SEC 60
#endif
// How long to wait for ACK (milliseconds)
#define ACK_TIMEOUT_MS 3000
// Maximum retries if no ACK received
#define MAX_RETRIES 3
// How long to listen for incoming packets after TX (milliseconds)
#define RX_WINDOW_MS 500
// ============================================================================
// LORA CONFIGURATION
// ============================================================================
// Frequency (US: 915 MHz, EU: 868 MHz, AS: 923 MHz)
#ifndef LORA_FREQUENCY
#define LORA_FREQUENCY 915.0
#endif
// Spreading factor (7-12, higher = longer range, slower)
#define LORA_SPREADING_FACTOR 9
// Bandwidth (kHz)
#define LORA_BANDWIDTH 125E3
// Coding rate (5-8)
#define LORA_CODING_RATE 7
// Sync word (must match gateway: 0x12)
#define LORA_SYNC_WORD 0x12
// TX power (dBm, max 20 for US)
#define LORA_TX_POWER 14
// ============================================================================
// BATTERY MONITORING
// ============================================================================
// Battery voltage thresholds (millivolts)
#define BATTERY_FULL_MV 4200 // Fully charged LiPo
#define BATTERY_NOMINAL_MV 3700 // Nominal LiPo
#define BATTERY_LOW_MV 3400 // Low battery warning threshold
#define BATTERY_CRITICAL_MV 3200 // Critical - send alert
// ADC calibration
// Voltage divider ratio (if using voltage divider for ADC)
// Set to 1.0 if reading directly (not recommended for LiPo)
#define BATTERY_DIVIDER_RATIO 2.0
// ============================================================================
// ALERT THRESHOLDS (can be overridden by gateway)
// ============================================================================
// Temperature thresholds (Celsius)
#define ALERT_TEMP_HIGH_C 35.0 // Too hot
#define ALERT_TEMP_LOW_C 10.0 // Too cold
// Humidity thresholds (percent)
#define ALERT_HUMIDITY_HIGH 85.0 // Too humid
#define ALERT_HUMIDITY_LOW 20.0 // Too dry
// IAQ threshold (BME680 only)
#define ALERT_IAQ_THRESHOLD 150 // Unhealthy air
// Duration before alert is sent (seconds)
#define ALERT_PERSIST_SEC 30
// ============================================================================
// DEEP SLEEP CONFIGURATION
// ============================================================================
// Use deep sleep between readings (recommended for battery)
#define ENABLE_DEEP_SLEEP 1
// Wake up sources
#define WAKE_ON_TIMER 1 // Wake on interval timer
#define WAKE_ON_GPIO 0 // Wake on external GPIO (for alerts)
#define WAKE_GPIO_PIN 0 // GPIO pin for external wake
// ============================================================================
// DEBUG CONFIGURATION
// ============================================================================
// Enable serial debug output (disable in production to save power)
#define ENABLE_SERIAL_DEBUG 1
// Enable OLED display (disable to save power if not needed)
#define ENABLE_OLED 1
// Blink LED on TX (for debugging)
#define ENABLE_TX_LED 1
#endif // CONFIG_H