ZUNO_REPORTS_HANDLER()

This macro is used to setup up a handler for incoming reports from other sensors. Syntax has changed starting from 2.1.5 release ZUNO_REPORTS_HANDLER(reportType, reportHandler) reportType type of the report to handle: Battery, SensorMultilevel, SensorBinary, Notification, SwitchMultilevel, SwitchBinary, Meter, Basic. reportHandler pointer to a user defined function that parses the incoming report of the defined type. void reportHandler(void) There are few helpful marco to parse the reported data inside the report handler:
  • Generic
  • REPORT_NODE_ID() returns the sender Node Id
  • Basic
  • REPORT_BASIC_VALUE() returns the value
  • Switch Multilevel
  • REPORT_SWITCH_MULTILEVEL_VALUE() returns the value
  • Switch Binary
  • REPORT_SWITCH_BINARY_VALUE() returns the value
  • Notification (Alarm)
  • REPORT_NOTIFICATION_TYPE() returns notification type
  • REPORT_NOTIFICATION_EVENT() returns notification event
  • REPORT_NOTIFICATION_EVENT_PARAM(i) returns notification parameters
  • REPORT_NOTIFICATION_STATUS() returns notification status
  • Sensor Binary
  • REPORT_SENSOR_BINARY_TYPE() returns sensor type
  • REPORT_SENSOR_BINARY_VALUE() returns the value
  • Sensor Multilevel
  • REPORT_SENSOR_MULTILEVEL_TYPE() returns sensor type
  • REPORT_SENSOR_MULTILEVEL_SCALE() returns sensor scale
  • REPORT_SENSOR_MULTILEVEL_UNITS() returns sensor units
  • REPORT_SENSOR_MULTILEVEL_PRECISION() returns sensor precision (number of digits after .)
  • REPORT_SENSOR_MULTILEVEL_SIZE() returns sensor value size (1, 2 or 4 bytes)
  • REPORT_SENSOR_MULTILEVEL_VALUE_1B() returns the BYTE value for size = 1 bytes
  • REPORT_SENSOR_MULTILEVEL_VALUE_2B() returns the WORD value for size = 2 bytes
  • REPORT_SENSOR_MULTILEVEL_VALUE_4B() returns the DWORD value for size = 4 bytes
  • Meter
  • REPORT_METER_TYPE() returns sensor type
  • REPORT_METER_RATE() returns sensor type
  • REPORT_METER_SCALE() returns sensor scale
  • REPORT_METER_UNITS() returns sensor units
  • REPORT_METER_PRECISION() returns sensor precision (number of digits after .)
  • REPORT_METER_SIZE() returns sensor value size (1, 2 or 4 bytes)
  • REPORT_METER_VALUE_1B() returns the BYTE value for size = 1 bytes
  • REPORT_METER_VALUE_2B() returns the WORD value for size = 2 bytes
  • REPORT_METER_VALUE_4B() returns the DWORD value for size = 4 bytes
  • Battery
  • REPORT_BATTERY_VALUE() returns battery level
Z-Uno will save the highest security level it used to communicate with a devices. The same level will be expected for a report.
        ZUNO_REPORTS_HANDLER(reportType, reportHandler);

void reportHandler() {
  ... REPORT_XXX_VALUE_1B() ...
}
It is suggested to return as fast as possible from the reports handler and do the main work in the loop().
        ZUNO_REPORTS_HANDLER(Battery, BatteryReport);
ZUNO_REPORTS_HANDLER(SensorMultilevel, SensorMultilevelReport);
ZUNO_REPORTS_HANDLER(SensorBinary, SensorBinaryReport);
ZUNO_REPORTS_HANDLER(Notification, NotificationReport);
ZUNO_REPORTS_HANDLER(SwitchMultilevel, SwitchMultilevelReport);
ZUNO_REPORTS_HANDLER(SwitchBinary, SwitchBinaryReport);
ZUNO_REPORTS_HANDLER(Meter, MeterReport);
ZUNO_REPORTS_HANDLER(Basic, BasicReport);

#define SERIAL Serial0
ZUNO_ENABLE(LOGGING_DBG LOGGING_EVENTS);

void logReportTitle(char * text) {
    SERIAL.print(millis());
    SERIAL.print("    ");
    SERIAL.print(text);
    SERIAL.print(" NODE:");
    SERIAL.print(REPORT_NODE_ID());
    SERIAL.print(" VALUE:");
}

void BatteryReport() {
    logReportTitle("BATTERY");
    SERIAL.println(REPORT_BATTERY_VALUE(), HEX);
}

void SensorMultilevelReport() {
    logReportTitle("SENSOR MULTILEVEL");
    switch(REPORT_SENSOR_MULTILEVEL_SIZE()) {
        case 1:
            SERIAL.fixPrint(int(REPORT_SENSOR_MULTILEVEL_VALUE_1B()), REPORT_SENSOR_MULTILEVEL_PRECISION());
            break;
        case 2:
            SERIAL.fixPrint(int(REPORT_SENSOR_MULTILEVEL_VALUE_2B()), REPORT_SENSOR_MULTILEVEL_PRECISION());
            break;
        case 4:
            SERIAL.fixPrint(long(REPORT_SENSOR_MULTILEVEL_VALUE_4B()), REPORT_SENSOR_MULTILEVEL_PRECISION());
            break;
    }
    SERIAL.print(" TYPE:");
    SERIAL.print(REPORT_SENSOR_MULTILEVEL_TYPE(), HEX);
    SERIAL.print(" SCALE:");
    SERIAL.println(REPORT_SENSOR_MULTILEVEL_SCALE(), HEX);
}

void SensorBinaryReport() {
    logReportTitle("SENSOR BINARY");
    SERIAL.print(REPORT_SENSOR_BINARY_VALUE(), HEX);
    SERIAL.print(" TYPE:");
    SERIAL.println(REPORT_SENSOR_BINARY_TYPE());
}

void SwitchBinaryReport() {
    logReportTitle("SWITCH BINARY");
    SERIAL.println(REPORT_SWITCH_BINARY_VALUE(), HEX);
}

void SwitchMultilevelReport() {
    logReportTitle("SWITCH MULTILEVEL");
    SERIAL.println(REPORT_SWITCH_MULTILEVEL_VALUE(), HEX);
}

void NotificationReport() {
    logReportTitle("NOTIFICATION ");
    SERIAL.print(REPORT_NOTIFICATION_STATUS(), HEX);
    SERIAL.print(" TYPE:");
    SERIAL.print(REPORT_NOTIFICATION_TYPE(), HEX);
    SERIAL.print(" EVENT:");
    SERIAL.print(REPORT_NOTIFICATION_EVENT(), HEX);
    SERIAL.print(" PARAM:");
    SERIAL.println(REPORT_NOTIFICATION_EVENT_PARAM(0), HEX);
}

void MeterReport() {
     logReportTitle("METER");
     switch(REPORT_METER_SIZE()){
        case 1:
            SERIAL.fixPrint(int(REPORT_METER_VALUE_1B()), REPORT_METER_PRECISION());
            break;
        case 2:
            SERIAL.fixPrint(int(REPORT_METER_VALUE_2B()), REPORT_METER_PRECISION());
            break;
        case 4:
            SERIAL.fixPrint(long(REPORT_METER_VALUE_4B()), REPORT_METER_PRECISION());
            break;
    }
    SERIAL.print(" TYPE:");
    SERIAL.print(REPORT_METER_TYPE(), HEX);
    SERIAL.print(" SCALE:");
    SERIAL.println(REPORT_METER_SCALE(), HEX);
}

void BasicReport() {
    logReportTitle("BASIC");
    SERIAL.println(REPORT_BASIC_VALUE(), HEX);
}

void setup() {
    SERIAL.begin(115200);
    SERIAL.print("START");
}

void loop() {
    delay(1000);
}