element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum MQTT client program not showing any results with Arduino
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 49 replies
  • Subscribers 395 subscribers
  • Views 4137 views
  • Users 0 members are here
Related

MQTT client program not showing any results with Arduino

Former Member
Former Member over 10 years ago

I modified the MQTT example present under MQTT library pubsubclient for Arduino.

My MQTT server address is 192.168.1.6 with port 8081.

To this MQTT server,another MQTT client in my mobile is able to connect.

But this is not working with Arduino.There is no error shown during compilation or during uploading.

Infact,I am not able to see the connection result messages such as "Connected" or "Not connected" which i given in Serial.println() in setup function.

I am resetting Arduino before uploading the program.Please let me know why this is not showing any output....

 

#include <SPI.h>

#include <Ethernet.h>

#include <PubSubClient.h>

// Update these with values suitable for your network.

byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };

byte server[] = {192, 168, 1, 6 };

//byte ip[]     = { 172, 16, 0, 100 };

 

 

void callback(char* topic, byte* payload, unsigned int length) {

  // handle message arrived

}

EthernetClient ethClient;

PubSubClient client(server, 8081, callback, ethClient);

void setup()

{

  Ethernet.begin(mac);

  if (client.connect("*")) {

     Serial.begin(9600);

    Serial.println("Connected to MQTT Server");

    client.publish("outTopic","hello world");

   // client.subscribe("inTopic");

  }

  else

  {

   Serial.println("Could not connect to MQTT Server");

  }

}

void loop()

{

  //client.loop();

 

}

  • Sign in to reply
  • Cancel

Top Replies

  • neilk
    neilk over 10 years ago in reply to Former Member +3
    generk4 and organtin Hi Radhamani and Giovanni - I had 30 minutes to spare so I copied the program from comment 19 and posted it into the Arduino IDE (I am using 1.6.1), compiled and uploaded it to a genuine…
  • Former Member
    Former Member over 10 years ago +3
    Hi Bob, Neil and Clem, I tried LM35 Temperature sensor with MQTT Arduino sketch and it works fine for me I am sooo happy Thanks once again for your wonderful support and help
  • Former Member
    Former Member over 10 years ago in reply to bobcroft +2
    Hi bob,Neil,Clem and many others who have helped and guided me in this issue, I have successfully completed MQTT program and Arduino is successfully publishing and subscribing messages Next step,I am going…
  • bobcroft
    bobcroft over 10 years ago in reply to Former Member

    Radhamani,  glad to hear you are getting a  new shield.  I have been away for a few days and unable to post.  When you get your new shield please try the example sketch i Arduino 1.6.1, Ethernet folder, sketch is called DhcpAddressPrinter.  Plug your shield onto your Arduino UNO and power via the USB cable.  Upload the sketch and run it.  Open the Arduino terminal window and make sure it is set to 9600 baud.  Unless you have a genuine Arduino Ethernet shield then it will NOT have a sticker giving the shields MAC address so the default MAC address in the sketch should work.  You can also choose your own MAC address as long as it follows the same format as the example.

     

    If you get a print out of the automatically assigned IP address for the shield, SUCCESS! you can then progress to getting your MQTT code working.  Please do try the example sketches because these are known to work.  Once you have the DHCP sketch working you can try pinging that IP address and you can then try setting the IP address manually, again follow some of the example code given.  Remember that IP addresses of the form 192.168.1.xx or similar are on your local net work and not accessible to the WAN without port forwarding unless you have a static IP.

     

    If you cannot get an IP address for the shield either manually or automatically and everything is powered up correctly and the Ethernet cable is good then you could have a problem with your router or the UNO.  Do you have a friend where you could take your set up and try it on their system or at university / college?

     

    I'll keep my fingers crossed that your new shield works and you are able to make progress.

     

    Bob

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to bobcroft

    Thank you so much bob for your support on this..I am feeling very happy and confident when I am getting so much help and guidance from you all in this forum.:)

    I am trying the example now with new UNO and Ethernet shield.Will let you know the progress

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to Former Member

    Hurrah!!! It seems to be working...

    imageimage

    After replacing the components,

    Starting ethernet...192.168.1.67 is showing in Serial monitor

    And,

    C:\Users\Radhamani>ping 192.168.1.67

     

     

    Pinging 192.168.1.67 with 32 bytes of data:

    Reply from 192.168.1.67: bytes=32 time<1ms TTL=128

    Reply from 192.168.1.67: bytes=32 time=1ms TTL=128

    Reply from 192.168.1.67: bytes=32 time=45ms TTL=128

     

     

    Ping statistics for 192.168.1.67:

        Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),

    Approximate round trip times in milli-seconds:

        Minimum = 0ms, Maximum = 45ms, Average = 15ms

     

    Hope next I can start with MQTT program.. image

     

    (Anyhow,telnet 192.168.1.67 80 showing connection failed!)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • neilk
    neilk over 10 years ago in reply to Former Member

    generk4  Hooray!!!!!!!!!!!!!!!!!!!!!!!!!!! image

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • bobcroft
    bobcroft over 10 years ago in reply to Former Member

    Fantastic news!!!  I suggest you save a copy of each stage that works as you develop your code.  That we you only have to go back one step when you hit a snag.  I couldn't get TELNET working either!  You shouldn't have any problems with MQTT  now you have a working Ethernet card and IP address.

     

    Bob

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to bobcroft

    Hi bob,Neil,Clem and many others who have helped and guided me in this issue,

    I have successfully completed MQTT program and Arduino  is successfully publishing and subscribing messages image

    Next step,I am going to use Dallas Temperature sensor (DS18B20) as one of MQTT clients... image Lets see how it goes image

     

    Thanks a lot for all your support image .Without your guidance,this would not have been possible for me ...

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago

    Hi Bob,Neil and Clem,

       I tried LM35 Temperature sensor with MQTT Arduino sketch and it works fine for me image

    I am sooo happy image Thanks once again for your wonderful support and help image

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Cancel
  • organtin
    organtin over 10 years ago in reply to Former Member

    Sorry for the late reply, but I was very busy during the past days.

     

    I'm glad to hear that you succeeded in making the Ethernet shield working. It seems you had a faulty shield, in fact.

     

    Good luck for your project!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • neilk
    neilk over 10 years ago in reply to Former Member

    generk4  Hi Radhaman That really is excellent news. I hope you can complete your project now. Please let us know. image

     

    Neil

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to neilk

    Hi all...

    I have completed my project successfully image Thanks again for your wonderful support imageThis forum is rocking !!!!

     

    Lessons learnt :-

      1) We have to press the Ethernet shield very tightly with Arduino board

      2) If basic DHCP program does not work even after tight connection of Ethernet shield and Arduino board,we need to check with the vendor whether its fault on the component.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
<>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube