Hi everyone,
I'm trying to get running a small Mosquitto server for a college work, however I can't seem to get the Arduino to connect to the Mosquitto Server on a local network. If someone could check the code to see if there is something that could be wrong it would be appreciated.
Setup is currently:
PC <-> Router <-> Arduino
On the PC I have an inbound rule for TCP Port 1883 and UDP Port 17500.
When I run "mosquitto -v" I keep getting the message: "New connection from 192.168.125 on port 1883" endlessly as if it has never connected.
//Libraries needed
#include "DHT.h"
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
//Defines for DHT.h
#define DHTPIN A0
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
//Needed for Ethernet
byte MAC_ADDRESS[] = { 0x90, 0xA2, 0xDA, 0x0E, 0x94, 0x93 };
byte MQTT_SERVER[] = { 192, 168, 0, 25 };
byte IP_ADDRESS[] = {192, 168, 0, 125};
//Needed for DHT
char* tempC;
unsigned long time;
char message_buffer[100];
//MQTT
EthernetClient ethClient;
PubSubClient client(MQTT_SERVER, 1883, 0, ethClient);
void setup()
{
Ethernet.begin(MAC_ADDRESS,IP_ADDRESS);
delay(1000);
dht.begin();
}
void loop()
{
//Retry until connected is true
while (!client.connected())
{
client.connect("arduinoClient");
delay(5000);
}
// Publish sensor reading every X milliseconds
delay(5000);
float tempF = dht.readTemperature();
tempC = dtostrf(tempF,5,2,message_buffer);
client.publish("arduino/temperature",tempC);
// MQTT client loop processing
client.loop();
}
Thanks for any tips.