Wifi module configuration for GR_Peach
Dependencies: mbed
Wifi.cpp@2:19bd6403dc75, 2017-01-04 (annotated)
- Committer:
- akverma
- Date:
- Wed Jan 04 07:42:43 2017 +0000
- Revision:
- 2:19bd6403dc75
- Parent:
- 1:e5ef21ebff5f
Wifi module working;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RahulSitaram | 0:7d24b78f9a5e | 1 | #include "mbed.h" |
RahulSitaram | 1:e5ef21ebff5f | 2 | #include <string> |
RahulSitaram | 1:e5ef21ebff5f | 3 | |
RahulSitaram | 1:e5ef21ebff5f | 4 | |
RahulSitaram | 1:e5ef21ebff5f | 5 | |
RahulSitaram | 0:7d24b78f9a5e | 6 | DigitalOut led1(LED1); |
RahulSitaram | 0:7d24b78f9a5e | 7 | DigitalOut led2(LED2); |
RahulSitaram | 1:e5ef21ebff5f | 8 | string data; |
RahulSitaram | 0:7d24b78f9a5e | 9 | uint8_t wifi_ack; |
RahulSitaram | 0:7d24b78f9a5e | 10 | Serial pc(USBTX, USBRX); |
RahulSitaram | 1:e5ef21ebff5f | 11 | //Serial Wifi(P2_14,P2_15); |
akverma | 2:19bd6403dc75 | 12 | Serial Wifi(P5_0, P5_1); |
RahulSitaram | 1:e5ef21ebff5f | 13 | bool i = true; |
RahulSitaram | 1:e5ef21ebff5f | 14 | bool j = false; |
RahulSitaram | 1:e5ef21ebff5f | 15 | char MSB; |
RahulSitaram | 1:e5ef21ebff5f | 16 | char LSB; |
RahulSitaram | 1:e5ef21ebff5f | 17 | |
akverma | 2:19bd6403dc75 | 18 | /* |
RahulSitaram | 0:7d24b78f9a5e | 19 | void call() { |
RahulSitaram | 0:7d24b78f9a5e | 20 | // Note: you need to actually read from the serial to clear the RX interrupt |
RahulSitaram | 1:e5ef21ebff5f | 21 | data = Wifi.getc(); |
RahulSitaram | 1:e5ef21ebff5f | 22 | pc.printf("%c\n", data); |
RahulSitaram | 1:e5ef21ebff5f | 23 | // Wifi.printf("%c",data); |
akverma | 2:19bd6403dc75 | 24 | }*/ |
RahulSitaram | 0:7d24b78f9a5e | 25 | |
RahulSitaram | 0:7d24b78f9a5e | 26 | int main() { |
akverma | 2:19bd6403dc75 | 27 | char c,d; |
RahulSitaram | 0:7d24b78f9a5e | 28 | //pc.attach(&call); |
RahulSitaram | 1:e5ef21ebff5f | 29 | pc.baud(9600); |
RahulSitaram | 1:e5ef21ebff5f | 30 | Wifi.baud(115200); |
RahulSitaram | 1:e5ef21ebff5f | 31 | //Wifi.attach(&call); |
RahulSitaram | 1:e5ef21ebff5f | 32 | /*while(1){ |
RahulSitaram | 1:e5ef21ebff5f | 33 | //Wifi.printf("AT\n"); |
RahulSitaram | 1:e5ef21ebff5f | 34 | //pc.printf("done!\n"); |
RahulSitaram | 1:e5ef21ebff5f | 35 | |
RahulSitaram | 1:e5ef21ebff5f | 36 | if(pc.readable()) { |
RahulSitaram | 1:e5ef21ebff5f | 37 | pc.putc(pc.getc()); |
RahulSitaram | 1:e5ef21ebff5f | 38 | led1 = ~led1; |
RahulSitaram | 1:e5ef21ebff5f | 39 | } |
RahulSitaram | 1:e5ef21ebff5f | 40 | if(Wifi.readable()) { |
RahulSitaram | 1:e5ef21ebff5f | 41 | pc.putc(Wifi.getc()); |
RahulSitaram | 1:e5ef21ebff5f | 42 | led2 = ~led2; |
RahulSitaram | 1:e5ef21ebff5f | 43 | } |
RahulSitaram | 1:e5ef21ebff5f | 44 | |
RahulSitaram | 1:e5ef21ebff5f | 45 | |
RahulSitaram | 1:e5ef21ebff5f | 46 | //wifi_ack = Wifi.getc(); |
RahulSitaram | 1:e5ef21ebff5f | 47 | //pc.printf("%c\n", wifi_ack); |
RahulSitaram | 1:e5ef21ebff5f | 48 | //wait(5); |
RahulSitaram | 1:e5ef21ebff5f | 49 | }*/ |
RahulSitaram | 1:e5ef21ebff5f | 50 | |
RahulSitaram | 1:e5ef21ebff5f | 51 | while (1) |
RahulSitaram | 1:e5ef21ebff5f | 52 | { |
RahulSitaram | 1:e5ef21ebff5f | 53 | if(Wifi.readable()) // check if the esp is sending a message |
RahulSitaram | 1:e5ef21ebff5f | 54 | { |
RahulSitaram | 1:e5ef21ebff5f | 55 | while(Wifi.readable()) |
RahulSitaram | 1:e5ef21ebff5f | 56 | { |
RahulSitaram | 1:e5ef21ebff5f | 57 | // The esp has data so display its output to the serial window |
akverma | 2:19bd6403dc75 | 58 | c = Wifi.getc(); // read the next character. |
RahulSitaram | 1:e5ef21ebff5f | 59 | pc.putc(c); |
RahulSitaram | 1:e5ef21ebff5f | 60 | //pc.printf("%c", c); |
akverma | 2:19bd6403dc75 | 61 | //i=~i; |
RahulSitaram | 1:e5ef21ebff5f | 62 | } |
RahulSitaram | 1:e5ef21ebff5f | 63 | } |
akverma | 2:19bd6403dc75 | 64 | if(pc.readable()) // check if the esp is sending a message |
RahulSitaram | 1:e5ef21ebff5f | 65 | { |
RahulSitaram | 1:e5ef21ebff5f | 66 | while(pc.readable()) |
RahulSitaram | 1:e5ef21ebff5f | 67 | { |
RahulSitaram | 1:e5ef21ebff5f | 68 | // The esp has data so display its output to the serial window |
akverma | 2:19bd6403dc75 | 69 | d = pc.getc(); // read the next character. |
RahulSitaram | 1:e5ef21ebff5f | 70 | Wifi.putc(d); |
RahulSitaram | 1:e5ef21ebff5f | 71 | //pc.printf("%c", c); |
akverma | 2:19bd6403dc75 | 72 | //j=~j; |
RahulSitaram | 1:e5ef21ebff5f | 73 | } |
RahulSitaram | 1:e5ef21ebff5f | 74 | } |
akverma | 2:19bd6403dc75 | 75 | // led1=i; |
akverma | 2:19bd6403dc75 | 76 | // led2=j; |
RahulSitaram | 1:e5ef21ebff5f | 77 | } |
RahulSitaram | 1:e5ef21ebff5f | 78 | } |