Connection through ethernet shield is possible but not when using MQTT on my arduino

0 votes
I have been trying to send messages via MQTT from my Arduino to my amazon web server. The code below connects the ethernet client but not the MQTT client. Why would my MQTT client not be connecting?

#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>

byte mac[]    = { 0x12, 0x42, 0x98, 0x85, 0x49, 0x3A }; //MAC address of server
char server[] = "http://52.1.29.117/"; //web address of server
IPAddress ip(172, 31, 51, 13); //IP address of server

void callback(char* topic, byte* payload, unsigned int length) {
  // handle message arrived
}

EthernetClient ethClient;
PubSubClient client(server, 80, callback, ethClient);

void setup()
{
    Serial.begin(9600);
    while (!Serial) {
        ; // wait for serial port to connect. Needed for Leonardo only
    }

    // start the Ethernet connection:
    if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        Ethernet.begin(mac, ip);
    }
    delay(1000);
    Serial.println("connecting...");

    if (ethClient.connect(server, 80)) {
        Serial.println("connected");
        // Make a HTTP request:
        ethClient.println("GET /search?q=arduino HTTP/1.1");
        ethClient.println("Host: www.google.com");
        ethClient.println("Connection: close");
        ethClient.println();
    }
Aug 27, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,262 views

1 answer to this question.

0 votes
You can only open a couple of specific  ports with IIRC AWS , You can open up some more with this:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/authorizing-access-to-an-instance.html
answered Aug 27, 2018 by Annie97
• 2,160 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer
0 votes
1 answer

AWS IoT login from android MQTT client using IAM is not working

Seeing your comments and questions. I had ...READ MORE

answered Jul 24, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
2,139 views
0 votes
1 answer

Android M - Sending request over WiFi (without connection) when Mobile data is ON (with connection)

Binding the network using ConnectivityManager.setProcessDefaultNetwork() will help ...READ MORE

answered Oct 11, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,981 views
0 votes
1 answer

Sending more than 8 byte through UART on Raspberry Pi using Android Things!

So, you can send 234212441325454543595674859764 in ASCII, ...READ MORE

answered Aug 25, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,034 views
0 votes
1 answer

Choosing Domain Name for IoT Device

Yes, I would avoid revealing an 'internal' ...READ MORE

answered Sep 27, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
2,679 views
0 votes
1 answer
0 votes
1 answer

AWS IOT Button Wifi network name

You can read about the complete setup ...READ MORE

answered Oct 12, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
582 views
0 votes
1 answer

MQTT : Connection lost on MQTT subscriber to Internet of Things Server

An invalid topic "matteo" seems to be causing the ...READ MORE

answered Oct 3, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
4,277 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP