Giter VIP home page Giter VIP logo

Comments (1)

shanedoolane avatar shanedoolane commented on June 2, 2024

The problem was that http client instance was not being passed a valid reference to the gsmClient instance

What didn't work:

I think this is because gsmClient i was using not initialized with a modem properly.

// main.cpp
TinyGsm modem = cellFunctions.modem;
TinyGsmClient gsmClient = cellFunctions.gsmClient;
// cellFunctions.h
class CellFunctions
{
public:
        CellFunctions(HardwareSerial &serialGsmRef, HardwareSerial &SerialATRef, StreamDebugger &debugger);
.
.
.

        TinyGsm modem;           // instance of TinyGsm modem class
        TinyGsmClient gsmClient; // instance of the TinyGsm client class to use with mqtt
};
// getMQTTEndpoint.cpp
bool MQTTEndpoint::getMQTTEndpoint(Client &client)
{
    char final_url[256]; 
    sprintf(final_url, "http://%s/api/firmware/%s/", domain, apiKey);
    bool endpoint_found = false;
    while (!endpoint_found) 
    {
        HttpClient http(client, domain, 80);
        http.setTimeout(10000);
        int err = http.get(final_url);
        if (err != 0)
        {
            Logger.logMessage(LOG_LEVEL_ERROR, "HTTP GET not successful");
        }
        err = http.responseStatusCode();
        Logger.logMessage(LOG_LEVEL_DEBUG, "The HTTP Response code is: %d", err);
        if (err >= 300 || err < 200)
        {
            Logger.logMessage(LOG_LEVEL_ERROR, "Failed to get MQTT Endpoint due to bad HTTP response code");
            delay(30000);
            continue;
        }
        String payload = http.readString();

What did work

//main.cpp
TinyGsm modem = cellFunctions.modem;
TinyGsmClient gsmClient(modem);  // here i actually pass the modem to the gsmClient before using the client to call getMQTTEndpoint

from tinygsm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.