This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

IoT aplication

Other Parts Discussed in Thread: EK-TM4C1294XL, ENERGIA

Hi everyone I'm working on a project based on the ek-tm4c1294xl board. I want to try others web services apart from exosite, so I'm trying to modify the qs_iot.c example bring by TI to achieve that. But in fact I'm kind of new in IoT issues, so the code is turning difficult to adapt. I wanted to know in first place if there is a generic library to use with any web service. Are there training documents with more examples of how to manage the eth_client libraries?

I've tried energia too, I could send the data but now I want to use this code in the way that is used in the qs_iot.c example, I mean, I don't wanna work with sketchs and anything like this. 

Thanks in advanced, 

Martin!

  • Hello Martin,

    Which is the IoT service provider that you are planning to use?

    Regards
    Amit
  • Hi Amit. thanks for answering!. Look this is the the HHTP post that allow me to update my data:

    http://api.thingspeak.com/update?key=GHCHLSFU3WXEJT7S&field1=500

    If I paste this in a web browser this code does what I want, so I need to do this but from my board.

    I've done this with some energia libraries in the same board.

    I've been trying to use this piece of text in the while(1) loop:

    char *p = prueba;

    EthClientSend((int8_t *)prueba, 50);

    p=prueba1;

    EthClientSend((int8_t *)prueba1, 50);

    p=prueba2;

    EthClientSend((int8_t *)prueba2, 50);

    p=prueba3;

    EthClientSend((int8_t *)prueba3, 50);

    p=prueba4;

    EthClientSend((int8_t *)prueba4, 50);

    p=prueba5;

    EthClientSend((int8_t *)prueba5, 50);

    p=prueba6;

    EthClientSend((int8_t *)prueba6, 50);

    p=prueba7;

    EthClientSend((int8_t *)prueba7, 50);

    of course I've defined previously:

    char prueba[]="POST /update HTTP/1.1\n";

    char prueba1[]="Host: api.thingspeak.com\n";

    char prueba2[]="Connection: close\n";

    char prueba3[]="X-THINGSPEAKAPIKEY: GHCHLSFU3WXEJT7S\n";

    char prueba4[]="Content-Type: application/x-www-form-urlencoded\n";

    char prueba5[]="Content-Length: ";

    char prueba6[]="\n\n";

    char prueba7[]="field1=100";

    My question would be how to manage adequately the eth_client_lwip library to send some data by a HTTP post.


    Thanks again Amit!

  • Hello Martin,

    Well I am not so familiar with this IoT site. How is the data from an embedded device expected by the site: HTTP POST and GET? You would need to rewrite the middle-ware which communicates with the IoT server. In this case eth_client_lwip, eth_exosite, etc

    Also a part of the middleware works with authentication, did you check that out, as to how the server authenticates the client.

    Regards
    Amit
  • Yes I made it works with the same board but using the energia ide with this piece of code:

    client.print("POST /update HTTP/1.1\n");

    client.print("Host: api.thingspeak.com\n");

    client.print("Connection: close\n");

    client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");

    client.print("Content-Type: application/x-www-form-urlencoded\n");

    client.print("Content-Length: ");

     client.print(tsData.length());

     client.print("\n\n");

     client.print(tsData);

    suposing that the writeAPIKey="GHCHLSFU3WXEJT7"; and tsdata="field1=100"

    I mean I made it work before wit Energia, but in fact is I can't make it work now with a CCS Project. Is there any document of aplication which explains how to use these libraries? If the exosite is updating at the same time in the same project, are the two connections to the server ready? 

    Thanks at all! Amit!

  • Hello Martin,

    There is no documentation from TI on the same. To reverse-engineer you would need to see the code in TivaWare and check the exosite documentation.

    Regards
    Amit
  • Ok, thanks, I'll work in this code, and then If I make it works paste the code here.

    Regards, Martin!
  • Hello Martin

    I am still not able to access the IoT server site... Is there a direct URL

    Regards
    Amit
  • Hi Amit, the server is ThingSpeak, you can google it.
    What I showed you before, the HTTP post:

    is an example of how to send the the data by a HTTP POST.
    Anyway what I'm punctually asking here is if there is a piece of code in any technical document of how to send data from the board to a web server using the library eth_client_lwip, because it is turning difficult to me get it from de qs_iot.c example.

    Thanks, Martin 

  • Hello Martin

    AFAIK, the eth_client_lwip performs tasks for exosite web server. I would also need to look into it.
  • Ok Amit thanks for all, but after a Quick look to the eth_client_lwip.c code I think it should be possible to connect any web server.

    But is Just an opinion. I Would precciatte a lot if you can check that. Thanks at all.

    Regards, Martin.

  • Hello Martin,

    Yes, technically it can.
  • Hi Amit, is there any novelty about the use of the eth_client_lwip.c library?

    Thanks in advanced.

    Martin 

  • Hello Martin

    Besides a single point for Proxy setting, Tx and Rx function call for the application layer drivers from exosite+HAL integration, I would say NO.
  • Hi Amit, I've been working with my partner in the project why didn't make any progress. I wanted to know if the functions:

    EthClientInit(uint32_t ui32SysClock, tEventFunction pfnEvent);
    EthClientSend(int8_t *pi8Request, uint32_t ui32Size);

    are enough to make the HTTP POST. I just need this info and perhaps a very brief diagram of how to use the library because there is not explain.

    There are not so many c functions in this library:

    void EthClientInit(uint32_t ui32SysClock, tEventFunction pfnEvent);
    void EthClientTick(uint32_t ui32TickMS);
    uint32_t EthClientAddrGet(void);
    void EthClientMACAddrGet(uint8_t *pui8Addr);
    int32_t EthClientTCPConnect(void);
    void EthClientTCPDisconnect(void);
    void EthClientProxySet(const char *pcProxyName, uint16_t ui16Port);
    void EthClientHostSet(const char *pcHostName, uint16_t ui16Port);
    int32_t EthClientDNSResolve(void);
    uint32_t EthClientServerAddrGet(void);
    int32_t EthClientSend(int8_t *pi8Request, uint32_t ui32Size);

    I need to make some progress here, I really want to make my project based in TI components, but if can't figure this out, I am forced to look in another tech solution.

    Thanks in advanced,

    Eng. Martin Castro.
  • Hello Martin,

    The following APIs have to be called to initialize and configure the Ethernet peripheral, lwIP stack and a TCP client socket.

    1. EthClientInit initializes the Ethernet peripheral and lwIP stack.
    2. EthClientHostSet sets up the global variables with socket configuration parameters, that is host name and port number.
    3. EthClientProxySet sets up the global variables with proxy server and port number. This API should be used only if proxy settings are required.
    4. EthClientDNSResolve resolves the IP address of the host name passed using EthClientHostSet (or EthClientProxySet).
    5. EthClientTCPConnect opens a TCP socket in client mode and configures it. The socket configuration parameters (that is host name and port number) should be passed before calling this API.

    Next step is to ensure that the API EthClientTick is called continuously by the application. A Sys Tick Interrupt is a good way to call this API continuously. Please refer enet_* examples of TivaWare to see how to use Sys Tick Interrupt.

    The EthClientTCPDisconnect API has to be called to close the socket, say on an error condition.

    The eth_client_lwip will inform the application about the state of the connection by passing the following flags  to the call-back function that was registered using the API EthClientInit.

    • ETH_CLIENT_EVENT_CONNECT that indicates that a connection with the server is established.
    • ETH_CLIENT_EVENT_DISCONNECT that indicates loss of IP address.
    • ETH_CLIENT_EVENT_SEND that indicates that data has been transmitted. One of the parameter will indicate the length of the data transmitted.
    • ETH_CLIENT_EVENT_RECEIVE that indicates that data has been received. The remaining parameters will have the actual payload and its length.
    • ETH_CLIENT_EVENT_ERROR that indicates that an error has been detected by lwIP TCP/IP stack and that the connection is no longer valid.
    • ETH_CLIENT_EVENT_DHCP that indicates that IP address has been acquired. One of the parameters contains the IP address.
    • ETH_CLIENT_EVENT_DNS that indicates that the DNS timer of lwIP has a failure or that a DNS address has been resolved. 

    The API EthClientSend should be called to transmit data.

    Hope this brief write-up gives some idea about how the eth_client_lwip driver works.

    Thanks,

    Sai

  • Amit, Sai, and Martin.

    Thank you for the excellent and clarifying previous answers, your answers have been helping me. I am trying to re-write this http post from energia. I have been am studying the enet_weather.c, enet_io, enetlwp, mongoose.h, and etc. It is so hard to figure out this.

    Please, could you help me to understand how to re-write this code the using ccs c lwip library and ethernet port in the tm4c129?



    void updateThingSpeak(String tsData)
    {
    Serial.println("Updating ThingSpeak");
    if (client.connect(thingSpeakAddress, 80))
    {
    Serial.println("Connected to ThingSpeak!");
    Serial.println();

    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(tsData.length());
    client.print("\n\n");
    client.print(tsData);

    failedCounter = 0;
    } else {
    failedCounter++;
    client.stop();

    Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");
    Serial.println();
    }

    lastConnectionTime = millis();
    }


    Best Regards!