GR_Peach_Abhinav_Rahul
/
test_thread_reneproj
Exclusive code for server communication
Fork of test_thread by
main.cpp@5:bdabacd90f75, 2017-01-14 (annotated)
- Committer:
- RahulSitaram
- Date:
- Sat Jan 14 06:42:58 2017 +0000
- Revision:
- 5:bdabacd90f75
- Parent:
- 4:fd0d5e707091
Committed on 14-01-2017 12:10 PM
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 | 4:fd0d5e707091 | 8 | string command; |
RahulSitaram | 4:fd0d5e707091 | 9 | uint8_t wifi_ack; |
RahulSitaram | 1:0ceb20b56f7f | 10 | char read_data; |
RahulSitaram | 1:0ceb20b56f7f | 11 | Serial pc(USBTX, USBRX); |
RahulSitaram | 1:0ceb20b56f7f | 12 | //Serial Wifi(P2_14,P2_15); |
RahulSitaram | 1:0ceb20b56f7f | 13 | Serial Wifi(P5_0, P5_1); |
RahulSitaram | 1:0ceb20b56f7f | 14 | bool i = true; |
RahulSitaram | 1:0ceb20b56f7f | 15 | bool j = false; |
RahulSitaram | 1:0ceb20b56f7f | 16 | char MSB; |
RahulSitaram | 1:0ceb20b56f7f | 17 | char LSB; |
akverma | 0:adb256c0dfa9 | 18 | |
RahulSitaram | 1:0ceb20b56f7f | 19 | void reader_thread(void const *args) { |
RahulSitaram | 1:0ceb20b56f7f | 20 | while (true) { |
RahulSitaram | 4:fd0d5e707091 | 21 | Wifi.printf("GET reneproj.esy.es/"); |
RahulSitaram | 4:fd0d5e707091 | 22 | Wifi.printf("peach/index.php?device_token=jabv5su2&device"); |
RahulSitaram | 4:fd0d5e707091 | 23 | Wifi.printf("_id=gr_peach1&command4u=00 HTTP/1.1\r\n"); |
RahulSitaram | 5:bdabacd90f75 | 24 | } |
RahulSitaram | 5:bdabacd90f75 | 25 | } |
RahulSitaram | 5:bdabacd90f75 | 26 | void read_from_wifi(){ |
RahulSitaram | 5:bdabacd90f75 | 27 | if(Wifi.readable()){ |
RahulSitaram | 1:0ceb20b56f7f | 28 | while(Wifi.readable()){ |
RahulSitaram | 1:0ceb20b56f7f | 29 | read_data = Wifi.getc(); |
RahulSitaram | 1:0ceb20b56f7f | 30 | pc.putc(read_data); |
RahulSitaram | 1:0ceb20b56f7f | 31 | } |
RahulSitaram | 1:0ceb20b56f7f | 32 | } |
RahulSitaram | 1:0ceb20b56f7f | 33 | |
RahulSitaram | 1:0ceb20b56f7f | 34 | } |
RahulSitaram | 2:52ecf89221d3 | 35 | void setup_esp8266(){ |
RahulSitaram | 2:52ecf89221d3 | 36 | Wifi.baud(9600); |
RahulSitaram | 2:52ecf89221d3 | 37 | pc.baud(9600); |
RahulSitaram | 2:52ecf89221d3 | 38 | Wifi.puts("AT\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 39 | wait(8); |
RahulSitaram | 2:52ecf89221d3 | 40 | Wifi.puts("AT+RST\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 41 | wait(8); |
RahulSitaram | 2:52ecf89221d3 | 42 | Wifi.puts("AT+CWMODE=3\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 43 | wait(8); |
RahulSitaram | 2:52ecf89221d3 | 44 | Wifi.puts("AT+CWJAP=\"Googol\",\"sudopass\"\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 45 | wait(8); |
RahulSitaram | 2:52ecf89221d3 | 46 | Wifi.puts("AT+CIPMUX=1\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 47 | wait(8); |
RahulSitaram | 2:52ecf89221d3 | 48 | Wifi.printf("AT+CIPSTART=0,\"TCP\",\"reneproj.esy.es\""); |
RahulSitaram | 2:52ecf89221d3 | 49 | wait(4); |
RahulSitaram | 2:52ecf89221d3 | 50 | Wifi.printf(",80\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 51 | wait(8); |
RahulSitaram | 2:52ecf89221d3 | 52 | Wifi.puts("AT+CIPSEND=0,30\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 53 | wait(8); |
RahulSitaram | 4:fd0d5e707091 | 54 | Thread thread(reader_thread); |
RahulSitaram | 2:52ecf89221d3 | 55 | } |
RahulSitaram | 4:fd0d5e707091 | 56 | void send_command(char* eight_byte_cmd){ |
RahulSitaram | 4:fd0d5e707091 | 57 | Wifi.puts("AT+CIPSTART=0,\"TCP\",\"localhost/peach/index.php?device_"); |
RahulSitaram | 4:fd0d5e707091 | 58 | Wifi.puts("token=jabv5su2&device_id=gr_peach1&command4u="); |
RahulSitaram | 4:fd0d5e707091 | 59 | Wifi.puts(eight_byte_cmd); |
RahulSitaram | 4:fd0d5e707091 | 60 | Wifi.puts("\",80\r\n"); |
RahulSitaram | 4:fd0d5e707091 | 61 | |
RahulSitaram | 4:fd0d5e707091 | 62 | } |
akverma | 0:adb256c0dfa9 | 63 | |
akverma | 0:adb256c0dfa9 | 64 | int main() { |
RahulSitaram | 5:bdabacd90f75 | 65 | Wifi.attach(&read_from_wifi); |
RahulSitaram | 2:52ecf89221d3 | 66 | setup_esp8266(); |
akverma | 0:adb256c0dfa9 | 67 | while (true) { |
RahulSitaram | 2:52ecf89221d3 | 68 | wait(10); |
akverma | 0:adb256c0dfa9 | 69 | } |
akverma | 0:adb256c0dfa9 | 70 | } |