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

  • gaspertom
    replied
    Paul,

    As another question - you will notice that I print to the screen using gfx.println() function - when the print hits the bottom of the screen any additional print calls do not appear on the screen, is there an easy way to have it scroll and continue printing?

    Tom
    Last edited by gaspertom; 15 March 2019, 02:13 AM.

    Leave a comment:


  • gaspertom
    replied
    I cleaned up the error messages in the connectToMqTT() routine - it show that the client.connect() is returning a false although the returnCode and lastError are successful

    10:32:55.218 -> MQTT connecting
    10:33:05.234 -> failed, returnCode -> Connection Accepted, lastError -> Success < try again in 20 seconds


    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, returnCode -> ");
          gfx.print("failed, returnCode -> ");
          lwMQTTErrConnection(client.returnCode());
          Serial.print(", lastError -> ");
          gfx.print(", lastError -> ");
          lwMQTTErr(client.lastError());
          if (!nonBlocking)
          {
            Serial.println(" < try again in 20 seconds");
            gfx.println(" < try again in 20 seconds");
            client.disconnect();
            for (int i = 0; i < 20; i++)
            {
              Serial.print(".");
              gfx.print(".");
              delay(1000);
              yield();
            }
            Serial.println(".");
            gfx.println(".");
            yield();
          }
          else
          {
            Serial.println(" <");
            gfx.print(" <");
          }
        }
        if (nonBlocking)
          break;
      }
    }

    Leave a comment:


  • pauleilio
    replied
    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

    Leave a comment:


  • gaspertom
    replied
    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; 15 March 2019, 01:52 AM.

    Leave a comment:


  • pauleilio
    replied
    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

    Leave a comment:


  • gaspertom
    replied
    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:	246
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; 14 March 2019, 02:23 PM.

    Leave a comment:


  • pauleilio
    replied
    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

    Leave a comment:


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

    Leave a comment:


  • pauleilio
    replied
    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

    Leave a comment:


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

    Leave a comment:


  • pauleilio
    replied
    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

    Leave a comment:


  • pauleilio
    replied
    Hi,

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

    Best regards

    Paul

    Leave a comment:


  • gaspertom
    replied
    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; 14 March 2019, 01:17 AM.

    Leave a comment:


  • pauleilio
    replied
    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

    Leave a comment:


  • gaspertom
    replied
    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; 15 March 2019, 12:59 AM.

    Leave a comment:

Working...
X