66 bool toJSON(
char* buffer,
size_t bufferSize)
const;
157 if (!buffer || bufferSize < 100)
return false;
159 JSONBufferWriter writer(buffer, bufferSize);
160 writer.beginObject();
163 writer.name(
"timestamp").value((
int)
timestamp);
167 writer.name(
"primary").value(
primary);
170 writer.name(
"secondary").value(
secondary);
173 writer.name(
"aux1").value(
aux1);
176 writer.name(
"aux2").value(
aux2);
179 writer.name(
"flag1").value(
flag1);
182 writer.name(
"flag2").value(
flag2);
187 return writer.dataSize() > 0;
Abstract interface for all sensors.
virtual bool setup()=0
Initialize the sensor hardware.
virtual void reset()=0
Reset sensor state and clear any cached data.
virtual void onSleep()
Notification that the device is entering deep sleep.
virtual bool onWake()
Notification that the device is waking from deep sleep.
virtual bool usesInterrupt() const
Whether this sensor uses a hardware interrupt for events.
virtual bool initializeHardware()
Initialize underlying hardware after power-on.
virtual int lastErrorCode() const
Last sensor-specific error code (if any).
virtual SensorData getData() const =0
Get the latest sensor data.
virtual bool loop()=0
Poll the sensor for new data.
virtual const char * getSensorType() const =0
Get sensor type identifier.
virtual bool isReady() const =0
Check if sensor is initialized and ready.
virtual bool isHealthy() const
Health check for the sensor.
Generic sensor data structure.
uint16_t aux2
Auxiliary numeric field 2.
bool hasNewData
Flag indicating if this record contains new data.
bool flag2
Spare boolean flag for future use.
uint16_t secondary
Secondary numeric value (score, quality, ...).
char sensorType[16]
Type of sensor ("PIR", "Ultrasonic", etc.).
SensorData()
Construct a new SensorData with default values.
time_t timestamp
When the data was captured (Unix time).
uint16_t aux1
Auxiliary numeric field 1.
bool toJSON(char *buffer, size_t bufferSize) const
Convert sensor data to JSON string for publishing.
uint16_t primary
Main numeric value (count, distance, faceNumber, ...).
bool flag1
Generic boolean flag (e.g., motionDetected, occupied, inRange).