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.

char array does not get updated at a specific CCS Program



Hi,

Here is my C function below. At a simpler CCS program for testing small code, the char led2[10] gets the value that I expect it to have from calling exosite_readSingle(). However, I copied and paste this to the program I am working on and char led2[10] does not get updated. What could be causing this? I have already set optimization to "off". Is this caused by something set at CCS?

void cloud_demo( void )
{
	int32_t Read_status = 0;
	int32_t	cloud_data1 = 0;
	uint16_t response_length1 = 0;
	char led2[10];

	//use exosite_read to read multiple aliases values
	Read_status = exosite_readSingle("ledd2", led2, 10, &response_length1);
	if (Read_status == 0)
	{
		cloud_data1 = exoPal_atoi(led2);
      //UARTprintf(" Exosite Read:  %s=%d\r\n", LED2_ALIAS, cloud_data1);
	}
}

  • Markel Robregado said:
    However, I copied and paste this to the program I am working on and char led2[10] does not get updated.

    Can you clarify if when led2 doesn't get updated, does exosite_readSingle return zero and does cloud_data1 get set to the expected value?

    i.e. does the program execute correctly, but CCS fails to display the expected value for the led2 array?

  • Hi Chester,

        Thanks for your reply. See, exosite_readSingle() function below.At the much simpler program I debug step it the led2[10] was initialized with garbage values. After calling exosite_readSingle(), the led2[10] got populated with the correct value, which is the the first element of array to be "1".

         At the program I am working on, the led2[10] was initialized with garbage values. After calling exosite_readSingle(), led2[10] has the same garbage values. I don't understand why this is happening. 

    exosite_readSingle() returns 0 for both program.

    /*!
     *  \brief  Reads data from Exosite
     *
     * Reads a single alias from the Exosite One Platform.  The alias
     * variable can only include one alias name.
     *
     * For example, if you want to read from the `myAlias` alias, you would set the
     * alias parameter to `"myAliasName"`.
     *
     * If the read is successful, the value returned in readResponse will be the
     * value of your alias.  These will always be strings.  Even if your data source
     * contains a numeric value, you must convert it to an integer before using it.
     *
       \code{.c}
       exosite_readSingle("myAlias", readBuffer, lenOfReadBuffer, retLen);
       // After this call, the readBuffer would look something like this: "3". The
       // length variable would be updated with the length of the response string, in this
       // case, 1.
       \endcode
     *
     * \param[in] alias Name/s of data source/s alias to read from
     * \param[out] readResponse buffer to place read response in
     * \param[in] buflen length of buffer
     * \param[out] length data placed into readResponse
     *
     * \return Error code if fail, else 0
     *
     */
    int32_t exosite_readSingle(const char * alias, char * readResponse, uint16_t buflen, uint16_t * length)
    {
        uint16_t responseLength;
        int16_t i;
        uint16_t j;
        uint16_t k;
        uint8_t connection_status;
        int32_t results = 0;
    
        if(!exosite_isCIKValid(cikBuffer))
        {
            // tried to write without a valid CIK
            return -99;
        }
        
        // connect to exosite
        connection_status = exosite_connect();
    
        // return error message if connect failed.
        if (connection_status != 0)
        {
            return connection_status;
        }
    
        // send request
        results |= exoPal_socketWrite(STR_READ_URL, sizeof(STR_READ_URL)-1);
        results |= exoPal_socketWrite(alias, exoPal_strlen(alias));
        results |= exoPal_socketWrite(" ", exoPal_strlen(" "));
        results |= exoPal_socketWrite(STR_HTTP, sizeof(STR_HTTP)-1);
        results |= exoPal_socketWrite(STR_CRLF, sizeof(STR_CRLF)-1);
    
        // send Host header
        results |= exoPal_socketWrite(STR_HOST, sizeof(STR_HOST)-1);
        results |= exoPal_socketWrite(STR_CRLF, sizeof(STR_CRLF)-1);
    
        // send cik header
        results |= exoPal_socketWrite(STR_CIK_HEADER, sizeof(STR_CIK_HEADER)-1);
        results |= exoPal_socketWrite(cikBuffer, sizeof(cikBuffer));
        results |= exoPal_socketWrite(STR_CRLF, sizeof(STR_CRLF)-1);
    
        // send content type header
        results |= exoPal_socketWrite(STR_CONTENT, sizeof(STR_CONTENT)-1);
        results |= exoPal_socketWrite(STR_CRLF, sizeof(STR_CRLF)-1);
    
        // send accept header
        results |= exoPal_socketWrite(STR_ACCEPT, sizeof(STR_ACCEPT)-1);
        results |= exoPal_socketWrite(STR_CRLF, sizeof(STR_CRLF)-1);
        results |= exoPal_socketWrite(STR_CRLF, sizeof(STR_CRLF)-1);
    
        results |= exoPal_sendingComplete();
        
        if (results != 0)
        {
            exosite_disconnect();
            return results;
        }
        
        responseLength = 0;
        // get response
        exoPal_socketRead(exoPal_rxBuffer, RX_BUFFER_SIZE, &responseLength);
    
        exosite_disconnect();
        
        // if we received a 200
        if (exosite_checkResponse(exoPal_rxBuffer, "200"))
        {
            status_code = EXO_STATUS_OK;
    		//find first '\n' char from end of response
            for (i = responseLength; i > 0; i--)
            {
                if (exoPal_rxBuffer[i] == '\n')
                {
                    // '\n' found
                    uint8_t charNotMatch = 0;
                    for ( j = 1; (j <= i) && i > 0; j++)
                    {
                        // If we're at the end of the inputted string?
                        if (alias[j-1] == '\0')
                        {
                            // if all chars of our requested alias match, we found the key
                            if (!charNotMatch)
                            {
                                // move j passed the '='
                                j++;
    
                                for (k = 0;
                                     (k <= buflen) && ((i + j + k) <= responseLength);
                                     k++)
                                {
                                    // copy remaining data into buffer
                                    readResponse[k] = exoPal_rxBuffer[i+j+k];
                                    *length = k;
                                }
                                i = 0;
                            }
                            else
                            {
                                // match not found, exit
                                i = 0;
                                *length = 0;
                            }
                        }
    
                        // confirm letter by letter
                        charNotMatch |= !(exoPal_rxBuffer[i+j] == alias[j-1]);
                    }
                }
            }
        }
    
        return 0;
    }

  • Markel Robregado said:
    At the program I am working on, the led2[10] was initialized with garbage values. After calling exosite_readSingle(), led2[10] has the same garbage values. I don't understand why this is happening. 

    exosite_readSingle() returns 0 for both program.

    Looking at the source code of the exosite_readSingle() function, if it doesn't receive the expected response it won't write to the readResponse 2nd parameter (led2 array in your example) but still return zero.

    In the failure case, can you step into the exosite_readSingle() function and see if it gets into the code block which writes to the readResponse argument?

  • Hi Chester,

    For the program I am working on the led2[10] array does not get populated after calling exosite_readSingle(). The return of ledd2 alias from exosite is either "1" or "0" only. However, led2[10] gets populated with the correct values if I call exosite_readSingle() with other alias that does not return only "1" or "0" . For example if I use alias "windspeed" at exosite_readSingle() , led2[10] gets populated with the correct values example "55".

    But, for simple program for testing API's purposes exosite_readSingle() returns the correct value if I use the alias ledd2. It will return "1" or "0".

    I give up with this and just use another API exosite_read. exosite_read will return "ledd2=1" or "ledd2=0". I will just atoi the last value for use.

    Thanks for your time Chester.

    - kel