|
@ -1,7 +1,13 @@ |
|
|
#include "MyMQTT.h" |
|
|
#include "MyMQTT.h" |
|
|
|
|
|
|
|
|
#include <AsyncMqttClient.h> |
|
|
#include <AsyncMqttClient.h> |
|
|
|
|
|
|
|
|
#include "hardware.h" |
|
|
#include "hardware.h" |
|
|
|
|
|
#include "shelf.h" |
|
|
|
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
|
|
extern Shelf* shelf; |
|
|
|
|
|
|
|
|
MyMQTT::MyMQTT(void) |
|
|
MyMQTT::MyMQTT(void) |
|
|
: host {mqtt_server}, |
|
|
: host {mqtt_server}, |
|
@ -31,6 +37,21 @@ void MyMQTT::onMqttMessage(char* topic, char* payload, AsyncMqttClientMessagePro |
|
|
Serial.print("incoming: "); |
|
|
Serial.print("incoming: "); |
|
|
Serial.println(topic); |
|
|
Serial.println(topic); |
|
|
Serial.println(payload); |
|
|
Serial.println(payload); |
|
|
|
|
|
if (String(payload).equals("{'num':'0'}")) { |
|
|
|
|
|
shelf->dispense(0); |
|
|
|
|
|
} else if (String(payload).equals("{'num':'1'}")) { |
|
|
|
|
|
shelf->dispense(1); |
|
|
|
|
|
} else if (String(payload).equals("{'num':'2'}")) { |
|
|
|
|
|
shelf->dispense(2); |
|
|
|
|
|
} else if (String(payload).equals("{'num':'3'}")) { |
|
|
|
|
|
shelf->dispense(3); |
|
|
|
|
|
} else if (String(payload).equals("{'num':'4'}")) { |
|
|
|
|
|
shelf->dispense(4); |
|
|
|
|
|
} else if (String(payload).equals("{'num':'5'}")) { |
|
|
|
|
|
shelf->dispense(5); |
|
|
|
|
|
} else if (String(payload).equals("{'num':'6'}")) { |
|
|
|
|
|
shelf->dispense(6); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void MyMQTT::onMqttConnect(bool sessionPresent) { |
|
|
void MyMQTT::onMqttConnect(bool sessionPresent) { |
|
@ -65,7 +86,6 @@ void MyMQTT::connect(void) { |
|
|
|
|
|
|
|
|
void MyMQTT::subscribe(void) { |
|
|
void MyMQTT::subscribe(void) { |
|
|
uint16_t dispenseIdSub = mqttClient.subscribe("sensor/vendingmachine/dispense", 0); |
|
|
uint16_t dispenseIdSub = mqttClient.subscribe("sensor/vendingmachine/dispense", 0); |
|
|
uint16_t dispenseIdSub2 = mqttClient.subscribe("sensor/esp100/#", 0); |
|
|
|
|
|
mqttClient.publish("sensor/vendingmachine/alive", 0, true, "test"); |
|
|
mqttClient.publish("sensor/vendingmachine/alive", 0, true, "test"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|