Hi Everyone, i have a issue on my Arduino Mega with Ethernet Shield on, i am using this code:
#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(192, 168, 0, 234);
IPAddress server(192, 168, 0, 100);
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(“ArduinoMegaMQTTNODE”, “mqttusername”, “mqttpassword”)) {
client.publish(“outTopic”,“hello world”);
client.subscribe(“inTopic”);
}
}
void loop()
{
client.loop();
}
When its started and connected to MQTT i can see its connected, so its working fine, but after 2-3 minutes of connected on my MQTT Broker its disconnect it self, i have alot of MQTT clients to that broker, i can still ping the Arduino, if i unplug the Arduino and plug it back in, its working again for 2-3 minutes, can anyone try my code on the hardware, and see if its only my boards is not working properly?