-
Notifications
You must be signed in to change notification settings - Fork 0
/
MQTT.ino
31 lines (22 loc) · 796 Bytes
/
MQTT.ino
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
void mqtt_connect(const char* server, const char* port, const char* name) {
Serial.println();
Serial.print("Connecting to MQTT server : "); Serial.print(server); Serial.print(":"); Serial.println(port);
mqtt.begin(server,atoi(port),wifi);
while (!mqtt.connect(name)) {
Serial.print(".");
delay(500);
}
Serial.println(" connected.");
// Announce us on the announce topic
mqtt.publish(MQTT_PREFIX"/announce", name);
// Subscribe to our dedicated topic
//mqtt.subscribe(MQTT_PREFIX"/"MODULE_NAME);
//mqtt.subscribe(MQTT_PREFIX"/"MODULE_NAME"/#");
}
void messageReceived(String topic, String payload, char * bytes, unsigned int length) {
Serial.print("incoming: ");
Serial.print(topic);
Serial.print(" - ");
Serial.print(payload);
Serial.println();
}