Configuration
Compile-time parameters, runtime flags, sensor calibration setup, network addressing, and performance tuning options for the sensor board firmware.
Main Loop Timing
/* src/sensor_board/main.c */
#define MAIN_TASK_DELAY_MS 5000 /* poll + transmit interval */
All sensors are polled and transmitted once per interval. Lowering this value increases network traffic and heap churn (one encode allocation per message).
Runtime Flags (main.c)
Flag | Default | Effect |
|---|---|---|
sendUDP | false | When false, udp_send_envelope() returns immediately: nothing is encoded or transmitted. Set to true to enable network output. |
skip_sensor_polling | false | When true, the pH/IMU/load cell/pressure polling block is skipped (flow and pump still run). |
Heap Management
uint32_t free_heap = xPortGetFreeHeapSize();
if (free_heap < 4096U) { /* critical threshold, was 8192U */
LOGE(TAG, "CRITICAL: Low heap! Free: %lu bytes", free_heap);
osDelay(10000);
continue;
}
- FreeRTOS heap size: 65536 bytes (configTOTAL_HEAP_SIZE, set in CubeMX)
- Critical threshold: 4096 bytes free
- LwIP heap: 16 KB at 0x30004900 (separate from the FreeRTOS heap)
Network Configuration
All addresses live in components/common/networking_constants/ip_mac_constants.h:
#define NETWORK_IP {192, 168, 0, 111} /* this board */
#define NETWORK_MAC {0x00, 0x80, 0xe1, 0x00, 0x00, 0x00}
#define SAMPLE_BOARD_IP {192, 168, 0, 222} /* UDP destination */
#define SAMPEL_BOARD_MAC {0x00, 0x43, 0x23, 0xee, 0x21, 0x64}
#define GATEWAY {192, 168, 0, 1}
#define NETMASK {255, 255, 255, 0}
#define PORT 1500 /* UDP port */
Changing the Destination Address or Port
- Edit SAMPLE_BOARD_IP / SAMPEL_BOARD_MAC (used both for sending and for the static ARP entry) or PORT in ip_mac_constants.h.
- Rebuild; no other file references the raw addresses.
MAC Address Filtering
Three source MACs are allowed through the hardware filter, configured in MainTask:
int mac1[6] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
int mac2[6] = {0x12, 0x23, 0x34, 0x45, 0x56, 0x67};
int mac3[6] = {0x90, 0x2e, 0x16, 0xbe, 0x1b, 0x33};
ETH_setup_MAC_address_filtering(mac1, mac2, mac3);
UDP Transmit Queues
#define SENSOR_SEND_QUEUE_SIZE 80 /* entries per priority queue, x2 queues */
Sensor Hardware Build Flags
The analog drivers are compile gated so the firmware links without ADC hardware. Add these to build_flags in platformio.ini once the corresponding CubeMX peripherals exist:
Flag | Effect |
|---|---|
-D PH_SENSOR_USE_ADC | Enables the pH ADC read path (optional: -D PH_SENSOR_ADC_HANDLE=hadc1, -D PH_SENSOR_ADC_MAX=65535, -D PH_SENSOR_ADC_TIMEOUT_MS=100) |
-D PRESSURE_USE_ADC | Enables the pressure/FSR ADC read path; bind each unit with pressure_sensor_init_hw() |
-D PUMP_MAX_RPM_EST=100 | Override the pump RPM estimate used when converting duty cycle to speed_rpm |
-D CONFIG_LOG_LEVEL=LOG_INFO | Log verbosity (already set in platformio.ini) |
Sensor Calibration Configuration
pH Sensor
/* components/sensor_board/ph/ph_sensor.h */
#define PH_SAMPLE_COUNT 40 /* averaging buffer size */
#define PH_DEFAULT_SLOPE 3.5f /* SEN0161 default: pH = 3.5 * V + offset */
/* runtime calibration */
ph_sensor_calibrate(&ph_sensor, offset, slope);
ph_sensor_reset_calibration(&ph_sensor); /* offset 0, slope 3.5 */
Load Cell (HX711)
/* components/sensor_board/load_cell/load_cell_sensor.h */
#define LOAD_CELL_DEFAULT_N_PER_COUNT 1.0f /* passthrough until calibrated */
#define LOAD_CELL_GAIN_PULSES 1U /* 1 = ch A gain 128 */
#define LOAD_CELL_READY_TIMEOUT_MS 200U /* wait for DOUT low */
/* runtime calibration */
load_cell_tare(&cell, 10); /* average 10 reads as zero */
load_cell_set_scale(&cell, n_per_count); /* marks is_calibrated = true */
Pressure / FSR
/* kPa = voltage * scale_kpa_per_volt + offset_kpa */
pressure_sensor_set_calibration(&sensor, scale_kpa_per_volt, offset_kpa);
Flow Sensor
/* components/sensor_board/sampling/flow_sensor/flow_sensor.h */
#define FLOW_SENSOR_PULSES_PER_ML_X10 55U /* FM-PS2216: 5.5 pulses/ml */
#define FLOW_SENSOR_SAMPLE_WINDOW_MS 1000U /* rate calculation window */
#define FLOW_SENSOR_MAX_FLOW_ML_MIN 150U /* plausibility clamp */
Changing the Sensor Poll Interval
- Edit MAIN_TASK_DELAY_MS in src/sensor_board/main.c.
- Keep it well above the slowest blocking read (HX711 ready wait can take up to 200 ms per cell).
- The flow rate is computed per poll from the pulse count, so the interval also sets flow rate resolution.
Enabling / Disabling Sensors
- All sensor polling: skip_sensor_polling flag in main.c (flow and pump are outside this block)
- Individual analog sensors: leave their build flag unset; the driver returns RESULT_ERR_UNIMPLEMENTED and the sensor reports IDLE / DISCONNECTED without affecting the rest of the loop
No comments to display
No comments to display