-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMQTT.hpp
54 lines (42 loc) · 1.11 KB
/
MQTT.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//const char* MQTT_BROKER_ADRESS = "192.168.1.114";
const char* MQTT_BROKER_ADRESS = "10.34.181.200";
const uint16_t MQTT_PORT = 1883;
const char* MQTT_CLIENT_NAME = "ESP8266Client_2";
WiFiClient espClient;
PubSubClient mqttClient(espClient);
void SuscribeMqtt()
{
//mqttClient.subscribe("PT/RFID");
mqttClient.subscribe("PT/RFID_CONTADOR",1);
}
String payload;
int contador_actual = 6;
void PublisMqttRFID(int data)
{
payload = "";
payload = String(data);
mqttClient.publish("PT/RFID_CONTADOR", (char*)payload.c_str());
}
void PublisMqttStringRFID(String data)
{
payload = "";
payload = String(data);
mqttClient.publish("PT/RFID", (char*)payload.c_str());
}
String content = "";
void OnMqttReceived(char* topic, byte* payload, unsigned int length)
{
Serial.print("Received on ");
Serial.print(topic);
Serial.print(": ");
content = "";
for (size_t i = 0; i < length; i++) {
content.concat((char)payload[i]);
}
contador_actual = content.toInt();
Serial.print(content);
Serial.println();
}
int obtener_contador(){
return contador_actual;
}