Make zm_mqtt compile

This commit is contained in:
Isaac Connor 2021-12-29 13:20:07 -05:00
parent 1f0f980e38
commit 034ca92937
2 changed files with 14 additions and 15 deletions

View File

@ -1,6 +1,7 @@
#include "zm.h"
#include "zm_logger.h"
#include "zm_mqtt.h"
#include "zm_monitor.h"
#include "zm_time.h"
#include <sstream>
@ -49,15 +50,13 @@ void MQTT::send() {
int mid;
std::stringstream mqtt_topic;
std::stringstream mqtt_payload;
mqtt_topic << "/a/";
mqtt_topic << api_key;
mqtt_topic << "/p/";
mqtt_topic << project_id;
mqtt_topic << "/device/" << device_id;
mqtt_topic << "/sensor/" << outer_iter->first;
//mqtt_topic << "/a/";
mqtt_topic << "/" << MQTT_TOPIC_PREFIX;
mqtt_topic << "/monitor/" << monitor_->Id();
//mqtt_topic << "/sensor/" << outer_iter->first;
mqtt_topic << "/data";
mqtt_payload << "{ \"value\":"<<inner_iter->second<<" }";
//mqtt_payload << "{ \"value\":"<<inner_iter->second<<" }";
const std::string mqtt_topic_string = mqtt_topic.str();
const std::string mqtt_payload_string = mqtt_payload.str();
@ -84,13 +83,13 @@ void MQTT::addActuator(std::string name, std::function <void(int val)> f) {
int mid;
std::stringstream mqtt_topic;
mqtt_topic << "/a/";
mqtt_topic << api_key;
mqtt_topic << "/p/";
mqtt_topic << project_id;
mqtt_topic << "/device/" << device_id;
mqtt_topic << "/actuator/" << name;
mqtt_topic << "/state";
//mqtt_topic << "/a/";
//mqtt_topic << api_key;
//mqtt_topic << "/p/";
//mqtt_topic << project_id;
//mqtt_topic << "/device/" << device_id;
//mqtt_topic << "/actuator/" << name;
//mqtt_topic << "/state";
subscribe(&mid, mqtt_topic.str().c_str());
}

View File

@ -39,7 +39,7 @@ class MQTT : public mosqpp::mosquittopp {
std::map<std::string, std::map<std::chrono::milliseconds, double>>::iterator sensorListIterator;
std::map<std::string, int> actuatorList;
Monitor *monitor;
Monitor *monitor_;
bool connected_;
};