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
• 7,480 points
91 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,190 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,260 points
194 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,040 points
138 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 24, 2018 in IoT (Internet of Things) by nirvana
• 3,040 points
61 views
0 votes
1 answer

Choosing Domain Name for IoT Device

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

answered Sep 26, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
60 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,190 points
28 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,190 points
255 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.