STM32F103C8T6_Internal_RTC
Dependencies: mbed-STM32F103C8T6 mbed
Fork of STM32F103C8T6_GPRS_TCP by
main.cpp@12:91de57777095, 2018-07-13 (annotated)
- Committer:
- shivanandgowdakr
- Date:
- Fri Jul 13 07:36:58 2018 +0000
- Revision:
- 12:91de57777095
- Parent:
- 10:4b88be251088
- Child:
- 13:bf9a5ca067bf
STM32F103C8T6 GPRS TCP ; ; Example Program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 5:3c3ef17a17a6 | 1 | #include "stm32f103c8t6.h" |
hudakz | 0:ab218237069e | 2 | #include "mbed.h" |
shivanandgowdakr | 12:91de57777095 | 3 | #include "gprs.h" |
shivanandgowdakr | 12:91de57777095 | 4 | |
shivanandgowdakr | 12:91de57777095 | 5 | char Server[20]="119.81.0.11" ; //write your Server IP here shoud be a static IP |
shivanandgowdakr | 12:91de57777095 | 6 | char Port[5]="8080"; // write your port Number |
shivanandgowdakr | 12:91de57777095 | 7 | char Phone_No[11]="1234567890"; |
shivanandgowdakr | 12:91de57777095 | 8 | char Service_Provider[40]="airtelgprs.com"; |
shivanandgowdakr | 12:91de57777095 | 9 | char Data[100]="Hellow World to Server"; |
hudakz | 10:4b88be251088 | 10 | |
hudakz | 10:4b88be251088 | 11 | Serial pc(PA_2, PA_3); |
hudakz | 10:4b88be251088 | 12 | DigitalOut myled(LED1); |
shivanandgowdakr | 12:91de57777095 | 13 | GPRS gprs(PB_6,PB_7,9600,Phone_No); |
shivanandgowdakr | 12:91de57777095 | 14 | char Reply[100]={'\0'}; |
shivanandgowdakr | 12:91de57777095 | 15 | int main() |
shivanandgowdakr | 12:91de57777095 | 16 | { |
shivanandgowdakr | 12:91de57777095 | 17 | confSysClock(); |
hudakz | 7:accb2c83a007 | 18 | myled = 0; // turn the LED on |
hudakz | 10:4b88be251088 | 19 | wait_ms(200); // 200 millisecond |
hudakz | 7:accb2c83a007 | 20 | myled = 1; // turn the LED off |
hudakz | 10:4b88be251088 | 21 | wait_ms(1000); // 1000 millisecond |
hudakz | 5:3c3ef17a17a6 | 22 | pc.printf("Blink\r\n"); |
shivanandgowdakr | 12:91de57777095 | 23 | |
shivanandgowdakr | 12:91de57777095 | 24 | |
shivanandgowdakr | 12:91de57777095 | 25 | pc.printf("Am here.... GOOD\r\n"); |
shivanandgowdakr | 12:91de57777095 | 26 | gprs.init(); |
shivanandgowdakr | 12:91de57777095 | 27 | if(gprs.checkSIMStatus()==0) |
shivanandgowdakr | 12:91de57777095 | 28 | { |
shivanandgowdakr | 12:91de57777095 | 29 | pc.printf("SIM Status is GOOD\r\n"); |
shivanandgowdakr | 12:91de57777095 | 30 | } |
shivanandgowdakr | 12:91de57777095 | 31 | else |
shivanandgowdakr | 12:91de57777095 | 32 | { |
shivanandgowdakr | 12:91de57777095 | 33 | pc.printf("SIM NOT Preset \r\n"); |
shivanandgowdakr | 12:91de57777095 | 34 | } |
shivanandgowdakr | 12:91de57777095 | 35 | |
shivanandgowdakr | 12:91de57777095 | 36 | if(gprs.checkSignalStrength ()>=3) |
shivanandgowdakr | 12:91de57777095 | 37 | { |
shivanandgowdakr | 12:91de57777095 | 38 | pc.printf("Signal strength Good \r\n"); |
shivanandgowdakr | 12:91de57777095 | 39 | |
shivanandgowdakr | 12:91de57777095 | 40 | } |
shivanandgowdakr | 12:91de57777095 | 41 | else |
shivanandgowdakr | 12:91de57777095 | 42 | { |
shivanandgowdakr | 12:91de57777095 | 43 | pc.printf("Signal strength Weak\r\n"); |
shivanandgowdakr | 12:91de57777095 | 44 | } |
shivanandgowdakr | 12:91de57777095 | 45 | |
shivanandgowdakr | 12:91de57777095 | 46 | if(gprs.checkSIMStatus()==0) |
shivanandgowdakr | 12:91de57777095 | 47 | { |
shivanandgowdakr | 12:91de57777095 | 48 | pc.printf("SIM Status is GOOD\r\n"); |
shivanandgowdakr | 12:91de57777095 | 49 | } |
shivanandgowdakr | 12:91de57777095 | 50 | |
shivanandgowdakr | 12:91de57777095 | 51 | else |
shivanandgowdakr | 12:91de57777095 | 52 | { |
shivanandgowdakr | 12:91de57777095 | 53 | pc.printf("SIM NOT Present \r\n"); |
shivanandgowdakr | 12:91de57777095 | 54 | } |
shivanandgowdakr | 12:91de57777095 | 55 | |
shivanandgowdakr | 12:91de57777095 | 56 | // gprs.networkInit( "202.56.231.117:8080"); |
shivanandgowdakr | 12:91de57777095 | 57 | int success= gprs.networkInit(Service_Provider); //write your apn here |
shivanandgowdakr | 12:91de57777095 | 58 | if(success==0) |
shivanandgowdakr | 12:91de57777095 | 59 | pc.printf("Network Initialised \r\n"); |
shivanandgowdakr | 12:91de57777095 | 60 | else |
shivanandgowdakr | 12:91de57777095 | 61 | pc.printf("Unable Initialise Network \r\n"); |
shivanandgowdakr | 12:91de57777095 | 62 | |
shivanandgowdakr | 12:91de57777095 | 63 | |
shivanandgowdakr | 12:91de57777095 | 64 | success=gprs.connectTCP(Server,Port); |
shivanandgowdakr | 12:91de57777095 | 65 | |
shivanandgowdakr | 12:91de57777095 | 66 | if(success==0) |
shivanandgowdakr | 12:91de57777095 | 67 | pc.printf("Connected to Server \r\n"); |
shivanandgowdakr | 12:91de57777095 | 68 | else |
shivanandgowdakr | 12:91de57777095 | 69 | pc.printf("Unable connect to Server \r\n"); |
shivanandgowdakr | 12:91de57777095 | 70 | |
shivanandgowdakr | 12:91de57777095 | 71 | success= gprs.sendTCPData(Data); |
shivanandgowdakr | 12:91de57777095 | 72 | |
shivanandgowdakr | 12:91de57777095 | 73 | if(success==0) |
shivanandgowdakr | 12:91de57777095 | 74 | pc.printf("Data Sent \r\n"); |
shivanandgowdakr | 12:91de57777095 | 75 | else |
shivanandgowdakr | 12:91de57777095 | 76 | pc.printf("Unable connect to Server \r\n"); |
shivanandgowdakr | 12:91de57777095 | 77 | |
shivanandgowdakr | 12:91de57777095 | 78 | success=gprs.waitforReply(Reply); |
shivanandgowdakr | 12:91de57777095 | 79 | |
shivanandgowdakr | 12:91de57777095 | 80 | if(success==0) |
shivanandgowdakr | 12:91de57777095 | 81 | pc.printf("Data Received form Server \r\n"); |
shivanandgowdakr | 12:91de57777095 | 82 | else |
shivanandgowdakr | 12:91de57777095 | 83 | pc.printf("No Reply from Server \r\n"); |
shivanandgowdakr | 12:91de57777095 | 84 | |
shivanandgowdakr | 12:91de57777095 | 85 | success=gprs.closeTCP(); |
shivanandgowdakr | 12:91de57777095 | 86 | |
shivanandgowdakr | 12:91de57777095 | 87 | if(success==0) |
shivanandgowdakr | 12:91de57777095 | 88 | pc.printf("Close TCP Connection \r\n"); |
shivanandgowdakr | 12:91de57777095 | 89 | else |
shivanandgowdakr | 12:91de57777095 | 90 | pc.printf("Unable to detach from Server \r\n"); |
shivanandgowdakr | 12:91de57777095 | 91 | |
shivanandgowdakr | 12:91de57777095 | 92 | success=gprs.shutTCP(); |
shivanandgowdakr | 12:91de57777095 | 93 | |
shivanandgowdakr | 12:91de57777095 | 94 | if(success==0) |
shivanandgowdakr | 12:91de57777095 | 95 | pc.printf("Shut TCP Connection \r\n"); |
shivanandgowdakr | 12:91de57777095 | 96 | else |
shivanandgowdakr | 12:91de57777095 | 97 | pc.printf("Unable to Shut TCP Connection \r\n"); |
shivanandgowdakr | 12:91de57777095 | 98 | |
hudakz | 0:ab218237069e | 99 | } |
shivanandgowdakr | 12:91de57777095 | 100 | |
shivanandgowdakr | 12:91de57777095 | 101 | |
shivanandgowdakr | 12:91de57777095 | 102 | |
shivanandgowdakr | 12:91de57777095 | 103 | |
shivanandgowdakr | 12:91de57777095 | 104 | |
shivanandgowdakr | 12:91de57777095 | 105 | |
shivanandgowdakr | 12:91de57777095 | 106 | |
shivanandgowdakr | 12:91de57777095 | 107 |