Automating AT Commands

Hi guys,

I’ve currently written a sequence of AT commands to connect my SODAQ R410M to the network and send a message. Yet it’s getting quite tedious to put all those AT commands in the serial monitor by hand. Is there any way of writing code to automatically send AT commands to the SARA module? I’ve seen some example code use the serial streams, yet I haven’t been succesfull in doing so myself.

Here’s an example of the sequence I want to send:

AT+URAT=8
AT+CMEE=2
AT+CGDCONT=1,“IP”,“nb.inetd.gdsp”
AT+CFUN=1
AT+COPS=1,2,“20404”
AT+CEREG=2
AT+USOCR=17
AT+UDCONF=1 ,1
AT+USOST=0,“Server_IP”,PORT,ByteCount,“40 bytes of hex data”
AT+USOCL=0

I’m currently working in the Arduino IDE, so my prefered way of sending the commands is using a .c file.
Any of you who have experience with this?

~Michael

You can write a function using Serial1.println() to send the AT-Commands to the R410M.
Before sending the next command, you should wait for a response.
The best way to do this is using MODEM_STREAM.read().

Ah, didn’t know I had to actually wait for a response. So I could use the following?

Serial1.println(“AT+CSQ”);
_While(MODEM_STREAM.read() != “OK”){
}
Serial1.println(“AT+URAT=8”);
_While(MODEM_STREAM.read() != “OK”){
}

So send some command, wait untill I receive “OK”, then send the next one?

~Michael

I tried working out the example.
Unfortunately I couldn’t get rid of the delay function.
When I replace delay(2000) with While(MODEM_STREAM.read() != “OK”){}, my application stops working.
This is what I have for now:

I put the commands in a String array and loop over it.

Thanks for thinking along! I’m definitely gonna try this for a couple of commands of which I know for sure they will return OK. Not quite sure on commands like AT+COPS which can take a little longer. Guess I’ll have to find a way to wait for any reply from the SARA. Thanks a lot though! :slight_smile:

We have NB-IoT library, it works on the R410 and N211.
Just for the R410 example, #define R4XX needs to be in the top of the sketch.