![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Increments the value by 1
Fork of test_thread_reneproj by
main.cpp@6:850122a18e82, 2017-02-05 (annotated)
- Committer:
- RahulSitaram
- Date:
- Sun Feb 05 15:22:28 2017 +0000
- Revision:
- 6:850122a18e82
- Parent:
- 5:bdabacd90f75
This increments the sent values by 1
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> |
RahulSitaram | 6:850122a18e82 | 4 | #include <iostream> |
akverma | 0:adb256c0dfa9 | 5 | |
akverma | 0:adb256c0dfa9 | 6 | DigitalOut led1(LED1); |
akverma | 0:adb256c0dfa9 | 7 | DigitalOut led2(LED2); |
RahulSitaram | 1:0ceb20b56f7f | 8 | std::string data; |
RahulSitaram | 4:fd0d5e707091 | 9 | string command; |
RahulSitaram | 4:fd0d5e707091 | 10 | uint8_t wifi_ack; |
RahulSitaram | 1:0ceb20b56f7f | 11 | char read_data; |
RahulSitaram | 1:0ceb20b56f7f | 12 | Serial pc(USBTX, USBRX); |
RahulSitaram | 1:0ceb20b56f7f | 13 | //Serial Wifi(P2_14,P2_15); |
RahulSitaram | 1:0ceb20b56f7f | 14 | Serial Wifi(P5_0, P5_1); |
RahulSitaram | 1:0ceb20b56f7f | 15 | bool i = true; |
RahulSitaram | 1:0ceb20b56f7f | 16 | bool j = false; |
RahulSitaram | 6:850122a18e82 | 17 | int k = 1; |
RahulSitaram | 1:0ceb20b56f7f | 18 | char MSB; |
RahulSitaram | 1:0ceb20b56f7f | 19 | char LSB; |
akverma | 0:adb256c0dfa9 | 20 | |
RahulSitaram | 1:0ceb20b56f7f | 21 | void reader_thread(void const *args) { |
RahulSitaram | 1:0ceb20b56f7f | 22 | while (true) { |
RahulSitaram | 4:fd0d5e707091 | 23 | Wifi.printf("GET reneproj.esy.es/"); |
RahulSitaram | 4:fd0d5e707091 | 24 | Wifi.printf("peach/index.php?device_token=jabv5su2&device"); |
RahulSitaram | 4:fd0d5e707091 | 25 | Wifi.printf("_id=gr_peach1&command4u=00 HTTP/1.1\r\n"); |
RahulSitaram | 5:bdabacd90f75 | 26 | } |
RahulSitaram | 5:bdabacd90f75 | 27 | } |
RahulSitaram | 5:bdabacd90f75 | 28 | void read_from_wifi(){ |
RahulSitaram | 5:bdabacd90f75 | 29 | if(Wifi.readable()){ |
RahulSitaram | 1:0ceb20b56f7f | 30 | while(Wifi.readable()){ |
RahulSitaram | 1:0ceb20b56f7f | 31 | read_data = Wifi.getc(); |
RahulSitaram | 1:0ceb20b56f7f | 32 | pc.putc(read_data); |
RahulSitaram | 1:0ceb20b56f7f | 33 | } |
RahulSitaram | 1:0ceb20b56f7f | 34 | } |
RahulSitaram | 1:0ceb20b56f7f | 35 | |
RahulSitaram | 1:0ceb20b56f7f | 36 | } |
RahulSitaram | 2:52ecf89221d3 | 37 | void setup_esp8266(){ |
RahulSitaram | 2:52ecf89221d3 | 38 | Wifi.baud(9600); |
RahulSitaram | 2:52ecf89221d3 | 39 | pc.baud(9600); |
RahulSitaram | 2:52ecf89221d3 | 40 | Wifi.puts("AT\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 41 | wait(8); |
RahulSitaram | 2:52ecf89221d3 | 42 | Wifi.puts("AT+RST\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 43 | wait(8); |
RahulSitaram | 2:52ecf89221d3 | 44 | Wifi.puts("AT+CWMODE=3\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 45 | wait(8); |
RahulSitaram | 2:52ecf89221d3 | 46 | Wifi.puts("AT+CWJAP=\"Googol\",\"sudopass\"\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 47 | wait(8); |
RahulSitaram | 2:52ecf89221d3 | 48 | Wifi.puts("AT+CIPMUX=1\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 49 | wait(8); |
RahulSitaram | 2:52ecf89221d3 | 50 | Wifi.printf("AT+CIPSTART=0,\"TCP\",\"reneproj.esy.es\""); |
RahulSitaram | 2:52ecf89221d3 | 51 | wait(4); |
RahulSitaram | 2:52ecf89221d3 | 52 | Wifi.printf(",80\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 53 | wait(8); |
RahulSitaram | 2:52ecf89221d3 | 54 | Wifi.puts("AT+CIPSEND=0,30\r\n"); |
RahulSitaram | 2:52ecf89221d3 | 55 | wait(8); |
RahulSitaram | 4:fd0d5e707091 | 56 | Thread thread(reader_thread); |
RahulSitaram | 2:52ecf89221d3 | 57 | } |
RahulSitaram | 6:850122a18e82 | 58 | void send_command(){ |
RahulSitaram | 6:850122a18e82 | 59 | pc.printf("sending command"); |
RahulSitaram | 6:850122a18e82 | 60 | Wifi.printf("AT+RST\r"); |
RahulSitaram | 6:850122a18e82 | 61 | Wifi.printf("\n"); |
RahulSitaram | 6:850122a18e82 | 62 | Wifi.printf("\r"); |
RahulSitaram | 6:850122a18e82 | 63 | Wifi.printf("\n"); |
RahulSitaram | 6:850122a18e82 | 64 | wait_ms(7000); |
RahulSitaram | 6:850122a18e82 | 65 | Wifi.printf("AT+CIPSTART=\"TCP\",\"184.106.153.149\",80\r"); |
RahulSitaram | 6:850122a18e82 | 66 | Wifi.printf("\n"); |
RahulSitaram | 6:850122a18e82 | 67 | wait_ms(7000); |
RahulSitaram | 6:850122a18e82 | 68 | Wifi.printf("AT+CIPSEND=51\r"); |
RahulSitaram | 6:850122a18e82 | 69 | Wifi.printf("\n"); |
RahulSitaram | 6:850122a18e82 | 70 | wait_ms(2000); |
RahulSitaram | 6:850122a18e82 | 71 | Wifi.printf("GET /update?api_key=ECSZCMRZJF1ZQDNY&field1="); |
RahulSitaram | 6:850122a18e82 | 72 | Wifi.printf("%d",k); |
RahulSitaram | 6:850122a18e82 | 73 | Wifi.printf("\n"); |
RahulSitaram | 6:850122a18e82 | 74 | Wifi.printf("\n"); |
RahulSitaram | 6:850122a18e82 | 75 | Wifi.printf("\n"); |
RahulSitaram | 6:850122a18e82 | 76 | Wifi.printf("\n"); |
RahulSitaram | 6:850122a18e82 | 77 | Wifi.printf("\n"); |
RahulSitaram | 6:850122a18e82 | 78 | Wifi.printf("\r"); |
RahulSitaram | 6:850122a18e82 | 79 | wait_ms(7000); |
RahulSitaram | 6:850122a18e82 | 80 | k++; |
RahulSitaram | 4:fd0d5e707091 | 81 | |
RahulSitaram | 4:fd0d5e707091 | 82 | } |
akverma | 0:adb256c0dfa9 | 83 | |
akverma | 0:adb256c0dfa9 | 84 | int main() { |
RahulSitaram | 5:bdabacd90f75 | 85 | Wifi.attach(&read_from_wifi); |
RahulSitaram | 6:850122a18e82 | 86 | // setup_esp8266(); |
akverma | 0:adb256c0dfa9 | 87 | while (true) { |
RahulSitaram | 6:850122a18e82 | 88 | send_command(); |
RahulSitaram | 6:850122a18e82 | 89 | wait_ms(7000); |
akverma | 0:adb256c0dfa9 | 90 | } |
akverma | 0:adb256c0dfa9 | 91 | } |