String customDevice::get(Topic &topic) { /* ~/get └─device (level 2) └─sensor1 (level 3) */ logging.debug("device get topic " + topic.topic_asString()); if (topic.getItemCount() != 4) // ~/get/device/sensor1 return TOPIC_NO; if (topic.itemIs(3, "sensor1")) { return String(measure()); } else { return TOPIC_NO; } }
String customDevice::set(Topic &topic) { /* ~/set └─device (level 2) └─yourItem (level 3) */ logging.debug("device set topic " + topic.topic_asString() + " to " + topic.arg_asString()); if (topic.getItemCount() != 4) // ~/set/device/yourItem return TOPIC_NO; if (topic.itemIs(3, "yourItem")) { return TOPIC_OK; } else { return TOPIC_NO; } }