![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Use the touchpad to enter a passcode, which is either confirmed or rejected, and is displayed on a webpage.
Fork of huzzah_helloWorld by
main.cpp@2:ae7610f4867a, 2016-03-16 (annotated)
- Committer:
- coleandbrandon
- Date:
- Wed Mar 16 14:20:11 2016 +0000
- Revision:
- 2:ae7610f4867a
- Parent:
- 1:fe195c33f794
Final commit with general code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhunter029 | 0:57cec3469a80 | 1 | #include "mbed.h" |
coleandbrandon | 1:fe195c33f794 | 2 | #include <string> |
coleandbrandon | 1:fe195c33f794 | 3 | #include <list> |
coleandbrandon | 1:fe195c33f794 | 4 | |
coleandbrandon | 1:fe195c33f794 | 5 | #include <mpr121.h> |
jhunter029 | 0:57cec3469a80 | 6 | |
jhunter029 | 0:57cec3469a80 | 7 | Serial pc(USBTX, USBRX); |
jhunter029 | 0:57cec3469a80 | 8 | Serial esp(p28, p27); // tx, rx |
coleandbrandon | 1:fe195c33f794 | 9 | Timer t; |
coleandbrandon | 1:fe195c33f794 | 10 | Timer t1; |
coleandbrandon | 1:fe195c33f794 | 11 | Timer t2; |
jhunter029 | 0:57cec3469a80 | 12 | DigitalOut led1(LED1); |
coleandbrandon | 1:fe195c33f794 | 13 | DigitalOut led2(LED2); |
coleandbrandon | 1:fe195c33f794 | 14 | DigitalOut led3(LED3); |
jhunter029 | 0:57cec3469a80 | 15 | DigitalOut led4(LED4); |
coleandbrandon | 1:fe195c33f794 | 16 | |
coleandbrandon | 1:fe195c33f794 | 17 | // Create the interrupt receiver object on pin 26 |
coleandbrandon | 1:fe195c33f794 | 18 | InterruptIn interrupt(p26); |
coleandbrandon | 1:fe195c33f794 | 19 | |
coleandbrandon | 1:fe195c33f794 | 20 | // Setup the i2c bus on pins 28 and 27 |
coleandbrandon | 1:fe195c33f794 | 21 | I2C i2c(p9, p10); |
coleandbrandon | 1:fe195c33f794 | 22 | |
coleandbrandon | 1:fe195c33f794 | 23 | // Setup the Mpr121: |
coleandbrandon | 1:fe195c33f794 | 24 | // constructor(i2c object, i2c address of the mpr121) |
coleandbrandon | 1:fe195c33f794 | 25 | Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); |
jhunter029 | 0:57cec3469a80 | 26 | |
jhunter029 | 0:57cec3469a80 | 27 | int count,ended,timeout; |
jhunter029 | 0:57cec3469a80 | 28 | char buf[2024]; |
jhunter029 | 0:57cec3469a80 | 29 | char snd[1024]; |
jhunter029 | 0:57cec3469a80 | 30 | |
coleandbrandon | 2:ae7610f4867a | 31 | char ssid[32] = "SSID"; // enter WiFi router ssid inside the quotes |
coleandbrandon | 2:ae7610f4867a | 32 | char pwd [32] = "PASSWORD"; // enter WiFi router password inside the quotes |
coleandbrandon | 1:fe195c33f794 | 33 | |
coleandbrandon | 2:ae7610f4867a | 34 | int hold0,hold1,hold2,hold3 = 0; //signal variables for correct password |
coleandbrandon | 2:ae7610f4867a | 35 | int signal = 0; //signal for correct sequence |
jhunter029 | 0:57cec3469a80 | 36 | |
jhunter029 | 0:57cec3469a80 | 37 | void SendCMD(),getreply(),ESPconfig(),ESPsetbaudrate(); |
jhunter029 | 0:57cec3469a80 | 38 | void dev_recv() |
jhunter029 | 0:57cec3469a80 | 39 | { |
jhunter029 | 0:57cec3469a80 | 40 | led1 = !led1; |
jhunter029 | 0:57cec3469a80 | 41 | while(esp.readable()) { |
jhunter029 | 0:57cec3469a80 | 42 | pc.putc(esp.getc()); |
jhunter029 | 0:57cec3469a80 | 43 | } |
jhunter029 | 0:57cec3469a80 | 44 | } |
jhunter029 | 0:57cec3469a80 | 45 | |
jhunter029 | 0:57cec3469a80 | 46 | void pc_recv() |
jhunter029 | 0:57cec3469a80 | 47 | { |
jhunter029 | 0:57cec3469a80 | 48 | led4 = !led4; |
jhunter029 | 0:57cec3469a80 | 49 | while(pc.readable()) { |
jhunter029 | 0:57cec3469a80 | 50 | esp.putc(pc.getc()); |
jhunter029 | 0:57cec3469a80 | 51 | } |
jhunter029 | 0:57cec3469a80 | 52 | } |
coleandbrandon | 1:fe195c33f794 | 53 | |
coleandbrandon | 2:ae7610f4867a | 54 | void fallInterrupt() { //code = 4180 (modify by changing "key_code == " statements in each if statement to be new passcode (add 1 each time) |
coleandbrandon | 1:fe195c33f794 | 55 | int key_code=0; |
coleandbrandon | 1:fe195c33f794 | 56 | int i=0; |
coleandbrandon | 1:fe195c33f794 | 57 | int value=mpr121.read(0x00); |
coleandbrandon | 1:fe195c33f794 | 58 | value +=mpr121.read(0x01)<<8; |
coleandbrandon | 1:fe195c33f794 | 59 | // LED demo mod by J. Hamblen |
coleandbrandon | 1:fe195c33f794 | 60 | //pc.printf("MPR value: %x \r\n", value); |
coleandbrandon | 1:fe195c33f794 | 61 | i=0; |
coleandbrandon | 1:fe195c33f794 | 62 | // puts key number out to LEDs for demo |
coleandbrandon | 1:fe195c33f794 | 63 | for (i=0; i<12; i++) { |
coleandbrandon | 1:fe195c33f794 | 64 | if (((value>>i)&0x01)==1) key_code=i+1; |
coleandbrandon | 1:fe195c33f794 | 65 | } |
coleandbrandon | 1:fe195c33f794 | 66 | if ((key_code ==5) && (hold0 == 0) && (hold1 == 0)&& (hold2 == 0) && (hold3 == 0)){ |
coleandbrandon | 1:fe195c33f794 | 67 | hold0 =1;} |
coleandbrandon | 1:fe195c33f794 | 68 | if ((key_code ==2) && (hold0 == 1) && (hold1 == 0)&& (hold2 == 0) && (hold3 == 0)){ |
coleandbrandon | 1:fe195c33f794 | 69 | hold1 =1;} |
coleandbrandon | 1:fe195c33f794 | 70 | if ((key_code ==9) && (hold0 == 1) && (hold1 == 1)&& (hold2 == 0) && (hold3 == 0)){ |
coleandbrandon | 1:fe195c33f794 | 71 | hold2 =1;} |
coleandbrandon | 1:fe195c33f794 | 72 | if ((key_code ==1) && (hold0 == 1) && (hold1 == 1)&& (hold2 == 1) && (hold3 == 0)){ |
coleandbrandon | 1:fe195c33f794 | 73 | hold3 =1;} |
coleandbrandon | 1:fe195c33f794 | 74 | if ((hold0 == 1) && (hold1 == 1)&& (hold2 == 1) && (hold3 == 1)) { |
coleandbrandon | 1:fe195c33f794 | 75 | signal = 1; |
coleandbrandon | 1:fe195c33f794 | 76 | } |
coleandbrandon | 1:fe195c33f794 | 77 | } |
coleandbrandon | 1:fe195c33f794 | 78 | |
jhunter029 | 0:57cec3469a80 | 79 | |
jhunter029 | 0:57cec3469a80 | 80 | |
jhunter029 | 0:57cec3469a80 | 81 | int main() |
jhunter029 | 0:57cec3469a80 | 82 | { |
coleandbrandon | 1:fe195c33f794 | 83 | //reset=0; //hardware reset for 8266 |
jhunter029 | 0:57cec3469a80 | 84 | pc.baud(9600); // set what you want here depending on your terminal program speed |
jhunter029 | 0:57cec3469a80 | 85 | pc.printf("\f\n\r-------------ESP8266 Hardware Reset-------------\n\r"); |
jhunter029 | 0:57cec3469a80 | 86 | wait(0.5); |
coleandbrandon | 1:fe195c33f794 | 87 | //reset=1; |
jhunter029 | 0:57cec3469a80 | 88 | timeout=2; |
jhunter029 | 0:57cec3469a80 | 89 | getreply(); |
jhunter029 | 0:57cec3469a80 | 90 | |
jhunter029 | 0:57cec3469a80 | 91 | esp.baud(9600); // change this to the new ESP8266 baudrate if it is changed at any time. |
jhunter029 | 0:57cec3469a80 | 92 | |
jhunter029 | 0:57cec3469a80 | 93 | //ESPsetbaudrate(); //****************** include this routine to set a different ESP8266 baudrate ****************** |
jhunter029 | 0:57cec3469a80 | 94 | |
jhunter029 | 0:57cec3469a80 | 95 | ESPconfig(); //****************** include Config to set the ESP8266 configuration *********************** |
jhunter029 | 0:57cec3469a80 | 96 | |
jhunter029 | 0:57cec3469a80 | 97 | |
jhunter029 | 0:57cec3469a80 | 98 | |
jhunter029 | 0:57cec3469a80 | 99 | pc.attach(&pc_recv, Serial::RxIrq); |
jhunter029 | 0:57cec3469a80 | 100 | esp.attach(&dev_recv, Serial::RxIrq); |
jhunter029 | 0:57cec3469a80 | 101 | |
jhunter029 | 0:57cec3469a80 | 102 | // continuosly get AP list and IP |
jhunter029 | 0:57cec3469a80 | 103 | while(1) { |
jhunter029 | 0:57cec3469a80 | 104 | sleep(); |
jhunter029 | 0:57cec3469a80 | 105 | } |
jhunter029 | 0:57cec3469a80 | 106 | |
jhunter029 | 0:57cec3469a80 | 107 | } |
jhunter029 | 0:57cec3469a80 | 108 | |
jhunter029 | 0:57cec3469a80 | 109 | // Sets new ESP8266 baurate, change the esp.baud(xxxxx) to match your new setting once this has been executed |
jhunter029 | 0:57cec3469a80 | 110 | void ESPsetbaudrate() |
jhunter029 | 0:57cec3469a80 | 111 | { |
coleandbrandon | 1:fe195c33f794 | 112 | strcpy(snd, "AT+CIOBAUD=9600\r\n"); // change the numeric value to the required baudrate |
jhunter029 | 0:57cec3469a80 | 113 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 114 | } |
jhunter029 | 0:57cec3469a80 | 115 | |
jhunter029 | 0:57cec3469a80 | 116 | // +++++++++++++++++++++++++++++++++ This is for ESP8266 config only, run this once to set up the ESP8266 +++++++++++++++ |
jhunter029 | 0:57cec3469a80 | 117 | void ESPconfig() |
jhunter029 | 0:57cec3469a80 | 118 | { |
jhunter029 | 0:57cec3469a80 | 119 | |
jhunter029 | 0:57cec3469a80 | 120 | wait(5); |
jhunter029 | 0:57cec3469a80 | 121 | pc.printf("\f---------- Starting ESP Config ----------\r\n\n"); |
jhunter029 | 0:57cec3469a80 | 122 | strcpy(snd,".\r\n.\r\n"); |
jhunter029 | 0:57cec3469a80 | 123 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 124 | wait(1); |
jhunter029 | 0:57cec3469a80 | 125 | pc.printf("---------- Reset & get Firmware ----------\r\n"); |
jhunter029 | 0:57cec3469a80 | 126 | strcpy(snd,"node.restart()\r\n"); |
jhunter029 | 0:57cec3469a80 | 127 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 128 | timeout=5; |
jhunter029 | 0:57cec3469a80 | 129 | getreply(); |
jhunter029 | 0:57cec3469a80 | 130 | pc.printf(buf); |
jhunter029 | 0:57cec3469a80 | 131 | |
jhunter029 | 0:57cec3469a80 | 132 | wait(2); |
jhunter029 | 0:57cec3469a80 | 133 | |
jhunter029 | 0:57cec3469a80 | 134 | pc.printf("\n---------- Get Version ----------\r\n"); |
jhunter029 | 0:57cec3469a80 | 135 | strcpy(snd,"print(node.info())\r\n"); |
jhunter029 | 0:57cec3469a80 | 136 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 137 | timeout=4; |
jhunter029 | 0:57cec3469a80 | 138 | getreply(); |
jhunter029 | 0:57cec3469a80 | 139 | pc.printf(buf); |
jhunter029 | 0:57cec3469a80 | 140 | |
jhunter029 | 0:57cec3469a80 | 141 | wait(3); |
jhunter029 | 0:57cec3469a80 | 142 | |
jhunter029 | 0:57cec3469a80 | 143 | // set CWMODE to 1=Station,2=AP,3=BOTH, default mode 1 (Station) |
jhunter029 | 0:57cec3469a80 | 144 | pc.printf("\n---------- Setting Mode ----------\r\n"); |
jhunter029 | 0:57cec3469a80 | 145 | strcpy(snd, "wifi.setmode(wifi.STATION)\r\n"); |
jhunter029 | 0:57cec3469a80 | 146 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 147 | timeout=4; |
jhunter029 | 0:57cec3469a80 | 148 | getreply(); |
jhunter029 | 0:57cec3469a80 | 149 | pc.printf(buf); |
jhunter029 | 0:57cec3469a80 | 150 | |
jhunter029 | 0:57cec3469a80 | 151 | wait(2); |
jhunter029 | 0:57cec3469a80 | 152 | |
jhunter029 | 0:57cec3469a80 | 153 | |
jhunter029 | 0:57cec3469a80 | 154 | |
jhunter029 | 0:57cec3469a80 | 155 | pc.printf("\n---------- Listing Access Points ----------\r\n"); |
jhunter029 | 0:57cec3469a80 | 156 | strcpy(snd, "function listap(t)\r\n"); |
jhunter029 | 0:57cec3469a80 | 157 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 158 | wait(1); |
jhunter029 | 0:57cec3469a80 | 159 | strcpy(snd, "for k,v in pairs(t) do\r\n"); |
jhunter029 | 0:57cec3469a80 | 160 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 161 | wait(1); |
jhunter029 | 0:57cec3469a80 | 162 | strcpy(snd, "print(k..\" : \"..v)\r\n"); |
jhunter029 | 0:57cec3469a80 | 163 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 164 | wait(1); |
jhunter029 | 0:57cec3469a80 | 165 | strcpy(snd, "end\r\n"); |
jhunter029 | 0:57cec3469a80 | 166 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 167 | wait(1); |
jhunter029 | 0:57cec3469a80 | 168 | strcpy(snd, "end\r\n"); |
jhunter029 | 0:57cec3469a80 | 169 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 170 | wait(1); |
jhunter029 | 0:57cec3469a80 | 171 | strcpy(snd, "wifi.sta.getap(listap)\r\n"); |
jhunter029 | 0:57cec3469a80 | 172 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 173 | wait(1); |
jhunter029 | 0:57cec3469a80 | 174 | timeout=15; |
jhunter029 | 0:57cec3469a80 | 175 | getreply(); |
jhunter029 | 0:57cec3469a80 | 176 | pc.printf(buf); |
jhunter029 | 0:57cec3469a80 | 177 | |
jhunter029 | 0:57cec3469a80 | 178 | wait(2); |
jhunter029 | 0:57cec3469a80 | 179 | |
jhunter029 | 0:57cec3469a80 | 180 | pc.printf("\n---------- Connecting to AP ----------\r\n"); |
jhunter029 | 0:57cec3469a80 | 181 | pc.printf("ssid = %s pwd = %s\r\n",ssid,pwd); |
jhunter029 | 0:57cec3469a80 | 182 | strcpy(snd, "wifi.sta.config(\""); |
jhunter029 | 0:57cec3469a80 | 183 | strcat(snd, ssid); |
jhunter029 | 0:57cec3469a80 | 184 | strcat(snd, "\",\""); |
jhunter029 | 0:57cec3469a80 | 185 | strcat(snd, pwd); |
jhunter029 | 0:57cec3469a80 | 186 | strcat(snd, "\")\r\n"); |
jhunter029 | 0:57cec3469a80 | 187 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 188 | timeout=10; |
jhunter029 | 0:57cec3469a80 | 189 | getreply(); |
jhunter029 | 0:57cec3469a80 | 190 | pc.printf(buf); |
jhunter029 | 0:57cec3469a80 | 191 | |
jhunter029 | 0:57cec3469a80 | 192 | wait(5); |
jhunter029 | 0:57cec3469a80 | 193 | |
jhunter029 | 0:57cec3469a80 | 194 | pc.printf("\n---------- Get IP's ----------\r\n"); |
jhunter029 | 0:57cec3469a80 | 195 | strcpy(snd, "print(wifi.sta.getip())\r\n"); |
jhunter029 | 0:57cec3469a80 | 196 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 197 | timeout=3; |
jhunter029 | 0:57cec3469a80 | 198 | getreply(); |
jhunter029 | 0:57cec3469a80 | 199 | pc.printf(buf); |
jhunter029 | 0:57cec3469a80 | 200 | |
jhunter029 | 0:57cec3469a80 | 201 | wait(1); |
jhunter029 | 0:57cec3469a80 | 202 | |
jhunter029 | 0:57cec3469a80 | 203 | pc.printf("\n---------- Get Connection Status ----------\r\n"); |
jhunter029 | 0:57cec3469a80 | 204 | strcpy(snd, "print(wifi.sta.status())\r\n"); |
jhunter029 | 0:57cec3469a80 | 205 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 206 | timeout=5; |
jhunter029 | 0:57cec3469a80 | 207 | getreply(); |
jhunter029 | 0:57cec3469a80 | 208 | pc.printf(buf); |
jhunter029 | 0:57cec3469a80 | 209 | |
jhunter029 | 0:57cec3469a80 | 210 | pc.printf("\n\n\n If you get a valid (non zero) IP, ESP8266 has been set up.\r\n"); |
jhunter029 | 0:57cec3469a80 | 211 | pc.printf(" Run this if you want to reconfig the ESP8266 at any time.\r\n"); |
jhunter029 | 0:57cec3469a80 | 212 | pc.printf(" It saves the SSID and password settings internally\r\n"); |
jhunter029 | 0:57cec3469a80 | 213 | wait(10); |
jhunter029 | 0:57cec3469a80 | 214 | |
jhunter029 | 0:57cec3469a80 | 215 | |
jhunter029 | 0:57cec3469a80 | 216 | pc.printf("\n---------- Setting up http server ----------\r\n"); |
jhunter029 | 0:57cec3469a80 | 217 | strcpy(snd, "srv=net.createServer(net.TCP)\r\n"); |
jhunter029 | 0:57cec3469a80 | 218 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 219 | wait(1); |
jhunter029 | 0:57cec3469a80 | 220 | strcpy(snd, "srv:listen(80,function(conn)\r\n"); |
jhunter029 | 0:57cec3469a80 | 221 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 222 | wait(1); |
jhunter029 | 0:57cec3469a80 | 223 | strcpy(snd, "conn:on(\"receive\",function(conn,payload)\r\n"); |
jhunter029 | 0:57cec3469a80 | 224 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 225 | wait(1); |
jhunter029 | 0:57cec3469a80 | 226 | strcpy(snd, "print(payload)\r\n"); |
jhunter029 | 0:57cec3469a80 | 227 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 228 | wait(1); |
jhunter029 | 0:57cec3469a80 | 229 | |
jhunter029 | 0:57cec3469a80 | 230 | strcpy(snd, "conn:send(\"<!DOCTYPE html>\")\r\n"); |
jhunter029 | 0:57cec3469a80 | 231 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 232 | wait(1); |
jhunter029 | 0:57cec3469a80 | 233 | |
jhunter029 | 0:57cec3469a80 | 234 | strcpy(snd, "conn:send(\"<html>\")\r\n"); |
jhunter029 | 0:57cec3469a80 | 235 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 236 | wait(1); |
jhunter029 | 0:57cec3469a80 | 237 | |
coleandbrandon | 1:fe195c33f794 | 238 | strcpy(snd, "conn:send(\"<h1> Password Test</h1>\")\r\n"); |
jhunter029 | 0:57cec3469a80 | 239 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 240 | wait(1); |
jhunter029 | 0:57cec3469a80 | 241 | |
coleandbrandon | 1:fe195c33f794 | 242 | //the good stuff |
coleandbrandon | 1:fe195c33f794 | 243 | interrupt.fall(&fallInterrupt); |
coleandbrandon | 1:fe195c33f794 | 244 | interrupt.mode(PullUp); |
coleandbrandon | 1:fe195c33f794 | 245 | |
coleandbrandon | 2:ae7610f4867a | 246 | pc.printf("ENTER YOUR PASSWORD IN THE NEXT 10 SECONDS!"); |
coleandbrandon | 1:fe195c33f794 | 247 | wait(10); |
coleandbrandon | 1:fe195c33f794 | 248 | |
coleandbrandon | 1:fe195c33f794 | 249 | if (signal ==1){ |
coleandbrandon | 1:fe195c33f794 | 250 | led1 = 1; |
coleandbrandon | 2:ae7610f4867a | 251 | strcpy(snd, "conn:send(\"<h1> UNLOCKED!</h1>\")\r\n"); |
coleandbrandon | 1:fe195c33f794 | 252 | SendCMD(); |
coleandbrandon | 1:fe195c33f794 | 253 | } |
coleandbrandon | 1:fe195c33f794 | 254 | else { |
coleandbrandon | 2:ae7610f4867a | 255 | strcpy(snd, "conn:send(\"<h1> REJECTED!</h1>\")\r\n"); |
coleandbrandon | 1:fe195c33f794 | 256 | SendCMD(); |
coleandbrandon | 1:fe195c33f794 | 257 | } |
coleandbrandon | 1:fe195c33f794 | 258 | |
jhunter029 | 0:57cec3469a80 | 259 | |
jhunter029 | 0:57cec3469a80 | 260 | strcpy(snd, "conn:send(\"</html>\")\r\n"); |
jhunter029 | 0:57cec3469a80 | 261 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 262 | wait(1); |
jhunter029 | 0:57cec3469a80 | 263 | |
jhunter029 | 0:57cec3469a80 | 264 | strcpy(snd, "end)\r\n"); |
jhunter029 | 0:57cec3469a80 | 265 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 266 | wait(1); |
jhunter029 | 0:57cec3469a80 | 267 | |
jhunter029 | 0:57cec3469a80 | 268 | strcpy(snd, "conn:on(\"sent\",function(conn) conn:close() end)\r\n"); |
jhunter029 | 0:57cec3469a80 | 269 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 270 | wait(1); |
jhunter029 | 0:57cec3469a80 | 271 | strcpy(snd, "end)\r\n"); |
jhunter029 | 0:57cec3469a80 | 272 | SendCMD(); |
jhunter029 | 0:57cec3469a80 | 273 | wait(1); |
jhunter029 | 0:57cec3469a80 | 274 | timeout=17; |
jhunter029 | 0:57cec3469a80 | 275 | getreply(); |
jhunter029 | 0:57cec3469a80 | 276 | pc.printf(buf); |
jhunter029 | 0:57cec3469a80 | 277 | pc.printf("\r\nDONE"); |
jhunter029 | 0:57cec3469a80 | 278 | } |
jhunter029 | 0:57cec3469a80 | 279 | |
jhunter029 | 0:57cec3469a80 | 280 | void SendCMD() |
jhunter029 | 0:57cec3469a80 | 281 | { |
jhunter029 | 0:57cec3469a80 | 282 | esp.printf("%s", snd); |
jhunter029 | 0:57cec3469a80 | 283 | } |
jhunter029 | 0:57cec3469a80 | 284 | |
jhunter029 | 0:57cec3469a80 | 285 | void getreply() |
jhunter029 | 0:57cec3469a80 | 286 | { |
jhunter029 | 0:57cec3469a80 | 287 | memset(buf, '\0', sizeof(buf)); |
jhunter029 | 0:57cec3469a80 | 288 | t.start(); |
jhunter029 | 0:57cec3469a80 | 289 | ended=0; |
jhunter029 | 0:57cec3469a80 | 290 | count=0; |
jhunter029 | 0:57cec3469a80 | 291 | while(!ended) { |
jhunter029 | 0:57cec3469a80 | 292 | if(esp.readable()) { |
jhunter029 | 0:57cec3469a80 | 293 | buf[count] = esp.getc(); |
jhunter029 | 0:57cec3469a80 | 294 | count++; |
jhunter029 | 0:57cec3469a80 | 295 | } |
jhunter029 | 0:57cec3469a80 | 296 | if(t.read() > timeout) { |
jhunter029 | 0:57cec3469a80 | 297 | ended = 1; |
jhunter029 | 0:57cec3469a80 | 298 | t.stop(); |
jhunter029 | 0:57cec3469a80 | 299 | t.reset(); |
jhunter029 | 0:57cec3469a80 | 300 | } |
jhunter029 | 0:57cec3469a80 | 301 | } |
jhunter029 | 0:57cec3469a80 | 302 | } |
jhunter029 | 0:57cec3469a80 | 303 | |
jhunter029 | 0:57cec3469a80 | 304 |