A snipet to show one example of writing commands with variables -- a MUCH NEEDED expansion of the ATCommands example. I hope this saves someone the time I wasted trying to get it to work.
//------------------------------------------------------------
//
// AT Cmd section used in API mode.
//
// This example exhibits Sleep commands but applies to any command that needs to
// pass a parameter.
//
//------------------------------------------------------------
void SetSleep()
{
uint8_t cmd_p[] = "SP", val_p[] = { 0x01, 0xf4 }; //500 10ms = 5 S sleep
uint8_t cmd_n[] = "SN", val_n[] = { 0x01 }; // # of SP's before pin assert /on/sleep
uint8_t cmd_t[] = "ST", val_t[] = { 0x03, 0xe8 }; // 1ms = 1S wake
uint8_t cmd_o[] = "SO", val_o[] = { 0x01, 0x00 }; // wake for all ST
uint8_t cmd_m[] = "SM", val_m[] = { 0x05 }; // 0 is disable 5 (& others) will sleep 5 sec wake 1s
uint8_t cmd_ac[] = "AC"; // apply above changes
//uint8_t cmd_ss[] = "SS"; // status read
//uint8_t cmd_os[] = "OS"; // status read
//uint8_t cmd_ow[] = "OW"; // status read
atRequest.setCommand(cmd_p); // The AT command
atRequest.setCommandValue(val_p); // The variable
atRequest.setCommandValueLength(sizeof(val_p)); // Number of bytes in the variable
SendATCmd(); // Send params (cmd, value, length of value)
atRequest.clearCommandValue(); // clear the passed params
atRequest.setCommand(cmd_ac); // write to actually store vars
SendATCmd();
/
atRequest.setCommand(cmd_ss); // these seem to display old or maybe default values
SendATCmd();
atRequest.setCommand(cmd_os);
SendATCmd();
atRequest.setCommand(cmd_ow);
SendATCmd();
/
/
atRequest.setCommand(cmd_p); // read what we just put there
SendATCmd();
atRequest.setCommand(cmd_n);
SendATCmd();
atRequest.setCommand(cmd_t);
SendATCmd();
atRequest.setCommand(cmd_o);
SendATCmd();
atRequest.setCommand(cmd_m);
SendATCmd(); /
}
A snipet to show one example of writing commands with variables -- a MUCH NEEDED expansion of the ATCommands example. I hope this saves someone the time I wasted trying to get it to work.
//------------------------------------------------------------ // // AT Cmd section used in API mode. // // This example exhibits Sleep commands but applies to any command that needs to // pass a parameter. // //------------------------------------------------------------
void InitATCmd() { atRequest = AtCommandRequest(); atResponse = AtCommandResponse(); }
void SetSleep() {
uint8_t cmd_p[] = "SP", val_p[] = { 0x01, 0xf4 }; //500 10ms = 5 S sleep uint8_t cmd_n[] = "SN", val_n[] = { 0x01 }; // # of SP's before pin assert /on/sleep uint8_t cmd_t[] = "ST", val_t[] = { 0x03, 0xe8 }; // 1ms = 1S wake uint8_t cmd_o[] = "SO", val_o[] = { 0x01, 0x00 }; // wake for all ST uint8_t cmd_m[] = "SM", val_m[] = { 0x05 }; // 0 is disable 5 (& others) will sleep 5 sec wake 1s
uint8_t cmd_ac[] = "AC"; // apply above changes
//uint8_t cmd_ss[] = "SS"; // status read //uint8_t cmd_os[] = "OS"; // status read
//uint8_t cmd_ow[] = "OW"; // status read
atRequest.setCommand(cmd_p); // The AT command atRequest.setCommandValue(val_p); // The variable atRequest.setCommandValueLength(sizeof(val_p)); // Number of bytes in the variable SendATCmd(); // Send params (cmd, value, length of value) atRequest.clearCommandValue(); // clear the passed params
atRequest.setCommand(cmd_n); atRequest.setCommandValue(val_n); atRequest.setCommandValueLength(sizeof(val_n)); SendATCmd(); atRequest.clearCommandValue();
atRequest.setCommand(cmd_t); atRequest.setCommandValue(val_t); atRequest.setCommandValueLength(sizeof(val_t)); SendATCmd(); atRequest.clearCommandValue();
atRequest.setCommand(cmd_o); atRequest.setCommandValue(val_o); atRequest.setCommandValueLength(sizeof(val_o)); SendATCmd(); atRequest.clearCommandValue();
atRequest.setCommand(cmd_m); atRequest.setCommandValue(val_m); atRequest.setCommandValueLength(sizeof(val_m)); SendATCmd();
atRequest.clearCommandValue();
atRequest.setCommand(cmd_ac); // write to actually store vars SendATCmd();
/ atRequest.setCommand(cmd_ss); // these seem to display old or maybe default values SendATCmd(); atRequest.setCommand(cmd_os); SendATCmd(); atRequest.setCommand(cmd_ow); SendATCmd(); / / atRequest.setCommand(cmd_p); // read what we just put there SendATCmd();
atRequest.setCommand(cmd_n); SendATCmd();
atRequest.setCommand(cmd_t); SendATCmd();
atRequest.setCommand(cmd_o); SendATCmd();
atRequest.setCommand(cmd_m); SendATCmd();
/ }