// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
// ------------------------------------- WARNING -------------------------------------
// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
// ---- This code is experimental and may not work and ruin the rest of your code ----
// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
#include "ATCommands.h"
void led(const char *parameter)
{
if (strlen(parameter) == 1)
if (parameter[0] == '1')
digitalWrite(13, HIGH);
else if (parameter[0] == '0')
digitalWrite(13, LOW);
}
void echo(const char *parameter)
{
Serial.println(parameter);
}
ATClass at;
void setup()
{
Serial.begin(9600);
Serial.println("Type some AT shit.");
at.attachCallback("LED", led); // LED=1 or LED=0 to change board LED state
at.attachCallback("ECHO", echo); // ECHO={string} without the brackets will echo the string
}
void loop()
{
if (Serial.available() > 0)
{
String serialBuffer = Serial.readStringUntil('\n');
serialBuffer.replace('\r', '\0'); // Remove ending characters if present
serialBuffer.replace('\n', '\0'); // If terminal sends only lf this is not needed
at.commandInput(serialBuffer.c_str());
}
delay(250);
}