Configuration
Compile-time parameters, runtime configuration,flags, sensor calibration setup, network addressing, UDP ports,and performance tuning options for the sensor board firmware.
UDP
Main Configuration
Loop Timing
// In* src/sensor_board/main.c #define SENSOR_UDP_DEST_PORT 7
uint8_t dest_ip[4] = {192, 168, 0, 255}; *// Broadcast addressMain Loop Timing
// In src/sensor_board/main.c
#define MAIN_TASK_DELAY_MS 5000 /* poll + transmit interval */ 5 seconds between updates
Heap
All Managementsensors
//are Criticalpolled and transmitted once per interval. Lowering this value increases network traffic and heap threshold
#define CRITICAL_HEAP_THRESHOLD 8192 // 8 KB minimumTask Configuration
const osThreadAttr_t mainTask_attributes = {
.name = "mainTask",
.stack_size = 1024 * 8, // 8 KB stack
.priority =churn (osPriority_t)osPriorityNormal,one };encode allocation per message).
Runtime ConfigurationFlags (main.c)
Changing
Flag | Default | Effect |
|---|---|---|
sendUDP | false | When |
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 Current: 5 seconds
#define MAIN_TASK_DELAY_MS 5000
// Change to 1 second
#define MAIN_TASK_DELAY_MS 1000
// Change to 10 seconds
#define MAIN_TASK_DELAY_MS 10000Enabling/Disabling Sensors
// Current: skip all sensor polling during development
const bool skip_sensor_pollingfree_heap = true;
// To ENABLE actual polling:
const bool skip_sensor_polling = false;
// To SKIP (for testing without hardware):
const bool skip_sensor_polling = true;Adjusting Heap Threshold
// Current: 8 KB criticalxPortGetFreeHeapSize();
if (free_heap < 8192)4096U) { /* critical threshold, was 8192U */
LOGE(TAG, "CRITICAL: Low heap detected!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 Calibration
/* components/sensor_board/ph/ph_sensor.h */
Set#define referencePH_SAMPLE_COUNT voltage40 (typically/* averaging buffer size */
#define PH_DEFAULT_SLOPE 3.3V or 5.0V)
ph_sensor_init(&ph_sensor, 3.3f);5f //* 3.3VSEN0161 reference
// Update calibration (after two-point calibration)
ph_sensor.calibration.offset = 0.0f; // Adjust afterdefault: pH 7.0 test
ph_sensor.calibration.slope = 3.5f;5 * V + offset */
/* runtime calibration */
Adjustph_sensor_calibrate(&ph_sensor, afteroffset, secondslope);
pHph_sensor_reset_calibration(&ph_sensor); test/* offset 0, slope 3.5 */
Load Cell Calibration(HX711)
/* components/sensor_board/load_cell/load_cell_sensor.h */
After#define tareLOAD_CELL_DEFAULT_N_PER_COUNT (no1.0f load):/* load_cell_data[0].tare_offset_countspassthrough until calibrated */
#define LOAD_CELL_GAIN_PULSES 1U /* 1 = adc_reading_no_load;ch A gain 128 */
#define LOAD_CELL_READY_TIMEOUT_MS 200U /* wait for DOUT low */
After/* knownruntime weightcalibration measurement:*/
load_cell_tare(&cell, 10); /* average 10 reads as zero */
scaleload_cell_set_scale(&cell, = (force_newtons)n_per_count); /* (adc_readingmarks - tare_offset)
load_cell_data[0].scale_newtons_per_count = scale_factor;
load_cell_data[0].is_calibrated = true;true */
Network
Pressure Configuration
/ Changing Broadcast AddressFSR
/* kPa = voltage * scale_kpa_per_volt + offset_kpa */To
bepressure_sensor_set_calibration(&sensor, implementedscale_kpa_per_volt, offset_kpa);
ChangingFlow UDP PortSensor
/* components/sensor_board/sampling/flow_sensor/flow_sensor.h */To
be#define implementedFLOW_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