I'm new to using the ethernet shield.
I'm able to connect to my mqtt server using the arduino insecurely (over port 1883).
I'm able to connect to my mqtt server using a raspberry pi securely (over port 8883).
However, I cannot connect to port 8883 with the arduino.
I've read every post out there and I can't tell if it's my sketch or it's just impossible. Can someone tell me definitively if it won't work or what the problem is with my code?
#include <SPI.h>
#include <Ethernet.h>
#include "PubSubClient.h"
//
//#define CLIENT_ID "BoilerRoom"
//#define USERNAME ""
//#define PASSWORD ""
//#define SERVER "192.168.0.222"
//#define PORT 1883
#define CLIENT_ID "BoilerRoom"
#define USERNAME "mudmin"
#define PASSWORD "password"
#define SERVER "mqttserver.domain.com"
#define PORT 8883
#define INTERVAL 3000 // 3 sec delay between publishing
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,223);
EthernetClient ethClient;
PubSubClient mqttClient;
long previousMillis;
void setup() {
// disable SD card if one in the slot
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
// setup serial communication
Serial.begin(9600);
// setup ethernet communication using DHCP
if(Ethernet.begin(mac) == 0) {
Serial.println(F("Ethernet configuration using DHCP failed"));
for(;;);
}
// setup mqtt client
mqttClient.setClient(ethClient);
mqttClient.setServer(SERVER,PORT);
Serial.println(F("MQTT client configured"));
previousMillis = millis();
}
void loop() {
// check interval
if(millis() - previousMillis > INTERVAL) {
sendData();
previousMillis = millis();
}
mqttClient.loop();
}
void sendData() {
char msgBuffer[20];
if(mqttClient.connect(CLIENT_ID, USERNAME, PASSWORD)) {
mqttClient.publish("hello", "world");
}
}