Arduino MEGA2560 with Ethernet Shield and MQTT
hello guys,
i´m play around arduino mega ethernet shield , mqtt protocol, since i´have issues i´hope guys can me solve problem.
i work mosquitto in pc make mqtt broker , running, look:
c:\program files (x86)\mosquitto>mosquitto -v
1468107949: mosquitto version 1.4.9 (build date 08/06/2016 11:59:29.51) starting
1468107949: using default config.
1468107949: opening ipv6 listen socket on port 1883.
1468107949: opening ipv4 listen socket on port 1883.
1468107949: new connection 192.168.0.2 on port 1883.
1468107949: new client connected 192.168.0.2 lens_p4trrdv0c3dtmz00jaoxawhqi
cm (c1, k120, u'iotuser').
1468107949: sending connack lens_p4trrdv0c3dtmz00jaoxawhqicm (0, 0)
1468107975: received publish lens_p4trrdv0c3dtmz00jaoxawhqicm (d0, q0, r0, m0,
'arduino/topic', ... (24 bytes))
i test mqttlens publish 1 message , result succeeded, mqtt protocol working fine!
the problem after grab basic example pubsubclient , work around bit see code not working, not receive message arduino broker.
the code simple, not work well, can fix code put arduino publish , subcribe topic, code:
#include <spi.h>
#include <ethernet.h>
#include <pubsubclient.h>
byte mac[] = {0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed};
ipaddress ip(192, 168, 0, 200);
ipaddress server(192, 168, 0, 2);
void callback(char* topic, byte* payload, unsigned int length)
{
serial.print("message arrived [");
serial.print(topic);
serial.print("] ");
(int i=0;i<length;i++)
{
serial.print((char)payload);
}
serial.println();
}
ethernetclient ethclient;
pubsubclient client(server, 1883, callback, ethclient);
void setup()
{
serial.begin(9600);
ethernet.begin(mac, ip);
client.publish("arduino/topic","simple message");
client.subscribe("arduino/topic");
}
void loop()
{
client.loop();
}
who missing or wrong?
i change many things code , search lot before request community, ok
thanks in advance
i´m play around arduino mega ethernet shield , mqtt protocol, since i´have issues i´hope guys can me solve problem.
i work mosquitto in pc make mqtt broker , running, look:
c:\program files (x86)\mosquitto>mosquitto -v
1468107949: mosquitto version 1.4.9 (build date 08/06/2016 11:59:29.51) starting
1468107949: using default config.
1468107949: opening ipv6 listen socket on port 1883.
1468107949: opening ipv4 listen socket on port 1883.
1468107949: new connection 192.168.0.2 on port 1883.
1468107949: new client connected 192.168.0.2 lens_p4trrdv0c3dtmz00jaoxawhqi
cm (c1, k120, u'iotuser').
1468107949: sending connack lens_p4trrdv0c3dtmz00jaoxawhqicm (0, 0)
1468107975: received publish lens_p4trrdv0c3dtmz00jaoxawhqicm (d0, q0, r0, m0,
'arduino/topic', ... (24 bytes))
i test mqttlens publish 1 message , result succeeded, mqtt protocol working fine!
the problem after grab basic example pubsubclient , work around bit see code not working, not receive message arduino broker.
the code simple, not work well, can fix code put arduino publish , subcribe topic, code:
#include <spi.h>
#include <ethernet.h>
#include <pubsubclient.h>
byte mac[] = {0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed};
ipaddress ip(192, 168, 0, 200);
ipaddress server(192, 168, 0, 2);
void callback(char* topic, byte* payload, unsigned int length)
{
serial.print("message arrived [");
serial.print(topic);
serial.print("] ");
(int i=0;i<length;i++)
{
serial.print((char)payload);
}
serial.println();
}
ethernetclient ethclient;
pubsubclient client(server, 1883, callback, ethclient);
void setup()
{
serial.begin(9600);
ethernet.begin(mac, ip);
client.publish("arduino/topic","simple message");
client.subscribe("arduino/topic");
}
void loop()
{
client.loop();
}
who missing or wrong?
i change many things code , search lot before request community, ok
thanks in advance
firstly- please use code tags </> post code- makes more readable.
did try run original version here? version lacks code calls reconnnect() never connected mqtt broker , allows no delay() enable ethernet link established.
if published example code library doesnt work hardware or setup, not problem example code.
did try run original version here? version lacks code calls reconnnect() never connected mqtt broker , allows no delay() enable ethernet link established.
if published example code library doesnt work hardware or setup, not problem example code.
Arduino Forum > Topics > Home Automation and Networked Objects > Arduino MEGA2560 with Ethernet Shield and MQTT
arduino
Comments
Post a Comment