GR_Peach_Abhinav_Rahul
/
test_thread_reneproj
Exclusive code for server communication
Fork of test_thread by
main.cpp@1:0ceb20b56f7f, 2017-01-09 (annotated)
- Committer:
- RahulSitaram
- Date:
- Mon Jan 09 10:53:01 2017 +0000
- Revision:
- 1:0ceb20b56f7f
- Parent:
- 0:adb256c0dfa9
- Child:
- 2:52ecf89221d3
Raw code for exclusive communication with server
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akverma | 0:adb256c0dfa9 | 1 | #include "mbed.h" |
akverma | 0:adb256c0dfa9 | 2 | #include "rtos.h" |
RahulSitaram | 1:0ceb20b56f7f | 3 | #include <string> |
akverma | 0:adb256c0dfa9 | 4 | |
akverma | 0:adb256c0dfa9 | 5 | DigitalOut led1(LED1); |
akverma | 0:adb256c0dfa9 | 6 | DigitalOut led2(LED2); |
RahulSitaram | 1:0ceb20b56f7f | 7 | std::string data; |
RahulSitaram | 1:0ceb20b56f7f | 8 | char read_data; |
RahulSitaram | 1:0ceb20b56f7f | 9 | uint8_t wifi_ack; |
RahulSitaram | 1:0ceb20b56f7f | 10 | Serial pc(USBTX, USBRX); |
RahulSitaram | 1:0ceb20b56f7f | 11 | //Serial Wifi(P2_14,P2_15); |
RahulSitaram | 1:0ceb20b56f7f | 12 | Serial Wifi(P5_0, P5_1); |
RahulSitaram | 1:0ceb20b56f7f | 13 | bool i = true; |
RahulSitaram | 1:0ceb20b56f7f | 14 | bool j = false; |
RahulSitaram | 1:0ceb20b56f7f | 15 | char MSB; |
RahulSitaram | 1:0ceb20b56f7f | 16 | char LSB; |
akverma | 0:adb256c0dfa9 | 17 | |
RahulSitaram | 1:0ceb20b56f7f | 18 | void reader_thread(void const *args) { |
RahulSitaram | 1:0ceb20b56f7f | 19 | while (true) { |
RahulSitaram | 1:0ceb20b56f7f | 20 | if(Wifi.readable()){ |
RahulSitaram | 1:0ceb20b56f7f | 21 | while(Wifi.readable()){ |
RahulSitaram | 1:0ceb20b56f7f | 22 | read_data = Wifi.getc(); |
RahulSitaram | 1:0ceb20b56f7f | 23 | pc.putc(read_data); |
RahulSitaram | 1:0ceb20b56f7f | 24 | } |
RahulSitaram | 1:0ceb20b56f7f | 25 | } |
RahulSitaram | 1:0ceb20b56f7f | 26 | Wifi.puts("\n"); |
RahulSitaram | 1:0ceb20b56f7f | 27 | pc.puts("\n"); |
akverma | 0:adb256c0dfa9 | 28 | } |
akverma | 0:adb256c0dfa9 | 29 | } |
RahulSitaram | 1:0ceb20b56f7f | 30 | void send_to_device(string command){ |
RahulSitaram | 1:0ceb20b56f7f | 31 | |
RahulSitaram | 1:0ceb20b56f7f | 32 | |
RahulSitaram | 1:0ceb20b56f7f | 33 | } |
akverma | 0:adb256c0dfa9 | 34 | |
akverma | 0:adb256c0dfa9 | 35 | int main() { |
akverma | 0:adb256c0dfa9 | 36 | led1 = 1; |
akverma | 0:adb256c0dfa9 | 37 | led2 = 1; |
akverma | 0:adb256c0dfa9 | 38 | uint8_t data[3] = {0x47, 0x32, 0xA7}; |
RahulSitaram | 1:0ceb20b56f7f | 39 | Wifi.puts("AT"); |
RahulSitaram | 1:0ceb20b56f7f | 40 | Wifi.puts("AT+RST"); |
RahulSitaram | 1:0ceb20b56f7f | 41 | wait(2); |
RahulSitaram | 1:0ceb20b56f7f | 42 | Wifi.puts("AT+CWMODE=3"); |
RahulSitaram | 1:0ceb20b56f7f | 43 | wait_ms(100); |
RahulSitaram | 1:0ceb20b56f7f | 44 | Wifi.puts("AT+CWJAP=\"Username\"+\"Password\""); |
RahulSitaram | 1:0ceb20b56f7f | 45 | Wifi.puts("AT+CIPMUX=1"); |
RahulSitaram | 1:0ceb20b56f7f | 46 | Thread thread(reader_thread); |
RahulSitaram | 1:0ceb20b56f7f | 47 | Wifi.puts("AT+CIPSTART=0,\"TCP\",\"localhost/peach/index.php?device_token=jabv5su2&device_id=gr_peach1&command4u=Sent_Something\",80"); |
RahulSitaram | 1:0ceb20b56f7f | 48 | Wifi.puts("AT+CIPSEND=0,30"); |
RahulSitaram | 1:0ceb20b56f7f | 49 | Wifi.puts("GET localhost/peach/index.php?device_token=jabv5su2&device_id=gr_peach1&command4u=Sent_Something HTTP/1.1" ); |
akverma | 0:adb256c0dfa9 | 50 | while (true) { |
akverma | 0:adb256c0dfa9 | 51 | led1 = !led1; |
akverma | 0:adb256c0dfa9 | 52 | Thread::wait(500); |
akverma | 0:adb256c0dfa9 | 53 | } |
akverma | 0:adb256c0dfa9 | 54 | } |