Announcement

Collapse
No announcement yet.

gen4-IoD-32T WiFi Display Module - Connection to AWS IoT using MQTT

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • gen4-IoD-32T WiFi Display Module - Connection to AWS IoT using MQTT

    I am attempting to connect my gen4-IoD-32T WiFi Display Module to the Amazon AWS server through MQTT protocol, without any luck.

    My code works fine using the Adafruit ESP8266 Huzzah board, but when I run it on the gen4-IoD-32T WiFi Display Module, it is having problems making the MQTT connection with the AWS certificates. Does the gen4-IoD-32T WiFi Display Module have limited memory or some other limitation that will not allow the certificates to complete the MQTT connection?

    Has anyone connected the gen4-IoD-32T WiFi Display Module to Amazon AWS successfully? Can you share how?

    I am noob to all of this and just hacking around trying to make something work.

    Thanks


  • #2
    Hello and welcome to the forum.

    The IoD should have more than enough resources to to connect with MQTT protocol. You could try the examples in the GFX4d library, WifiscanIoD to check Wifi signal & GFXDemo4d to check Wifi connection just in case the issue is related to wifi connection rather than anything to do with MQTT. If possible, could you please send me the code you are using for me to examine and test here.

    Best regards

    Paul

    Comment


    • #3
      Paul,

      Thanks for the reply. I have successfully ran the examples in the GFX4d library - the WIFI network connection works well. The problem is connecting to AWS using certificates with MQTT protocol.

      Here is the serial monitor output when I run the code on the Adafruit ESP8266 Huzzah Board - Note the reply from Lamba is the function on the Amazon AWS to send a message anytime someting is received on MQTT thread.

      Serial Monitor from Adafruit.PNG

      And here is the serial monitor output when I run the same code on the gen4-IoD-32T - Note the MQTT fails connection and will just sit forever.

      Serial Monitor from gen4-IoD-32T.PNG



      Here is the code I am running. It is based off of the youtube from Debashish Sahu at https://www.youtube.com/watch?v=OzNlSk7VU68

      The secrets.h file holds the SSID and SSID PSWD that will need to be set. Also the settings for the AWS certificates and access to "MyThing1" should work as is. I did not change the from Adafruit to the IoD device. ( Yes I realize that I am sending these certifications out for anyone to hack - but this is just a test account on AWS, so help yourself )

      WorksOnAdafruit.ino

      secrets.h.ino (remove the .ino for the secrets.h file - for some reason I could not upload a .h file to this post)
      Last edited by gaspertom; 15th March 2019, 12:59 AM.

      Comment


      • #4
        Hi,

        Thanks for uploading the code that you are using,

        It is quite possible that the IoD may just need to have a yield() command in its setup routine as it has done a bit more work than the Huzzah before trying to connect with MQTT by using a few gfx.print commands. There should also be a yield() within the main loop.

        Code:
        void setup()
        {
          gfx.begin();
          gfx.Cls();
          gfx.ScrollEnable(true);
          gfx.BacklightOn(true);
          gfx.Orientation(LANDSCAPE);
          gfx.SmoothScrollSpeed(5);
          gfx.TextColor(YELLOW); gfx.Font(2);  gfx.TextSize(1);
        
          Serial.begin(115200);
          delay(5000);
          Serial.println();
          gfx.println();
        
        #ifdef ESP32
          WiFi.setHostname(THINGNAME);
          Serial.println("Using ESP32");
          gfx.println("Using ESP32");
        #else
          WiFi.hostname(THINGNAME);
          Serial.println("Using ESP8266" );
          gfx.println("Using ESP8266" );
        #endif
          WiFi.mode(WIFI_STA);
          WiFi.begin(ssid, pass);
          connectToWiFi(String("Connecting to SSID: ") + String(ssid));
          yield();
          NTPConnect();
        
        #ifdef ESP32
          net.setCACert(cacert);
          net.setCertificate(client_cert);
          net.setPrivateKey(privkey);
        #else
          net.setTrustAnchors(&cert);
          net.setClientRSACert(&client_crt, &key);
        #endif
         
          client.begin(MQTT_HOST, MQTT_PORT, net);
          client.onMessage(messageReceived);
          yield();
          connectToMqtt();
        }
        As it seems to be in a hanging state, it is likely to be the cause. Could you please try modifying your code to see if it solves the issue.

        Best regards

        Paul

        Comment


        • #5
          Thanks for the suggestion Paul,

          Unfortunately not seeing any effect - still not connecting to MQTT successfully. Are you able to run my code on your systems and confirm it operation?

          I also included yield() in the connection routine as well as your suggestion in startup() - did not help.

          It appears to be "locking up" during the call to client.connect(THINGNAME) where client is MQTTClient client;. As I mentioned I am somewhat of a noob on this and not sure if the Arduino library #include <MQTT.h> is the correct one or how to debug it - but again all works fine on the Huzzah

          Is there example code for MQTT communication on the IoD?


          Code:
          void connectToMqtt(bool nonBlocking = false)
          {
          
            while (!client.connected())
            {
              yield();
              Serial.print("MQTT connecting ");
              gfx.print("MQTT connecting ");
          
              if (client.connect(THINGNAME))
              {
                Serial.println("connected!");
                gfx.println("connected!");
                if (!client.subscribe(MQTT_SUB_TOPIC))
                  lwMQTTErr(client.lastError());
              }
              else
              {
                Serial.println("");
                gfx.println("");
                Serial.print("failed, reason -> ");
                gfx.print("failed, reason -> ");
                lwMQTTErrConnection(client.returnCode());
                if (!nonBlocking)
                {
                  Serial.println(" < try again in 1 seconds");
                  gfx.println(" < again in 1 seconds");
                  for (int i = 0; i < 10; i++)
                  {
                    Serial.print(".");
                    gfx.print(".");
                    delay(100);
                    yield();
                  }
                  Serial.println(".");
                  gfx.println(".");
                  yield();
                }
                else
                {
                  Serial.println(" <");
                  gfx.print(" <");
                }
              }
              if (nonBlocking)
                break;
            }
          }
          Last edited by gaspertom; 14th March 2019, 01:17 AM.

          Comment


          • #6
            Hi,

            I am testing the above example now, and will work through it to see if I can find a solution.

            Best regards

            Paul

            Comment


            • #7
              Hi,

              I have tested the above code and I am not able to connect to MQTT but I am not in the stalled state as you have experienced. It will continue to retry. It seems that it may be connected on your setup but for some reason, it can't carry on to the next step. I will endeavour to try to get MQTT to connect and see if I can troubleshoot the issue when connected.

              Best regards

              Paul

              Comment


              • #8
                Thanks for the verification - are you able to test it on a ESP8266 Huzzah board (or equivalent)?

                Comment


                • #9
                  Hi,

                  After a modification, just to get the NTP server to move on, It connected and gave a response. The mod to NTP isn't relevant to the issue, it was only added to prevent it staying in the NTP routine. It also does it reliably when I power down and power back up again so I am a bit of a loss as to what the issue might be. In your setup NTP successfully completes in any case so it isn't an issue with NTP orwith yield() as I haven't added any to this code. I will keep looking for a solution or a difference that is causing your setup to fail.

                  Best regards

                  Paul

                  Attached Files

                  Comment


                  • #10
                    Thanks again. Correct - I have not had an issue with the WiFi or NTP connecting.

                    Comment


                    • #11
                      Hi,

                      Just as a test so we can both be on the same page, could you try using the GFX4d Beta library which I have attached below and set your CPU frequency to 160Mhz and then try again to see if it makes a difference.

                      Best regards

                      Paul
                      Attached Files

                      Comment


                      • #12
                        Not sure what I was to expect - but no change to result, still not MQTT connection

                        FYI - sill works fine on Huzzah with the clock speed change and beta library



                        I found this note in https://github.com/debsahu/ESP-MQTT-AWS-IoT-Core readme.

                        Click image for larger version

Name:	Note.PNG
Views:	8
Size:	13.9 KB
ID:	67479


                        What is the Arduino Core n the gen4-IoD-32T WiFi display module? Could it be updated as noted?
                        Last edited by gaspertom; 14th March 2019, 02:23 PM.

                        Comment


                        • #13
                          Hi,

                          You can check this by opening Boards Manager and scrolling down to the ESP9266 and when you click on it, a Select Version box will appear. You can choose 2.5.0 here and it will update the core.

                          Best regards

                          Paul

                          Comment


                          • #14
                            Ok, I confirmed I am running the latest 2.50 version.

                            The good news is that this morning I started the device and it worked - it received the reply from AWS Lambda. Yeeha!

                            However when I recompiled and uploaded the same code (basically - resenting the device) - it will not work again - still not connecting with MQTT reliably compared to the Huzzah.

                            Should I continue to use the GFX4dBeta?
                            Last edited by gaspertom; 15th March 2019, 01:52 AM.

                            Comment


                            • #15
                              Hi,

                              That is very encouraging news but a bit frustrating that it also failed again. I will continue to investigate it as it failed once last night for me also when testing.

                              Yes carry on with the GFX4dBeta. It will be released in the near future with new documentation for all the new features. The Beta version is faster in all aspects so very worthwhile to keep using it.

                              I will update you if I find anything

                              Best regards

                              Paul

                              Comment

                              Working...
                              X