Compare commits
2 Commits
cc472c72df
...
047d8e0902
Author | SHA1 | Date | |
---|---|---|---|
047d8e0902 | |||
f319f4b97f |
@ -14,7 +14,7 @@
|
|||||||
"export": {
|
"export": {
|
||||||
"exclude": "examples"
|
"exclude": "examples"
|
||||||
},
|
},
|
||||||
"version": "0.1.0",
|
"version": "0.2.0",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "espressif8266",
|
"platforms": "espressif8266",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
16
simple_iot.h
16
simple_iot.h
@ -78,6 +78,7 @@ public:
|
|||||||
bool act_on(String topic, IOTActionHandlerFunction f);
|
bool act_on(String topic, IOTActionHandlerFunction f);
|
||||||
bool report_on(String topic, IOTReportHandlerFunction f, unsigned long update_interval, bool use_cache);
|
bool report_on(String topic, IOTReportHandlerFunction f, unsigned long update_interval, bool use_cache);
|
||||||
void log(const char* fmt, ...) __attribute__((format (printf, 2, 3)));
|
void log(const char* fmt, ...) __attribute__((format (printf, 2, 3)));
|
||||||
|
void publish(String topic, String payload, bool retain=false);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -338,10 +339,23 @@ void SimpleIOT::_mqtt_callback(char* top, byte* pl, uint len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SimpleIOT::_mqtt_publish_report(String topic, String report) {
|
void SimpleIOT::_mqtt_publish_report(String topic, String report) {
|
||||||
|
publish(topic, report, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publishes a message via MQTT.
|
||||||
|
*
|
||||||
|
* @param topic The topic to publish to. Will be appended to base_topic.
|
||||||
|
* @param payload The payload to publish.
|
||||||
|
* @param retain Whether to ask the broker to retain the message.
|
||||||
|
*/
|
||||||
|
void SimpleIOT::publish(String topic, String payload, bool retain) {
|
||||||
|
if (!_mqtt_enabled) return;
|
||||||
String final_topic = String(_mqtt_topic);
|
String final_topic = String(_mqtt_topic);
|
||||||
final_topic.concat(topic);
|
final_topic.concat(topic);
|
||||||
_mqtt_client.publish(final_topic.c_str(), report.c_str(), true);
|
_mqtt_client.publish(final_topic.c_str(), payload.c_str(), retain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** End of MQTT stuff *****/
|
/***** End of MQTT stuff *****/
|
||||||
|
|
||||||
/***** HTTP stuff *****/
|
/***** HTTP stuff *****/
|
||||||
|
Loading…
Reference in New Issue
Block a user