Arduino Library
Send readings from your own sketch with the HydroNode Arduino library. It takes care of the network, time, TLS and signing every request. WiFi on every ESP32 and the ESP8266, Ethernet, LTE-M and NB-IoT on any board with an Arduino client.
Get the Sensor ID and Secret
The library signs every request with your sensor's Sensor ID and Secret. Create the sensor and copy both from Settings → Connection:
Install the library
The library is in the official Arduino Library Manager. Open Tools → Manage Libraries, search for HydroNode-Library and install it. The IDE offers to install the dependencies along with it: say yes. For reference, these are:
ArduinoJsonArduinoHttpClientWiFiManagerTinyGSMESP_SSLClientIn PlatformIO, pin the Git tag. The registry does not always carry the newest version right away:
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps =
https://github.com/TexhFexLabs/HydroNode-Library.git#1.9.0 Or clone the repository into your libraries/ folder and install the dependencies above by hand:
git clone https://github.com/TexhFexLabs/HydroNode-Library.git ~/Arduino/libraries/HydroNodeA complete .ino sketch
Fill in YOUR_WIFI_SSID, YOUR_WIFI_PASSWORD, your Sensor ID and your Secret, then upload. sendValues() sends every value of one round in a single signed request, stamped with the time it was measured. That saves one connection per value, which is several seconds on an ESP8266. The library fetches the time itself and refreshes it every 30 minutes.
#include <HydroNode.h>
const char* WIFI_SSID = "YOUR_WIFI_SSID";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
// Settings > Connection on the sensor page
const char* SENSOR_ID = "YOUR_SENSOR_ID";
const char* SECRET_KEY = "YOUR_SECRET";
HydroNode hydro(SENSOR_ID, SECRET_KEY);
// Command "pump" with type UINT32 from the HydroNode app
void pumpCallback(uint32_t ms) {
if (ms > 10000) ms = 10000; // never trust a network value blindly
Serial.printf("Pump for %u ms\n", ms);
// run the pump for ms milliseconds
}
void setup() {
Serial.begin(115200);
hydro.setDebug(Serial); // optional: prints every request and answer
while (!hydro.connectWiFi(WIFI_SSID, WIFI_PASSWORD)) {
Serial.println("WiFi failed, retrying");
}
hydro.begin(); // fetches the time, needed for every signature
hydro.onUInt32("pump", pumpCallback);
}
void loop() {
// Replace with real readings from your hardware
HydroNodeValue reading[] = {
{"TEMPERATURE", 22.4}, // °C
{"HUMIDITY", 65.2}, // %
};
int status = hydro.sendValues(reading, 2);
Serial.printf("HydroNode answered %d\n", status);
delay(60000); // one round per minute
} HydroNode accepts one value per measurement type every 10 seconds, and up to 64 values in one request. sendValue("TEMPERATURE", 22.4) still works for a single value.
Check that the values arrive
Open the serial monitor at 115200 baud. HydroNode answered 202 means accepted. Then open the sensor page in HydroNode and press the ` key. The device console shows every request the moment it arrives, with the signature check and how far the device clock is off.
| Answer | Meaning | What to do |
|---|---|---|
202 | Accepted | Nothing, all good. |
401 | Signature or time wrong | Check the Sensor ID and Secret. The console names the exact reason. |
429 | Too fast | Send at most one value per measurement type every 10 seconds. |
-1 | No network | Check the WiFi name and password, the cable or the modem. |
-2 | No time | Allow UDP port 123 (NTP) on your network. |
-3 | Connection failed | TLS or network error. The library tries again with the next round. |
-4 | Invalid type name | Use upper case: TEMPERATURE, not temperature. |
-5 | Invalid value | The value is NaN or infinite. Check the sensor reading. |
A rejected request shows up in red in the console, with the exact reason. The Rejected filter shows only those.
Send commands to the device
A command has a name, a value type and a value. On the device you register one callback per name and type. One name can have several types, for example relay1 true and relay1 1400.
hydro.onBool(name, fn)hydro.onInt32(name, fn)hydro.onUInt32(name, fn)hydro.onInt64(name, fn)hydro.onUInt64(name, fn)hydro.onString(name, fn)// App: name "lamp", type BOOL, value true
hydro.onBool("lamp", [](bool on) {
digitalWrite(LAMP_PIN, on ? HIGH : LOW);
});
// Same name, type UINT32: "lamp 1400" lights it for 1.4 s
hydro.onUInt32("lamp", [](uint32_t ms) {
ms = min(ms, (uint32_t)10000); // local safety limit
digitalWrite(LAMP_PIN, HIGH);
delay(ms);
digitalWrite(LAMP_PIN, LOW);
});
// App: name "display", type STRING, value "Hello"
hydro.onString("display", [](const String& text) {
lcd.print(text);
});- 1Send itOn the sensor page press Send command and fill in name, type and value. Or type
lamp:bool truein the Commands tab of the console. - 2Wait for the next roundCommands travel with the answer to the next value the device sends. With one round per minute, that takes up to a minute.
- 3Read the statusConfirmed means the device has a matching callback and started it. Declined names the reason and the callback never runs: No handler on the device when the name is unknown, Type does not match when the callback expects another type, Value not accepted when the value does not fit, for example
-1forUINT32.
Hex like 0x20124 is accepted for the integer types and arrives as the number 131364. There is no float type: send a whole number in a fixed unit, for example tenths of a degree. Commands are delivered at most once. If a response is lost, send the command again.
Switches and choices with a real state
For a relay or a mode in HydroNode's Controls, let the device report the state it really took as a value (0/1, or the index of a mode) and listen to a command for it. In HydroNode, open that data point, set Read as to On or off or Choice and turn on Send a command when it is set with the command's name and type (BOOL or UINT32). Controls then show the change as waiting until the reported value matches. The library example EnumState is a heater with three modes built this way.
Protect a battery device
From library 1.8.0, HydroNodeBatteryGuard looks after the battery the same way HydroNode firmware does: it sends less often below Save, turns WiFi and outputs off below Radio off, sleeps an hour at a time below Standby and runs normally again from Resume. Before it goes quiet it sends one last round, so HydroNode shows Low battery standby instead of Offline.
With onSettings() the sketch also takes a new send interval and new thresholds that you change in HydroNode under Settings → Battery → On the device. The example PowerThresholds in the library shows the whole round, including deep sleep. Every threshold and rule is in Battery and Power.
Ethernet, LTE-M and NB-IoT
The signature does not care how the bytes travel. From library 1.9.0 the network is a separate object, the transport. Pick the one for your hardware and keep the rest of the sketch: values, commands and battery settings work the same everywhere. Only what you include is compiled, so a WiFi sketch carries no modem code.
| Network | Hardware | Example |
|---|---|---|
| WiFi | Every ESP32 and the ESP8266 | QuickStart |
| Ethernet | ESP32 with built-in port (WT32-ETH01, Olimex ESP32-POE) | Ethernet_ESP32 |
| Ethernet | W5500 module on SPI, any board | Ethernet_W5500 |
| LTE-M, NB-IoT | SIM7080G, SIM7000, BG95, SARA-R4 | Cellular_SendNow |
| LTE Cat-1 | A7670, SIM7600, TLS in the modem | Cellular_ModemTLS |
| WiFi, else LTE-M | ESP32 with a modem | WiFi_Fallback_LTE |
| Any client | UNO R4 WiFi, MKR, Nano 33 IoT, Pico W | Board_MKR_WiFi1010 |
A cellular board in short. TinyGSM drives the modem, ESP_SSLClient runs TLS on the board, and the transport takes the time from the modem:
#define TINY_GSM_MODEM_SIM7080
#include <TinyGsmClient.h>
#include <ESP_SSLClient.h>
#include <HydroNodeClient.h>
#include <HydroNodeCellular.h>
#include <HydroNodeCerts.h>
TinyGsm modem(Serial1);
TinyGsmClient tcp(modem);
ESP_SSLClient tls;
HydroNodeCellular<TinyGsm> lte(modem, tls, HydroNodeNet::LTE_M);
HydroNodeClient hydro(lte, SENSOR_ID, SECRET_KEY);
void setup() {
tls.setClient(&tcp);
tls.setCACert(HYDRONODE_CA_BUNDLE);
lte.onBeforeConnect([](uint32_t now) { tls.setX509Time(now); });
modem.init();
modem.waitForNetwork();
modem.gprsConnect("iot.1nce.net"); // the APN of your SIM
}
void loop() {
HydroNodeValue reading[] = {{"TEMPERATURE", 14.2}};
hydro.sendValues(reading, 1);
delay(300000);
}The fleet view shows the network of the last request: WiFi, Ethernet, LTE-M, NB-IoT or LTE, with the signal from the modem.
Keep readings and send them later
From library 1.9.0 a HydroNodeBuffer keeps readings until they reach HydroNode. Every reading keeps the time it was measured, so the chart looks the same as if it had been sent right away. It covers two cases:
- 1Never lose a readingWhen the network is gone,
sendValues()stores the round and sends it with the next successful request. - 2Send less often
record()stores without radio,flush()sends many rounds in one request. A cellular board measures every 6 minutes and sends once an hour.
// Memory that survives deep sleep on the ESP32 (about 100 rounds)
RTC_DATA_ATTR uint8_t mem[4096];
HydroNodeBuffer buffer(mem, sizeof(mem));
void setup() {
buffer.begin(); // keeps what was stored before the sleep
hydro.attachBuffer(buffer);
HydroNodeValue reading[] = {{"TEMPERATURE", 12.3}};
hydro.record(reading, 1); // store, no radio
// Ten readings stored, or the oldest is an hour old: one request for all
if (hydro.flushDue(10, 3600) && connect()) hydro.flush();
esp_deep_sleep(6 * 60 * 1000000ULL);
} Rounds can be up to 7 days old. A round sent twice is stored once. HydroNode learns the sending rhythm from the deliveries, so a board that sends once an hour is not shown as delayed in between. In the device console a late round shows when it was measured. Full examples: Cellular_CollectHourly, Buffer_OfflineSafe and Buffer_DeepSleep. From SIM card to the first stored reading, and why a battery board sends once an hour: ESP32 over LTE-M, NB-IoT and Ethernet.
Captive portal setup via WiFiManager
The example WiFiManagerSetup uses WiFiManager instead of a hardcoded network. On first boot the device opens an access point named HydroNode-Setup-XXXX (the last four characters of your Sensor ID, from hydro.getApName()). Connect to it from a phone or laptop, and a captive portal asks for your network. The device saves it to flash and restarts into normal operation. No password is compiled into the firmware.
All examples are in the library's examples/ folder on GitHub.
Make an outdoor sensor a station
If this board is part of an outdoor weather or environmental installation, it can become a station without changing the sketch or switching to LoRaWAN. A station has a location and can appear on the public map.
- 1Save the sensor as OutdoorOn the sensor page open Settings → General, set Environment to Outdoor and save. Indoor sensors cannot be stations.
- 2Turn on Use as a stationThe switch sits in the Station group of the same section. The Sensor ID, the Secret and every reading stay as they are.
- 3Set the locationLocation and public map opens the station settings. Enter the location, and turn on Show on the public map only if you want others to see it.
TEMPERATURE, is case-sensitive. Always use the exact uppercase key. The library refuses names that are not upper case letters, digits and underscores (-4), and a typo like TEMPERATUR creates a new measurement instead of an error. See every type on the Sensor Types reference. 


