5.9.1f * Upgrade library ArduinoJson to 5.11.2 * Upgrade library IRRemoteEsp8266 to 2.2.1 + 2 commits but tweaked some protocols to keep code usage small * Upgrade library NeoPixelBus to 2.2.9 * Upgrade library OneWire to 2.3.3 + 6 commits * Formalize library PubSubClient to 2.6 + 9 commits and additional delay * Add optional ADS1115 driver as alternative for unsupported I2Cdevlib in esp8266-core 2.4.0-rc2 * Fix wrong response name for command HlwISet (#1214)
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
/*
|
|
Basic MQTT example with Authentication
|
|
|
|
- connects to an MQTT server, providing username
|
|
and password
|
|
- publishes "hello world" to the topic "outTopic"
|
|
- subscribes to the topic "inTopic"
|
|
*/
|
|
|
|
#include <SPI.h>
|
|
#include <Ethernet.h>
|
|
#include <PubSubClient.h>
|
|
|
|
// Update these with values suitable for your network.
|
|
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
|
|
IPAddress ip(172, 16, 0, 100);
|
|
IPAddress server(172, 16, 0, 2);
|
|
|
|
void callback(char* topic, byte* payload, unsigned int length) {
|
|
// handle message arrived
|
|
}
|
|
|
|
EthernetClient ethClient;
|
|
PubSubClient client(server, 1883, callback, ethClient);
|
|
|
|
void setup()
|
|
{
|
|
Ethernet.begin(mac, ip);
|
|
// Note - the default maximum packet size is 128 bytes. If the
|
|
// combined length of clientId, username and password exceed this,
|
|
// you will need to increase the value of MQTT_MAX_PACKET_SIZE in
|
|
// PubSubClient.h
|
|
|
|
if (client.connect("arduinoClient", "testuser", "testpass")) {
|
|
client.publish("outTopic","hello world");
|
|
client.subscribe("inTopic");
|
|
}
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
client.loop();
|
|
}
|