Skip to content

Commit

Permalink
Add generic Command example and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopi-tlt committed Nov 15, 2021
1 parent 98c6a48 commit 455fd27
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ME310 0.0.0 - ????.??.??

ME310 2.7.0 - 2021.11.15
* Added generic AT command utilities and example sketch

ME310 2.6.0 - 2021.10.14
* File utilities improvements
* sketches code improvements
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The following examples are available:
- **[Ping_example](examples/Ping_example/Ping_example.ino)** : _Simple example that enables the connectivity and pings a server_
- **[Socket_example](examples/Socket_example/Socket_example.ino)** : _Enables connectivity and uses a TCP socket example communicating with a demo server_
- **[TransparentBridge](examples/TransparentBridge/TransparentBridge.ino)** : _Enable the modem and creates a bridge between Arduino serial and modem AT interface, allowing user to send AT commands manually_
- **[GenericCommand_example](examples/GenericCommand_example/GenericCommand_example.ino)** : _Shows how to send AT commands to the modem manually and manage the response (useful for complex AT commands or chains of commands)_


## Support
Expand Down
84 changes: 84 additions & 0 deletions examples/GenericCommand_example/GenericCommand_example.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*Copyright (C) 2020 Telit Communications S.p.A. Italy - All Rights Reserved.*/
/* See LICENSE file in the project root for full license information. */

/**
@file
ME310.cpp
string.h
stdio.h
@brief
Sample test of the use of Generic Command method via ME310 library
@details
In this example sketch, the use of method offered by the ME310 library for using AT commands is shown.\n
Through this method, it is possible to send a generic AT command or a list of AT commands.\n
@version
1.0.0
@note
@author
Cristina Desogus
@date
08/11/2021
*/
#include <Arduino.h>
#include <ME310.h>

#ifndef ARDUINO_TELIT_SAMD_CHARLIE
#define ON_OFF 6 /*Select the GPIO to control ON_OFF*/
#endif

using namespace me310;

ME310 myME310;
ME310::return_t myRc;
void setup() {
int i = 0;
const char OKanswer[] = "OK";
Serial.begin(115200);
myME310.begin(115200);
delay(1000);
Serial.println("Generic AT Command test");
delay(1000);
myME310.powerOn();
Serial.println("ME310 is ON");

/*
ATCommand is the command string which contains the AT commands to send.
The single command must be separated from the ;.
The "AT" string must not be repeated.
For example: "AT#GPIO=1,1,1;#GPIO=2,1,1;#GPIO=3,1,1"
*/
const char ATCommand[] = "AT#SWPKGV;#CGMM";
Serial.println((String)"Send: " + ATCommand);
myRc = myME310.send_command(ATCommand, OKanswer); //issue a list of command indicated in the string and wait for anwser or timeout
Serial.println((String) "Result value: " + myME310.return_string(myRc)); //print the anwser value
while(myME310.buffer_cstr(i) != NULL)
{
Serial.println(myME310.buffer_cstr(i)); //print line of modem answer
i++;
}

const char readCommand[] = "at+cops?";
Serial.println((String)"Send: " + readCommand);
myRc = myME310.send_command(readCommand, OKanswer); //issue a command indicated in the string and wait for anwser or timeout
Serial.println((String) "Result value: " + myME310.return_string(myRc));
Serial.println(myME310.buffer_cstr(1));

const char testCommand[] = "at+cmee=?";
Serial.println((String)"Send: " + testCommand);
myRc = myME310.send_command(testCommand, OKanswer);
Serial.println((String) "Result value: " + myME310.return_string(myRc));
Serial.println(myME310.buffer_cstr(1));
}

void loop() {
// put your main code here, to run repeatedly:
Serial.println("The application has ended...");
exit(0);
}
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.6.0
version=2.7.0
author=Telit
maintainer=Telit <[email protected]>
sentence=Allows communication with ME310G1 Telit module.
Expand Down
18 changes: 17 additions & 1 deletion 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.6.0
2.7.0
@note
Expand Down Expand Up @@ -6368,6 +6368,22 @@ ME310::return_t ME310::set_trace(int mode, char* configuration_string, tout_t aT
snprintf((char *)mBuffer, ME310_BUFFSIZE-1, F("AT#TRACE=%d,%s"), mode, configuration_string);
return send_wait((char*)mBuffer, OK_STRING, aTimeout);
}

//! \brief Send the generic AT command and waits for a specific answer
/*! \details
The command sends a generic AT command and waits for a specific answer.
* \param aCommand command string to send
* \param aAnswer answer string to wait for
* \param aTimeout answer timeout
* \return return code
*/
ME310::return_t ME310::send_command(const char *aCommand, const char *aAnswer, tout_t aTimeout)
{
memset(mBuffer, 0, ME310_BUFFSIZE);
snprintf((char *)mBuffer, ME310_BUFFSIZE-1, aCommand);
return send_wait((char*)mBuffer, aAnswer, aTimeout);
}

//--------------------------------------------------------------------------------------------------------------
//! \brief Returns the string by index received from the ME310 serial connection
/*!
Expand Down
9 changes: 7 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.6.0
2.7.0
@note
Dependencies:
Expand Down Expand Up @@ -1243,7 +1243,12 @@ namespace me310

return_t set_trace(int mode, char* configuration_string, tout_t aTimeout = TOUT_100MS);
_READ_TEST(set_trace, "AT#TRACE", TOUT_100MS)
// -----------------------------------------------------------------------------

// Generic Command---------------------------------------------------------------

return_t send_command(const char *aCommand, const char *aAnswer = OK_STRING, tout_t aTimeout = TOUT_200MS);


const uint8_t *buffer(void) { return mBuffer;} //!< Returns pointer to local buffer
size_t length(void) { return mBuffLen;} //!< Returns length of local buffer
const char * buffer_cstr(int aIndex = 0);
Expand Down

0 comments on commit 455fd27

Please sign in to comment.