./fru-mark/projects/agrosensor

← All projects

AgroSensor

Field-node firmware for precision agriculture. An ESP8266 samples a soil probe and a water board, applies calibration and temperature compensation, and publishes readings as versioned JSON.

  • C++
  • PlatformIO
  • ESP8266
  • IoT
AgroSensor preview

AgroSensor is the field node of the AgroSmart system. A NodeMCU ESP-12E samples two very different sensor boards — a 4-in-1 water board over TTL UART and a 7-in-1 soil probe over RS485 Modbus RTU — and turns their readings into versioned JSON that a backend can trust.

Most of the engineering is in not lying about what the hardware actually measured. The soil probe does not measure nitrogen, phosphorus or potassium: it measures bulk electrical conductivity and back-calculates all three from a linear fit, so every reading carries an npkEstimated flag that stays true until per-soil coefficients are written to the device. Dry soil legitimately reports zero nitrogen, and there is a test asserting that such a frame decodes as valid rather than as a fault.

Architecture

  • C++ / Arduino

    C++11

    Firmware for the NodeMCU ESP-12E. Both sensors run on SoftwareSerial, which leaves UART0 free on USB for logging throughout.

  • PlatformIO

    6.x

    Build, flash and test runner. A native environment runs the host-side unit tests with no board attached.

  • NodeMCU ESP-12E

    ESP8266

    ESP8266 module doing the sampling and publishing. Not 5V tolerant, so every sensor line goes through a divider.

  • Modbus RTU over RS485

    RTU

    Transport for the 7-in-1 soil probe at 4800 8N1, through an auto-flow-control converter with no DE/RE pin.

  • TTL UART

    8N1

    Transport for the 4-in-1 water board at 9600 8N1. The two boards run at different baud rates, which is the most common cause of an apparently dead sensor.

  • Unity test framework

    2.5

    194 passing host-side tests, including the case where dry soil legitimately reports zero nitrogen.

Applications

  • Measuring soil moisture, temperature, conductivity, pH and NPK on smallholder plots.
  • Reading water pH, sunlight, temperature and water level from the companion 4-in-1 board.
  • Publishing versioned JSON telemetry to the AgroSmart ingest API over HTTP.
  • Spooling readings through a network outage and replaying them once the uplink returns.
  • Provisioning over a captive portal, so a node reaches the field without credentials compiled in.

Access the project

The host-side test suite runs with no hardware at all — one PlatformIO command against the native environment. To go further, flash a NodeMCU and develop the uplink against the bundled mock ingest server, which can simulate an outage or a given failure rate. Read the wiring notes before applying power: the ESP8266 is not 5V tolerant.