Hi
This is the full code so far
/*
Publishing in the callback
- connects to an MQTT server
- subscribes to the topic "inTopic"
- when a message is received, republishes it to "outTopic"
This example shows how to publish messages within the
callback function. The callback function header needs to
be declared before the PubSubClient constructor and the
actual callback defined afterwards.
This ensures the client reference in the callback function
is valid.
*/
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
// Update these with values suitable for your network.
byte server[] = {192,168,0,2}; // If its a numerical address use this and comment out above line
byte ip[] = {192,168,0,3}; // Update this with value suitable for this network.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
String store;
// Callback function header
void callback(char* topic, byte* payload, unsigned int length);
EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);
// ___________________________________________________________________________________________________________
// Callback function
void callback(char* topic, byte* payload, unsigned int length)
{
client.publish("outTopic", payload, length);
Serial.begin(9600);
Serial.println("Arduino got payload ...");
for (int i = 0; i < length; i++)
{
Serial.println(payload[i]);
}
if(strcmp((char *)payload, "t") == 0)
{
Serial.println("Arduino got match ...");
}
}
// ____________________________________________________________________________________________
void setup()
{
Ethernet.begin(mac, ip);
if (client.connect("arduinoClient")) {
client.publish("outTopic","hello world");
client.subscribe("inTopic");
}
}
// ____________________________________________________________________________________________
void loop()
{
client.loop();
}
Regards Gary