mqtt connection implementation
This commit is contained in:
parent
0dfb066a74
commit
1163f2e30f
7 changed files with 33 additions and 38 deletions
|
@ -1,5 +1,5 @@
|
|||
#include <ESPMegaPRO_OOP.hpp>
|
||||
|
||||
#include <ETH.h>
|
||||
// Instantiate ESPMega
|
||||
ESPMegaPRO espmega = ESPMegaPRO();
|
||||
|
||||
|
@ -11,21 +11,34 @@ void mqtt_callback(char *topic, char *payload)
|
|||
Serial.println(payload);
|
||||
}
|
||||
|
||||
IPAddress ip(192, 168, 0, 11);
|
||||
IPAddress gateway(192, 168, 0, 1);
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Initialize ESPMega
|
||||
espmega.begin();
|
||||
Serial.println("ESPMega initialized");
|
||||
Serial.println("Initializing ESPMega IoT");
|
||||
espmega.enableIotModule();
|
||||
espmega.iot.connectToEthernet();
|
||||
IPAddress ip(192, 168, 0, 11);
|
||||
IPAddress gateway(192, 168, 0, 1);
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
espmega.iot.setETHStaticIp(ip, gateway, subnet);
|
||||
Serial.println("ESPMega IoT module enabled");
|
||||
Serial.println("Setting static IP");
|
||||
Serial.println("Connecting to Ethernet");
|
||||
ETH.begin();
|
||||
delay(1000);
|
||||
ETH.config(ip, gateway, subnet);
|
||||
Serial.println("Static IP set");
|
||||
Serial.println("Begin MQTT Initialization Routine");
|
||||
Serial.println("Setting MQTT Base Topic");
|
||||
espmega.iot.setBaseTopic("/testmegaoop");
|
||||
Serial.println("Initializing MQTT");
|
||||
espmega.iot.connectToMqtt("espmega", "192.168.0.26", 1883);
|
||||
Serial.println("Publishing a test message");
|
||||
espmega.iot.publishRelative("test", "test");
|
||||
Serial.println("Subscribing to test topic");
|
||||
espmega.iot.subscribeRelative("test");
|
||||
Serial.println("Registering MQTT Callback");
|
||||
espmega.iot.registerMqttCallback(mqtt_callback);
|
||||
Serial.println("ESPMega IoT initialized");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue