Wifi IoT Project

Dependencies:   4DGL-uLCD-SE mbed

Committer:
yscho529
Date:
Tue Nov 01 19:51:07 2016 +0000
Revision:
0:6e8326358c6c
Wifi IoT

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yscho529 0:6e8326358c6c 1 // ESP8266 Static page WEB server to control Mbed
yscho529 0:6e8326358c6c 2
yscho529 0:6e8326358c6c 3 #include "mbed.h"
yscho529 0:6e8326358c6c 4 #include "song.h"
yscho529 0:6e8326358c6c 5
yscho529 0:6e8326358c6c 6 Serial pc(USBTX, USBRX);
yscho529 0:6e8326358c6c 7 Serial esp(p28, p27); // tx, rx
yscho529 0:6e8326358c6c 8
yscho529 0:6e8326358c6c 9
yscho529 0:6e8326358c6c 10 // Standard Mbed LED definitions
yscho529 0:6e8326358c6c 11 DigitalOut led1(LED1);
yscho529 0:6e8326358c6c 12 DigitalOut led2(LED2);
yscho529 0:6e8326358c6c 13 DigitalOut led3(LED3);
yscho529 0:6e8326358c6c 14 DigitalOut led4(LED4);
yscho529 0:6e8326358c6c 15
yscho529 0:6e8326358c6c 16 char ssid[32] = "Mia"; // enter WiFi router ssid inside the quotes
yscho529 0:6e8326358c6c 17 char pwd [32] = "myhotspot"; // enter WiFi router password inside the quotes
yscho529 0:6e8326358c6c 18
yscho529 0:6e8326358c6c 19 float temperature, AdcIn, Ht;
yscho529 0:6e8326358c6c 20 float R1=100000, R2=10000; // resistor values to give a 10:1 reduction of measured AnalogIn voltage
yscho529 0:6e8326358c6c 21 char Vcc[10];
yscho529 0:6e8326358c6c 22 char Temp[10];
yscho529 0:6e8326358c6c 23
yscho529 0:6e8326358c6c 24 // things for sending/receiving data over serial
yscho529 0:6e8326358c6c 25 volatile int tx_in=0;
yscho529 0:6e8326358c6c 26 volatile int tx_out=0;
yscho529 0:6e8326358c6c 27 volatile int rx_in=0;
yscho529 0:6e8326358c6c 28 volatile int rx_out=0;
yscho529 0:6e8326358c6c 29 const int buffer_size = 4095;
yscho529 0:6e8326358c6c 30 char tx_buffer[buffer_size+1];
yscho529 0:6e8326358c6c 31 char rx_buffer[buffer_size+1];
yscho529 0:6e8326358c6c 32 void Tx_interrupt();
yscho529 0:6e8326358c6c 33 void Rx_interrupt();
yscho529 0:6e8326358c6c 34 void send_line();
yscho529 0:6e8326358c6c 35 void read_line();
yscho529 0:6e8326358c6c 36
yscho529 0:6e8326358c6c 37 int DataRX;
yscho529 0:6e8326358c6c 38 int update;
yscho529 0:6e8326358c6c 39 int count;
yscho529 0:6e8326358c6c 40 char cmdbuff[1024];
yscho529 0:6e8326358c6c 41 char replybuff[4096];
yscho529 0:6e8326358c6c 42 char webdata[4096]; // This may need to be bigger depending on WEB browser used
yscho529 0:6e8326358c6c 43 char webbuff[4096]; // Currently using 1986 characters, Increase this if more web page data added
yscho529 0:6e8326358c6c 44 char timebuf[30];
yscho529 0:6e8326358c6c 45 void SendCMD(),getreply(),ReadWebData(),startserver();
yscho529 0:6e8326358c6c 46 char rx_line[1024];
yscho529 0:6e8326358c6c 47 int port =80; // set server port
yscho529 0:6e8326358c6c 48 int SERVtimeout =5; // set server timeout in seconds in case link breaks.
yscho529 0:6e8326358c6c 49 struct tm t;
yscho529 0:6e8326358c6c 50 // manual set RTC values
yscho529 0:6e8326358c6c 51 int minute =00; // 0-59
yscho529 0:6e8326358c6c 52 int hour =12; // 2-23
yscho529 0:6e8326358c6c 53 int dayofmonth =26; // 1-31
yscho529 0:6e8326358c6c 54 int month =8; // 1-12
yscho529 0:6e8326358c6c 55 int year =15; // last 2 digits
yscho529 0:6e8326358c6c 56
yscho529 0:6e8326358c6c 57 int main()
yscho529 0:6e8326358c6c 58 {
yscho529 0:6e8326358c6c 59 pc.baud(9600);
yscho529 0:6e8326358c6c 60 esp.baud(9600);
yscho529 0:6e8326358c6c 61 led1=1,led2=0,led3=0, led4=0;
yscho529 0:6e8326358c6c 62 // Setup a serial interrupt function to receive data
yscho529 0:6e8326358c6c 63 esp.attach(&Rx_interrupt, Serial::RxIrq);
yscho529 0:6e8326358c6c 64 // Setup a serial interrupt function to transmit data
yscho529 0:6e8326358c6c 65 esp.attach(&Tx_interrupt, Serial::TxIrq);
yscho529 0:6e8326358c6c 66 startserver();
yscho529 0:6e8326358c6c 67 DataRX=0;
yscho529 0:6e8326358c6c 68 count=0;
yscho529 0:6e8326358c6c 69 while(1) {
yscho529 0:6e8326358c6c 70 if(DataRX==1) {
yscho529 0:6e8326358c6c 71 ReadWebData();
yscho529 0:6e8326358c6c 72 esp.attach(&Rx_interrupt, Serial::RxIrq);
yscho529 0:6e8326358c6c 73 }
yscho529 0:6e8326358c6c 74 }
yscho529 0:6e8326358c6c 75 }
yscho529 0:6e8326358c6c 76
yscho529 0:6e8326358c6c 77 // Reads and processes GET and POST web data
yscho529 0:6e8326358c6c 78 void ReadWebData()
yscho529 0:6e8326358c6c 79 {
yscho529 0:6e8326358c6c 80 wait_ms(200);
yscho529 0:6e8326358c6c 81 esp.attach(NULL,Serial::RxIrq);
yscho529 0:6e8326358c6c 82 DataRX=0;
yscho529 0:6e8326358c6c 83 memset(webdata, '\0', sizeof(webdata));
yscho529 0:6e8326358c6c 84 strcpy(webdata, rx_buffer);
yscho529 0:6e8326358c6c 85 memset(rx_buffer, '\0', sizeof(rx_buffer));
yscho529 0:6e8326358c6c 86 rx_in = 0;
yscho529 0:6e8326358c6c 87 rx_out = 0;
yscho529 0:6e8326358c6c 88 // check web data for form information
yscho529 0:6e8326358c6c 89 if( strstr(webdata, "check=led1v") != NULL ) {
yscho529 0:6e8326358c6c 90 led1=!led1;
yscho529 0:6e8326358c6c 91 playsong1();
yscho529 0:6e8326358c6c 92 }
yscho529 0:6e8326358c6c 93 else if( strstr(webdata, "check=led2v") != NULL ) {
yscho529 0:6e8326358c6c 94 led2=!led2;
yscho529 0:6e8326358c6c 95 playsong2();
yscho529 0:6e8326358c6c 96 }
yscho529 0:6e8326358c6c 97 else if( strstr(webdata, "check=led3v") != NULL ) {
yscho529 0:6e8326358c6c 98 led3=!led3;
yscho529 0:6e8326358c6c 99 playsong3();
yscho529 0:6e8326358c6c 100 }
yscho529 0:6e8326358c6c 101 else if( strstr(webdata, "check=led4v") != NULL ) {
yscho529 0:6e8326358c6c 102 led4=!led4;
yscho529 0:6e8326358c6c 103 playsong4();
yscho529 0:6e8326358c6c 104 }
yscho529 0:6e8326358c6c 105 if( strstr(webdata, "POST") != NULL ) { // set update flag if POST request
yscho529 0:6e8326358c6c 106 update=1;
yscho529 0:6e8326358c6c 107 }
yscho529 0:6e8326358c6c 108 if( strstr(webdata, "GET") != NULL && strstr(webdata, "favicon") == NULL ) { // set update flag for GET request but do not want to update for favicon requests
yscho529 0:6e8326358c6c 109 update=1;
yscho529 0:6e8326358c6c 110 }
yscho529 0:6e8326358c6c 111 }
yscho529 0:6e8326358c6c 112 // Starts webserver
yscho529 0:6e8326358c6c 113 void startserver()
yscho529 0:6e8326358c6c 114 {
yscho529 0:6e8326358c6c 115 pc.printf("++++++++++ Resetting ESP ++++++++++\r\n");
yscho529 0:6e8326358c6c 116 strcpy(cmdbuff,"node.restart()\r\n");
yscho529 0:6e8326358c6c 117 SendCMD();
yscho529 0:6e8326358c6c 118 wait(2);
yscho529 0:6e8326358c6c 119 getreply();
yscho529 0:6e8326358c6c 120
yscho529 0:6e8326358c6c 121 pc.printf("\n++++++++++ Starting Server ++++++++++\r\n> ");
yscho529 0:6e8326358c6c 122
yscho529 0:6e8326358c6c 123 // initial values
yscho529 0:6e8326358c6c 124 sprintf(cmdbuff, "count,time,analog1,analog2=0,\"%s\",\"%s\",\"%s\"\r\n",timebuf,Temp,Vcc);
yscho529 0:6e8326358c6c 125 SendCMD();
yscho529 0:6e8326358c6c 126 getreply();
yscho529 0:6e8326358c6c 127 wait(0.5);
yscho529 0:6e8326358c6c 128
yscho529 0:6e8326358c6c 129 //create server
yscho529 0:6e8326358c6c 130 sprintf(cmdbuff, "srv=net.createServer(net.TCP,%d)\r\n",SERVtimeout);
yscho529 0:6e8326358c6c 131 SendCMD();
yscho529 0:6e8326358c6c 132 getreply();
yscho529 0:6e8326358c6c 133 wait(0.5);
yscho529 0:6e8326358c6c 134 strcpy(cmdbuff,"srv:listen(80,function(conn)\r\n");
yscho529 0:6e8326358c6c 135 SendCMD();
yscho529 0:6e8326358c6c 136 getreply();
yscho529 0:6e8326358c6c 137 wait(0.3);
yscho529 0:6e8326358c6c 138 strcpy(cmdbuff,"conn:on(\"receive\",function(conn,payload) \r\n");
yscho529 0:6e8326358c6c 139 SendCMD();
yscho529 0:6e8326358c6c 140 getreply();
yscho529 0:6e8326358c6c 141 wait(0.3);
yscho529 0:6e8326358c6c 142
yscho529 0:6e8326358c6c 143 //print data to mbed
yscho529 0:6e8326358c6c 144 strcpy(cmdbuff,"print(payload)\r\n");
yscho529 0:6e8326358c6c 145 SendCMD();
yscho529 0:6e8326358c6c 146 getreply();
yscho529 0:6e8326358c6c 147 wait(0.2);
yscho529 0:6e8326358c6c 148
yscho529 0:6e8326358c6c 149 //web page data
yscho529 0:6e8326358c6c 150 strcpy(cmdbuff,"conn:send('<!DOCTYPE html><html><body><h1>ECE 4180 Lab 4</h1>')\r\n");
yscho529 0:6e8326358c6c 151 SendCMD();
yscho529 0:6e8326358c6c 152 getreply();
yscho529 0:6e8326358c6c 153 wait(0.4);
yscho529 0:6e8326358c6c 154 strcpy(cmdbuff,"conn:send('<form method=\"POST\"')\r\n");
yscho529 0:6e8326358c6c 155 SendCMD();
yscho529 0:6e8326358c6c 156 getreply();
yscho529 0:6e8326358c6c 157 wait(0.3);
yscho529 0:6e8326358c6c 158 strcpy(cmdbuff, "conn:send('<p><input type=\"checkbox\" name=\"check\" value=\"led1v\"> Play Rambling Wreck')\r\n");
yscho529 0:6e8326358c6c 159 SendCMD();
yscho529 0:6e8326358c6c 160 getreply();
yscho529 0:6e8326358c6c 161 wait(0.3);
yscho529 0:6e8326358c6c 162 strcpy(cmdbuff, "conn:send('<p><input type=\"checkbox\" name=\"check\" value=\"led2v\"> Play Mary had a little lamb')\r\n");
yscho529 0:6e8326358c6c 163 SendCMD();
yscho529 0:6e8326358c6c 164 getreply();
yscho529 0:6e8326358c6c 165 wait(0.3);
yscho529 0:6e8326358c6c 166 strcpy(cmdbuff, "conn:send('<p><input type=\"checkbox\" name=\"check\" value=\"led3v\"> Play Bingo')\r\n");
yscho529 0:6e8326358c6c 167 SendCMD();
yscho529 0:6e8326358c6c 168 getreply();
yscho529 0:6e8326358c6c 169 wait(0.3);
yscho529 0:6e8326358c6c 170 strcpy(cmdbuff, "conn:send('<p><input type=\"checkbox\" name=\"check\" value=\"led4v\"> Play Are you sleeping?')\r\n");
yscho529 0:6e8326358c6c 171 SendCMD();
yscho529 0:6e8326358c6c 172 getreply();
yscho529 0:6e8326358c6c 173 wait(0.3);
yscho529 0:6e8326358c6c 174 strcpy(cmdbuff,"conn:send('<p><input type=\"submit\" value=\"Play\"></form>')\r\n");
yscho529 0:6e8326358c6c 175 SendCMD();
yscho529 0:6e8326358c6c 176 getreply();
yscho529 0:6e8326358c6c 177 wait(0.3);
yscho529 0:6e8326358c6c 178 strcpy(cmdbuff, "conn:send('<p><h2>How to use:</h2><ul><li>Select a checkbox to choose song</li><li>Click Play to play songs</li></ul></body></html>')\r\n");
yscho529 0:6e8326358c6c 179 SendCMD();
yscho529 0:6e8326358c6c 180 getreply();
yscho529 0:6e8326358c6c 181 wait(0.5);
yscho529 0:6e8326358c6c 182 // end web page data
yscho529 0:6e8326358c6c 183 strcpy(cmdbuff, "conn:on(\"sent\",function(conn) conn:close() end)\r\n"); // close current connection
yscho529 0:6e8326358c6c 184 SendCMD();
yscho529 0:6e8326358c6c 185 getreply();
yscho529 0:6e8326358c6c 186 wait(0.3);
yscho529 0:6e8326358c6c 187 strcpy(cmdbuff, "end)\r\n");
yscho529 0:6e8326358c6c 188 SendCMD();
yscho529 0:6e8326358c6c 189 getreply();
yscho529 0:6e8326358c6c 190 wait(0.2);
yscho529 0:6e8326358c6c 191 strcpy(cmdbuff, "end)\r\n");
yscho529 0:6e8326358c6c 192 SendCMD();
yscho529 0:6e8326358c6c 193 getreply();
yscho529 0:6e8326358c6c 194 wait(0.2);
yscho529 0:6e8326358c6c 195
yscho529 0:6e8326358c6c 196 strcpy(cmdbuff, "tmr.alarm(0, 1000, 1, function()\r\n");
yscho529 0:6e8326358c6c 197 SendCMD();
yscho529 0:6e8326358c6c 198 getreply();
yscho529 0:6e8326358c6c 199 wait(0.2);
yscho529 0:6e8326358c6c 200 strcpy(cmdbuff, "if wifi.sta.getip() == nil then\r\n");
yscho529 0:6e8326358c6c 201 SendCMD();
yscho529 0:6e8326358c6c 202 getreply();
yscho529 0:6e8326358c6c 203 wait(0.2);
yscho529 0:6e8326358c6c 204 strcpy(cmdbuff, "print(\"Connecting to AP...\\n\")\r\n");
yscho529 0:6e8326358c6c 205 SendCMD();
yscho529 0:6e8326358c6c 206 getreply();
yscho529 0:6e8326358c6c 207 wait(0.2);
yscho529 0:6e8326358c6c 208 strcpy(cmdbuff, "else\r\n");
yscho529 0:6e8326358c6c 209 SendCMD();
yscho529 0:6e8326358c6c 210 getreply();
yscho529 0:6e8326358c6c 211 wait(0.2);
yscho529 0:6e8326358c6c 212 strcpy(cmdbuff, "ip, nm, gw=wifi.sta.getip()\r\n");
yscho529 0:6e8326358c6c 213 SendCMD();
yscho529 0:6e8326358c6c 214 getreply();
yscho529 0:6e8326358c6c 215 wait(0.2);
yscho529 0:6e8326358c6c 216 strcpy(cmdbuff,"print(\"IP Address: \",ip)\r\n");
yscho529 0:6e8326358c6c 217 SendCMD();
yscho529 0:6e8326358c6c 218 getreply();
yscho529 0:6e8326358c6c 219 wait(0.2);
yscho529 0:6e8326358c6c 220 strcpy(cmdbuff,"tmr.stop(0)\r\n");
yscho529 0:6e8326358c6c 221 SendCMD();
yscho529 0:6e8326358c6c 222 getreply();
yscho529 0:6e8326358c6c 223 wait(0.2);
yscho529 0:6e8326358c6c 224 strcpy(cmdbuff,"end\r\n");
yscho529 0:6e8326358c6c 225 SendCMD();
yscho529 0:6e8326358c6c 226 getreply();
yscho529 0:6e8326358c6c 227 wait(0.2);
yscho529 0:6e8326358c6c 228 strcpy(cmdbuff,"end)\r\n");
yscho529 0:6e8326358c6c 229 SendCMD();
yscho529 0:6e8326358c6c 230 getreply();
yscho529 0:6e8326358c6c 231 wait(0.2);
yscho529 0:6e8326358c6c 232
yscho529 0:6e8326358c6c 233 pc.printf("\n\n++++++++++ Ready ++++++++++\r\n\n");
yscho529 0:6e8326358c6c 234 }
yscho529 0:6e8326358c6c 235
yscho529 0:6e8326358c6c 236
yscho529 0:6e8326358c6c 237 // ESP Command data send
yscho529 0:6e8326358c6c 238 void SendCMD()
yscho529 0:6e8326358c6c 239 {
yscho529 0:6e8326358c6c 240 int i;
yscho529 0:6e8326358c6c 241 char temp_char;
yscho529 0:6e8326358c6c 242 bool empty;
yscho529 0:6e8326358c6c 243 i = 0;
yscho529 0:6e8326358c6c 244 // Start Critical Section - don't interrupt while changing global buffer variables
yscho529 0:6e8326358c6c 245 NVIC_DisableIRQ(UART1_IRQn);
yscho529 0:6e8326358c6c 246 empty = (tx_in == tx_out);
yscho529 0:6e8326358c6c 247 while ((i==0) || (cmdbuff[i-1] != '\n')) {
yscho529 0:6e8326358c6c 248 // Wait if buffer full
yscho529 0:6e8326358c6c 249 if (((tx_in + 1) % buffer_size) == tx_out) {
yscho529 0:6e8326358c6c 250 // End Critical Section - need to let interrupt routine empty buffer by sending
yscho529 0:6e8326358c6c 251 NVIC_EnableIRQ(UART1_IRQn);
yscho529 0:6e8326358c6c 252 while (((tx_in + 1) % buffer_size) == tx_out) {
yscho529 0:6e8326358c6c 253 }
yscho529 0:6e8326358c6c 254 // Start Critical Section - don't interrupt while changing global buffer variables
yscho529 0:6e8326358c6c 255 NVIC_DisableIRQ(UART1_IRQn);
yscho529 0:6e8326358c6c 256 }
yscho529 0:6e8326358c6c 257 tx_buffer[tx_in] = cmdbuff[i];
yscho529 0:6e8326358c6c 258 i++;
yscho529 0:6e8326358c6c 259 tx_in = (tx_in + 1) % buffer_size;
yscho529 0:6e8326358c6c 260 }
yscho529 0:6e8326358c6c 261 if (esp.writeable() && (empty)) {
yscho529 0:6e8326358c6c 262 temp_char = tx_buffer[tx_out];
yscho529 0:6e8326358c6c 263 tx_out = (tx_out + 1) % buffer_size;
yscho529 0:6e8326358c6c 264 // Send first character to start tx interrupts, if stopped
yscho529 0:6e8326358c6c 265 esp.putc(temp_char);
yscho529 0:6e8326358c6c 266 }
yscho529 0:6e8326358c6c 267 // End Critical Section
yscho529 0:6e8326358c6c 268 NVIC_EnableIRQ(UART1_IRQn);
yscho529 0:6e8326358c6c 269 return;
yscho529 0:6e8326358c6c 270 }
yscho529 0:6e8326358c6c 271
yscho529 0:6e8326358c6c 272 // Get Command and ESP status replies
yscho529 0:6e8326358c6c 273 void getreply()
yscho529 0:6e8326358c6c 274 {
yscho529 0:6e8326358c6c 275 read_line();
yscho529 0:6e8326358c6c 276 sscanf(rx_line,replybuff);
yscho529 0:6e8326358c6c 277 }
yscho529 0:6e8326358c6c 278
yscho529 0:6e8326358c6c 279 // Read a line from the large rx buffer from rx interrupt routine
yscho529 0:6e8326358c6c 280 void read_line() {
yscho529 0:6e8326358c6c 281 int i;
yscho529 0:6e8326358c6c 282 i = 0;
yscho529 0:6e8326358c6c 283 // Start Critical Section - don't interrupt while changing global buffer variables
yscho529 0:6e8326358c6c 284 NVIC_DisableIRQ(UART1_IRQn);
yscho529 0:6e8326358c6c 285 // Loop reading rx buffer characters until end of line character
yscho529 0:6e8326358c6c 286 while ((i==0) || (rx_line[i-1] != '\r')) {
yscho529 0:6e8326358c6c 287 // Wait if buffer empty
yscho529 0:6e8326358c6c 288 if (rx_in == rx_out) {
yscho529 0:6e8326358c6c 289 // End Critical Section - need to allow rx interrupt to get new characters for buffer
yscho529 0:6e8326358c6c 290 NVIC_EnableIRQ(UART1_IRQn);
yscho529 0:6e8326358c6c 291 while (rx_in == rx_out) {
yscho529 0:6e8326358c6c 292 }
yscho529 0:6e8326358c6c 293 // Start Critical Section - don't interrupt while changing global buffer variables
yscho529 0:6e8326358c6c 294 NVIC_DisableIRQ(UART1_IRQn);
yscho529 0:6e8326358c6c 295 }
yscho529 0:6e8326358c6c 296 rx_line[i] = rx_buffer[rx_out];
yscho529 0:6e8326358c6c 297 i++;
yscho529 0:6e8326358c6c 298 rx_out = (rx_out + 1) % buffer_size;
yscho529 0:6e8326358c6c 299 }
yscho529 0:6e8326358c6c 300 // End Critical Section
yscho529 0:6e8326358c6c 301 NVIC_EnableIRQ(UART1_IRQn);
yscho529 0:6e8326358c6c 302 rx_line[i-1] = 0;
yscho529 0:6e8326358c6c 303 return;
yscho529 0:6e8326358c6c 304 }
yscho529 0:6e8326358c6c 305
yscho529 0:6e8326358c6c 306 // Interupt Routine to read in data from serial port
yscho529 0:6e8326358c6c 307 void Rx_interrupt() {
yscho529 0:6e8326358c6c 308 DataRX=1;
yscho529 0:6e8326358c6c 309 //led3=1;
yscho529 0:6e8326358c6c 310 // Loop just in case more than one character is in UART's receive FIFO buffer
yscho529 0:6e8326358c6c 311 // Stop if buffer full
yscho529 0:6e8326358c6c 312 while ((esp.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) {
yscho529 0:6e8326358c6c 313 rx_buffer[rx_in] = esp.getc();
yscho529 0:6e8326358c6c 314 // Uncomment to Echo to USB serial to watch data flow
yscho529 0:6e8326358c6c 315 pc.putc(rx_buffer[rx_in]);
yscho529 0:6e8326358c6c 316 rx_in = (rx_in + 1) % buffer_size;
yscho529 0:6e8326358c6c 317 }
yscho529 0:6e8326358c6c 318 //led3=0;
yscho529 0:6e8326358c6c 319 return;
yscho529 0:6e8326358c6c 320 }
yscho529 0:6e8326358c6c 321
yscho529 0:6e8326358c6c 322 // Interupt Routine to write out data to serial port
yscho529 0:6e8326358c6c 323 void Tx_interrupt() {
yscho529 0:6e8326358c6c 324 //led2=1;
yscho529 0:6e8326358c6c 325 // Loop to fill more than one character in UART's transmit FIFO buffer
yscho529 0:6e8326358c6c 326 // Stop if buffer empty
yscho529 0:6e8326358c6c 327 while ((esp.writeable()) && (tx_in != tx_out)) {
yscho529 0:6e8326358c6c 328 esp.putc(tx_buffer[tx_out]);
yscho529 0:6e8326358c6c 329 tx_out = (tx_out + 1) % buffer_size;
yscho529 0:6e8326358c6c 330 }
yscho529 0:6e8326358c6c 331 //led2=0;
yscho529 0:6e8326358c6c 332 return;
yscho529 0:6e8326358c6c 333 }