SIM800L works with AT command on CoolTerm.

Dependencies:   mbed BufferedSerial SoftSerial

Committer:
kchhouk
Date:
Fri Jan 31 20:55:08 2020 +0000
Revision:
0:b98b6cf2edfe
SIM800L works, with AT command, CoolTerm.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kchhouk 0:b98b6cf2edfe 1 #include "mbed.h"
kchhouk 0:b98b6cf2edfe 2 #include "BufferedSerial.h"
kchhouk 0:b98b6cf2edfe 3 #include <string>
kchhouk 0:b98b6cf2edfe 4
kchhouk 0:b98b6cf2edfe 5 //Works with AT Command
kchhouk 0:b98b6cf2edfe 6 Serial pc(USBTX, USBRX);
kchhouk 0:b98b6cf2edfe 7 Serial SIM800L(P3_1, P3_0);
kchhouk 0:b98b6cf2edfe 8 DigitalOut led1(LED1);
kchhouk 0:b98b6cf2edfe 9 DigitalOut led2(LED2);
kchhouk 0:b98b6cf2edfe 10
kchhouk 0:b98b6cf2edfe 11 char *phone = "\"17039739276\"";
kchhouk 0:b98b6cf2edfe 12 //char str[2];
kchhouk 0:b98b6cf2edfe 13
kchhouk 0:b98b6cf2edfe 14 long GSMBAUD = 9600;
kchhouk 0:b98b6cf2edfe 15 long PCBAUD = 9600;
kchhouk 0:b98b6cf2edfe 16
kchhouk 0:b98b6cf2edfe 17 int main(){
kchhouk 0:b98b6cf2edfe 18 pc.baud(PCBAUD);
kchhouk 0:b98b6cf2edfe 19 SIM800L.baud(GSMBAUD);
kchhouk 0:b98b6cf2edfe 20 /*
kchhouk 0:b98b6cf2edfe 21 SIM800L.puts("AT");
kchhouk 0:b98b6cf2edfe 22 SIM800L.puts("\r\n");
kchhouk 0:b98b6cf2edfe 23 //wait(0.1f);
kchhouk 0:b98b6cf2edfe 24
kchhouk 0:b98b6cf2edfe 25 SIM800L.puts("AT+CMGF=1");
kchhouk 0:b98b6cf2edfe 26 SIM800L.puts("\r\n");
kchhouk 0:b98b6cf2edfe 27 //wait(0.1f);
kchhouk 0:b98b6cf2edfe 28
kchhouk 0:b98b6cf2edfe 29 SIM800L.puts("AT+CMGS=\"17039739276\"");
kchhouk 0:b98b6cf2edfe 30 SIM800L.puts("\r\n");
kchhouk 0:b98b6cf2edfe 31 //wait(0.1f);
kchhouk 0:b98b6cf2edfe 32
kchhouk 0:b98b6cf2edfe 33 SIM800L.printf("Testing SMS from KC.");
kchhouk 0:b98b6cf2edfe 34 //SIM800L.puts("\r\n");
kchhouk 0:b98b6cf2edfe 35 //wait(0.1f);
kchhouk 0:b98b6cf2edfe 36 //wait_ms(500);
kchhouk 0:b98b6cf2edfe 37 */
kchhouk 0:b98b6cf2edfe 38 while(1){
kchhouk 0:b98b6cf2edfe 39 while(pc.readable()){
kchhouk 0:b98b6cf2edfe 40 SIM800L.putc(pc.getc());
kchhouk 0:b98b6cf2edfe 41 //SIM800L.printf("%c", SIM800L.putc(pc.getc()));
kchhouk 0:b98b6cf2edfe 42 //SIM800L.puts("\r\n");
kchhouk 0:b98b6cf2edfe 43 }
kchhouk 0:b98b6cf2edfe 44 wait(0.1f);
kchhouk 0:b98b6cf2edfe 45 while(SIM800L.readable()){
kchhouk 0:b98b6cf2edfe 46 //pc.putc(SIM800L.getc());
kchhouk 0:b98b6cf2edfe 47 pc.printf("%c", pc.putc(SIM800L.getc()));
kchhouk 0:b98b6cf2edfe 48 }
kchhouk 0:b98b6cf2edfe 49 //wait(0.1f);
kchhouk 0:b98b6cf2edfe 50
kchhouk 0:b98b6cf2edfe 51
kchhouk 0:b98b6cf2edfe 52
kchhouk 0:b98b6cf2edfe 53 }
kchhouk 0:b98b6cf2edfe 54
kchhouk 0:b98b6cf2edfe 55
kchhouk 0:b98b6cf2edfe 56 }