works!

Dependencies:   mbed

Committer:
kchhouk
Date:
Fri Feb 21 21:03:41 2020 +0000
Revision:
2:5e5cdc3504fe
Parent:
0:5c1655777e38
Added the functionality of scanf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kchhouk 0:5c1655777e38 1 #include "mbed.h"
kchhouk 0:5c1655777e38 2 #include "USBSerial.h"
kchhouk 0:5c1655777e38 3 //#include "string.h"
kchhouk 0:5c1655777e38 4
kchhouk 0:5c1655777e38 5 // Blinking rate in milliseconds
kchhouk 0:5c1655777e38 6 #define BLINKING_RATE_MS 500
kchhouk 0:5c1655777e38 7 #define CTRL_Z 26 //Attach at the end of this message string
kchhouk 0:5c1655777e38 8
kchhouk 0:5c1655777e38 9 // Virtual serial port over USB
kchhouk 0:5c1655777e38 10 USBSerial microUSB;
kchhouk 0:5c1655777e38 11 Serial SIM800L(P0_1, P0_0); //tx, rx
kchhouk 0:5c1655777e38 12 // Serial pc(USBTX, USBRX);
kchhouk 0:5c1655777e38 13 char buf[40];
kchhouk 0:5c1655777e38 14 char buf1[40];
kchhouk 2:5e5cdc3504fe 15 char sstr[40];
kchhouk 0:5c1655777e38 16 long GSMBAUD = 9600;
kchhouk 0:5c1655777e38 17 // long PCBAUD = 9600;
kchhouk 0:5c1655777e38 18
kchhouk 0:5c1655777e38 19 int main()
kchhouk 0:5c1655777e38 20 {
kchhouk 0:5c1655777e38 21 // Initialise the digital pin LED1 as an output
kchhouk 0:5c1655777e38 22 //DigitalOut led(LED1);
kchhouk 0:5c1655777e38 23 SIM800L.baud(GSMBAUD);
kchhouk 2:5e5cdc3504fe 24 microUSB.scanf("%s", sstr);
kchhouk 2:5e5cdc3504fe 25
kchhouk 0:5c1655777e38 26 //microUSB.scanf("%s", buf);
kchhouk 0:5c1655777e38 27 SIM800L.puts("AT\r\n");
kchhouk 0:5c1655777e38 28 SIM800L.scanf("%s", buf);
kchhouk 0:5c1655777e38 29 SIM800L.scanf("%s", buf1);
kchhouk 0:5c1655777e38 30 microUSB.printf("%s" , buf);
kchhouk 0:5c1655777e38 31 microUSB.printf("%s\n", buf1);
kchhouk 0:5c1655777e38 32
kchhouk 0:5c1655777e38 33 SIM800L.puts("AT+CMGF=1\r\n");
kchhouk 0:5c1655777e38 34 SIM800L.scanf("%s", buf);
kchhouk 0:5c1655777e38 35 SIM800L.scanf("%s", buf1);
kchhouk 0:5c1655777e38 36 microUSB.printf("%s" , buf);
kchhouk 0:5c1655777e38 37 microUSB.printf("%s\n", buf1);
kchhouk 0:5c1655777e38 38
kchhouk 0:5c1655777e38 39 SIM800L.puts("AT+CMGS=\"17039739276\"\r\n");
kchhouk 0:5c1655777e38 40
kchhouk 0:5c1655777e38 41 wait(0.1f);
kchhouk 0:5c1655777e38 42
kchhouk 0:5c1655777e38 43 SIM800L.printf("This is the automatted program SMS from SIM800L. :D %c\r\n", CTRL_Z);
kchhouk 0:5c1655777e38 44
kchhouk 0:5c1655777e38 45 SIM800L.scanf("%s", buf);
kchhouk 0:5c1655777e38 46 SIM800L.scanf("%s", buf1);
kchhouk 0:5c1655777e38 47 microUSB.printf("%s" , buf);
kchhouk 0:5c1655777e38 48 microUSB.printf("%s\n", buf1);
kchhouk 0:5c1655777e38 49
kchhouk 0:5c1655777e38 50 wait(1);
kchhouk 0:5c1655777e38 51
kchhouk 0:5c1655777e38 52 //pc.printf("Yike");
kchhouk 0:5c1655777e38 53 SIM800L.puts("AT+CMGF=0\r\n");
kchhouk 0:5c1655777e38 54 SIM800L.scanf("%s", buf);
kchhouk 0:5c1655777e38 55 SIM800L.scanf("%s", buf1);
kchhouk 0:5c1655777e38 56 microUSB.printf("%s" , buf);
kchhouk 0:5c1655777e38 57 microUSB.printf("%s\n", buf1);
kchhouk 0:5c1655777e38 58 //led = !led;
kchhouk 0:5c1655777e38 59 // pc.printf("regular serial communication works!");
kchhouk 0:5c1655777e38 60 //microUSB.printf("you typed: %s\r\n",buf);
kchhouk 0:5c1655777e38 61 //microUSB.printf("\x1B[2J"); //clear terminal program screen
kchhouk 0:5c1655777e38 62 // while (SIM800L.readable()){
kchhouk 0:5c1655777e38 63 // microUSB.printf("%c", microUSB.putc((SIM800L.getc())));
kchhouk 0:5c1655777e38 64 //
kchhouk 0:5c1655777e38 65 }
kchhouk 0:5c1655777e38 66