AgriQL Embedded
AgriQLEdge is the part of AgriQL that runs on the field device. It keeps sensor readings on the board's flash memory until a gateway collects them, and it writes them in the same format the AgriQL server reads.
Two builds, one format. A microcontroller runs AgriQLEdge: the sensor log only, with no SQL. A Raspberry Pi or other Linux gateway runs the full AgriQL server. Both read and write the same flash format, so data moves between them without conversion.
What it does on the board
- Survives power cuts. Readings are written in checksummed frames, and no byte of flash is programmed twice. A frame torn by a power cut is detected and skipped the next time the log mounts.
- Looks after the flash. Erases rotate across the partition. When it is full, the log either refuses new readings or drops the oldest segment, as you choose.
- Forwards whole segments. Send the oldest complete segment over LoRaWAN, NB-IoT, Wi-Fi or serial, then release it when the gateway confirms it.
- Keeps honest time. Stamp readings with the board's millisecond counter and record a clock anchor whenever GNSS, NTP or an RTC gives real time. The server converts ticks to UTC with an error bound for each reading.
- Marks quality. Each reading carries flags: missing, out of range, late, suspect, uncalibrated.
- Small. About 14 KB of flash and 664 bytes of RAM. No heap, no RTOS, no other libraries.
Install
Arduino IDE and CLILibrary Manager, ZIP, or arduino-cli.
PlatformIOOne line in platformio.ini.
Other SDKsESP-IDF, Pico SDK, Zephyr, STM32Cube, and Rust.
Boards and costWhich boards work, and what it costs in flash and RAM.
Flash driversThree functions per board: read, program, erase.
Data to the serverForward segments, or read the chip.
A first sketch
#include <AgriQLEdge.h>
AgriQLRamFlash<1024, 8> ram; // 8 KB of RAM with flash rules: try it on any board
AgriQLEdge logbook;
void setup() {
agriql_flash_t flash = ram.driver();
logbook.begin(flash, 2, true); // 2 erase blocks per segment, drop oldest when full
}
void loop() {
logbook.record(7, (int64_t)millis(), analogRead(A0)); // sensor 7: soil moisture
delay(1000);
}
Replace the RAM driver with a real flash driver to keep the readings across resets. See flash drivers.
What it is not
- It does not run SQL on the board. Queries run on the server.
- It does not work on AVR boards (UNO R3, Mega, Nano classic). They have too little RAM and no flash the sketch can write while running.
- It is not yet precompiled for the Xtensa ESP32, ESP32-S2 and ESP32-S3. The RISC-V ESP32s work: C3, C5, C6, H2 and P4.
- The examples have been compiled for each board family listed on the boards page. They have not been run on real hardware by this project yet.