Skip to content

Commit

Permalink
add http_send_with_parameter method and fix str_start method
Browse files Browse the repository at this point in the history
  • Loading branch information
CristinaDesogus123 committed Apr 16, 2024
1 parent 5fb3dc0 commit d0188ab
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
ME310 0.0.0 - ????.??.??

ME310 2.13.1 - 2024.04.16
* Fixes in M2MWrite
* Added Http_send_without_parameter
* Fixes str_start

ME310 2.12.1 - 2023.11.23
* Fixes in LWM2M_first example

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ME310G1
version=2.12.1
version=2.13.1
author=Telit
maintainer=Telit <[email protected]>
sentence=Allows communication with ME310G1 Telit module.
Expand Down
56 changes: 48 additions & 8 deletions src/ME310.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
It makes it easy to build Arduino applications that use the full power of ME310 module
@version
2.11.0
2.13.1
@note
Expand All @@ -43,7 +43,7 @@ const char *ME310::OK_STRING = "OK"; ///< String for OK modem
const char *ME310::ERROR_STRING = "ERROR"; ///< String for ERROR modem answer
const char *ME310::CONNECT_STRING = "CONNECT"; ///< String for CONNECT modem answer
const char *ME310::CME_ERROR_STRING = "+CME ERROR: "; ///< String for +CME ERROR modem answer
const char *ME310::SEQUENCE_STRING = ">>> "; ///< Sequence string
const char *ME310::SEQUENCE_STRING = ">>>"; ///< Sequence string
const char *ME310::WAIT_DATA_STRING = "> "; ///< Wait Data string
const char *ME310::TERMINATION_STRING = ""; ///< Termination character
const char *ME310::NO_CARRIER_STRING = "NO CARRIER"; ///< String for NO CARRIER modem answer
Expand Down Expand Up @@ -5114,6 +5114,12 @@ ME310::return_t ME310::send_http_send(int prof_id, int command, const char *reso
{
ME310::return_t ret;
memset(mBuffer, 0, ME310_BUFFSIZE);
if( post_param == "")
{
ret = send_http_send_without_params(prof_id, command, resource, data_len, data, aTimeout);
return ret;
}

snprintf((char *)mBuffer, ME310_BUFFSIZE-1, F("AT#HTTPSND=%d,%d,\"%s\",%d,\"%s\",\"%s\""), prof_id, command, resource, data_len, post_param, extra_header_line);
ret = send_wait((char*)mBuffer,SEQUENCE_STRING,aTimeout);
if ((ret == RETURN_VALID))
Expand All @@ -5125,6 +5131,31 @@ ME310::return_t ME310::send_http_send(int prof_id, int command, const char *reso
return ret;
}

//! \brief Implements the AT\#HTTPSND command and waits for OK answer
/*! \details
This command performs a POST or PUT request to HTTP server and starts sending data to the server.
* \param prof_id profile identifier
* \param command command requested to HTTP server
* \param resource HTTP resource (uri), object of the request
* \param data_len data length to send in bytes
* \param aTimeout timeout in ms
* \return return code
*/
ME310::return_t ME310::send_http_send_without_params(int prof_id, int command, const char *resource, int data_len, char *data, tout_t aTimeout)
{
ME310::return_t ret;
memset(mBuffer, 0, ME310_BUFFSIZE);
snprintf((char *)mBuffer, ME310_BUFFSIZE-1, F("AT#HTTPSND=%d,%d,\"%s\",%d"), prof_id, command, resource, data_len);
ret = send_wait((char*)mBuffer,SEQUENCE_STRING,aTimeout);
if ((ret == RETURN_VALID))
{
memset(mBuffer, 0, ME310_BUFFSIZE);
memcpy(mBuffer, data, data_len);
ret = send_wait((char*)mBuffer,OK_STRING,TERMINATION_STRING,aTimeout);
}
return ret;
}

//! \brief Implements the AT\#HTTPRCV command and returns
/*! \details
This command permits the user to read data from HTTP server in response to a previous HTTP module
Expand Down Expand Up @@ -7612,7 +7643,6 @@ ME310::return_t ME310::send_wait(const char *aCommand, int flag, const char *aA
return wait_for(aCommand, flag, aAnswer, aTimeout);
}


//! \brief Waits for the answer to an AT command or timeouts
/*!
* \param aAnswer answer string to wait for
Expand Down Expand Up @@ -7648,6 +7678,11 @@ ME310::return_t ME310::wait_for(const char *aAnswer, ME310::tout_t aTimeout)
on_valid((const char *)pBuffer);
return RETURN_VALID;
}
if(str_start((const char *)pBuffer,aAnswer))
{
on_valid((const char *)pBuffer);
return RETURN_VALID;
}
if(str_equal((const char *)pBuffer,ERROR_STRING))
{
on_error((const char *)pBuffer);
Expand Down Expand Up @@ -7952,12 +7987,17 @@ const char *ME310::str_start(const char *buffer, const char *string)
return nullptr;
}
const char *rc = buffer;
for(; ;buffer++,string++)

String bufTMP, strTMP;
bufTMP = buffer;
strTMP = string;
if(bufTMP.startsWith(strTMP))
{
if(*buffer != *string)
return nullptr; // exit if different
else if(*buffer == 0)
return rc; // exit if equal but = 0
return rc;
}
else
{
return nullptr;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/ME310.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
It makes it easy to build Arduino applications that use the full power of ME310 module
@version
2.11.0
2.13.1
@note
Dependencies:
Expand Down Expand Up @@ -1032,7 +1032,8 @@ namespace me310
return_t send_http_query(int prof_id, int command, const char *resource, tout_t aTimeout = TOUT_100MS);
_TEST(send_http_query,"AT#HTTPQRY",TOUT_100MS)

return_t send_http_send(int prof_id, int command, const char *resource, int data_len, char *data, const char *post_param ="", const char *extra_header_line = "",tout_t aTimeout = TOUT_100MS);
return_t send_http_send(int prof_id, int command, const char *resource, int data_len, char *data, const char *post_param ="", const char *extra_header_line = "", tout_t aTimeout = TOUT_100MS);
return_t send_http_send_without_params(int prof_id, int command, const char *resource, int data_len, char *data, tout_t aTimeout = TOUT_100MS);
_TEST(send_http_send,"AT#HTTPSND",TOUT_100MS)

void receive_http_data_start(int prof_id, int max_byte = 0);
Expand Down

0 comments on commit d0188ab

Please sign in to comment.