4180 Final Project

Dependencies:   4DGL-uLCD-SE mbed Servo

Committer:
ecarrick
Date:
Sun May 01 19:54:20 2016 +0000
Revision:
27:2bd737c0a8af
Parent:
26:f08205fa22d3
some small fixes and adding comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pshabbaki3 0:5d35ff3dc9a5 1 #include "mbed.h"
ecarrick 6:50a82641d07b 2 #include "wifi.h"
pshabbaki3 0:5d35ff3dc9a5 3 #include <string>
pshabbaki3 0:5d35ff3dc9a5 4 #include <vector>
pshabbaki3 0:5d35ff3dc9a5 5 #include <iostream>
pshabbaki3 0:5d35ff3dc9a5 6 #include <sstream>
pshabbaki3 0:5d35ff3dc9a5 7 #include <iterator>
pshabbaki3 0:5d35ff3dc9a5 8 #include <stdio.h>
pshabbaki3 0:5d35ff3dc9a5 9 #include <ctype.h>
pshabbaki3 0:5d35ff3dc9a5 10 #include "uLCD_4DGL.h"
ecarrick 25:2e95a5731412 11 #include "Servo.h"
pshabbaki3 0:5d35ff3dc9a5 12
mbedTrent 7:52b51f507ee5 13 #include <list>
mbedTrent 7:52b51f507ee5 14 #include <mpr121.h>
mbedTrent 7:52b51f507ee5 15
ecarrick 1:dd048edb2716 16 LocalFileSystem local("local");
ecarrick 25:2e95a5731412 17 Servo lock(p25); // a pwm pin, 0 for unlocked; 1 for locked;
pshabbaki3 0:5d35ff3dc9a5 18
pshabbaki3 0:5d35ff3dc9a5 19 DigitalOut myled(LED1);
ecarrick 17:632c56db3c0a 20 DigitalOut ledr(p5);
ecarrick 17:632c56db3c0a 21 DigitalOut ledg(p6);
ecarrick 17:632c56db3c0a 22 DigitalOut ledb(p7);
ecarrick 17:632c56db3c0a 23
pshabbaki3 0:5d35ff3dc9a5 24 Serial pc(USBTX,USBRX);
ecarrick 16:fb2a50f0ecde 25 //uLCD_4DGL lcd(p28,p27,p30); // serial tx, serial rx, reset pin;
pshabbaki3 0:5d35ff3dc9a5 26
mbedTrent 7:52b51f507ee5 27 // Create the interrupt receiver object on pin 26
mbedTrent 7:52b51f507ee5 28 InterruptIn interrupt(p26);
mbedTrent 7:52b51f507ee5 29
mbedTrent 7:52b51f507ee5 30 // Setup the i2c bus on pins 28 and 27
mbedTrent 7:52b51f507ee5 31 I2C i2c(p9, p10);
mbedTrent 7:52b51f507ee5 32
mbedTrent 7:52b51f507ee5 33 // Setup the Mpr121:
mbedTrent 7:52b51f507ee5 34 // constructor(i2c object, i2c address of the mpr121)
mbedTrent 7:52b51f507ee5 35 Mpr121 mpr121(&i2c, Mpr121::ADD_VSS);
mbedTrent 7:52b51f507ee5 36
ecarrick 25:2e95a5731412 37 // log for web page
ecarrick 25:2e95a5731412 38 vector<string> accessLog;
ecarrick 27:2bd737c0a8af 39 unsigned logLength = 5;
ecarrick 25:2e95a5731412 40 volatile bool updateAccessLog = false;
ecarrick 25:2e95a5731412 41
ecarrick 25:2e95a5731412 42 // save to file flag
ecarrick 25:2e95a5731412 43 volatile bool saveToFileFlag = false;
ecarrick 25:2e95a5731412 44 volatile bool newData = false;
ecarrick 25:2e95a5731412 45
ecarrick 25:2e95a5731412 46 // time
ecarrick 25:2e95a5731412 47 time_t rtc;
pshabbaki3 0:5d35ff3dc9a5 48
pshabbaki3 0:5d35ff3dc9a5 49 vector<char> im;
ecarrick 26:f08205fa22d3 50 vector<char> tempim;
pshabbaki3 4:e6b198a22216 51 vector<char> pass;
pshabbaki3 0:5d35ff3dc9a5 52 vector<char> name;
pshabbaki3 0:5d35ff3dc9a5 53 vector<char> final;
pshabbaki3 11:1ca1f07896b0 54 vector<char> ans;
pshabbaki3 0:5d35ff3dc9a5 55
ecarrick 25:2e95a5731412 56 string print_vector(vector<char>& vec){
ecarrick 25:2e95a5731412 57 string str;
ecarrick 25:2e95a5731412 58 str.append(vec.begin(),vec.end());
ecarrick 25:2e95a5731412 59 return str;
ecarrick 25:2e95a5731412 60 }
ecarrick 25:2e95a5731412 61
mbedTrent 10:cf127bd9b857 62 vector<char> password;
mbedTrent 15:3d43fe8e108b 63 unsigned maxLength = 18; //random length chosen
mbedTrent 15:3d43fe8e108b 64 unsigned minLength = 6; //random length chosen
mbedTrent 10:cf127bd9b857 65
ecarrick 24:94e8b3e00c24 66 void print_to_serial()
ecarrick 24:94e8b3e00c24 67 {
ecarrick 24:94e8b3e00c24 68 for(unsigned i=0; i< im.size(); i++) {
ecarrick 24:94e8b3e00c24 69 pc.printf("%c",im[i]);
ecarrick 24:94e8b3e00c24 70 }
ecarrick 24:94e8b3e00c24 71 pc.printf("\r\n");
ecarrick 24:94e8b3e00c24 72 }
pshabbaki3 12:22444d5f5920 73
mbedTrent 10:cf127bd9b857 74 //function for debugging
pshabbaki3 12:22444d5f5920 75 void printPW()
pshabbaki3 12:22444d5f5920 76 {
mbedTrent 10:cf127bd9b857 77 for (int i=0; i<password.size(); i++) {
ecarrick 24:94e8b3e00c24 78 pc.printf("%c", password[i]);
mbedTrent 10:cf127bd9b857 79 }
mbedTrent 10:cf127bd9b857 80 pc.printf("\r\n");
mbedTrent 10:cf127bd9b857 81 }
mbedTrent 7:52b51f507ee5 82
ecarrick 25:2e95a5731412 83 bool foundResult = false;
ecarrick 16:fb2a50f0ecde 84 void checkResult(vector<char> pass, vector<char> name)
ecarrick 16:fb2a50f0ecde 85 {
ecarrick 25:2e95a5731412 86 /*
ecarrick 24:94e8b3e00c24 87 for (int i=0; i<pass.size(); i++) {
ecarrick 24:94e8b3e00c24 88 pc.printf("%d", int(pass[i]));
ecarrick 24:94e8b3e00c24 89 }
ecarrick 25:2e95a5731412 90 */
ecarrick 25:2e95a5731412 91
ecarrick 25:2e95a5731412 92 //pc.printf("\r\n");
ecarrick 16:fb2a50f0ecde 93 // This function will check the keypad values and check if the passcode exists or not
ecarrick 16:fb2a50f0ecde 94
ecarrick 16:fb2a50f0ecde 95 if (pass.size()==6) {
ecarrick 24:94e8b3e00c24 96 if (password == pass) {
ecarrick 25:2e95a5731412 97 //pc.printf("Found");
ecarrick 16:fb2a50f0ecde 98 final = name;
ecarrick 16:fb2a50f0ecde 99 final.push_back(' ');
ecarrick 16:fb2a50f0ecde 100 final.insert(final.end(),pass.begin(),pass.end());
ecarrick 25:2e95a5731412 101 foundResult=true;
ecarrick 25:2e95a5731412 102 ledb =0;
ecarrick 25:2e95a5731412 103 ledr =0;
ecarrick 25:2e95a5731412 104 ledg =1;
ecarrick 25:2e95a5731412 105 lock = 0;
ecarrick 25:2e95a5731412 106 //wait(0.01);
ecarrick 25:2e95a5731412 107 //ledg =0;
ecarrick 16:fb2a50f0ecde 108
ecarrick 16:fb2a50f0ecde 109 } else {
ecarrick 25:2e95a5731412 110 //pc.printf("not found");
ecarrick 16:fb2a50f0ecde 111 //lcd.printf("\nnot found\n");
ecarrick 16:fb2a50f0ecde 112 final.clear();
ecarrick 16:fb2a50f0ecde 113 }
ecarrick 16:fb2a50f0ecde 114 }
ecarrick 16:fb2a50f0ecde 115 }
ecarrick 16:fb2a50f0ecde 116
ecarrick 16:fb2a50f0ecde 117
ecarrick 16:fb2a50f0ecde 118 void checkKeyboard()
ecarrick 16:fb2a50f0ecde 119 {
pshabbaki3 23:e23578000e42 120 //load_from_file();
ecarrick 25:2e95a5731412 121 //pc.printf("CHECKING PASSWORD\n\r");
ecarrick 25:2e95a5731412 122 //pc.printf("\n\r");
pshabbaki3 19:6fce7b88de5e 123 bool colon = false;
ecarrick 25:2e95a5731412 124 vector<char> empty;
ecarrick 25:2e95a5731412 125 swap(empty, pass);
ecarrick 25:2e95a5731412 126 vector<char> empty2;
ecarrick 25:2e95a5731412 127 swap(empty2, name);
ecarrick 25:2e95a5731412 128 //pass.clear();
ecarrick 25:2e95a5731412 129 //name.clear();
ecarrick 16:fb2a50f0ecde 130 for (int i = 0; i<im.size(); i++) {
pshabbaki3 19:6fce7b88de5e 131
ecarrick 16:fb2a50f0ecde 132 // find space
ecarrick 16:fb2a50f0ecde 133 if (im[i] ==' ') {
ecarrick 16:fb2a50f0ecde 134 checkResult(pass,name);
pshabbaki3 19:6fce7b88de5e 135 colon = false;
ecarrick 25:2e95a5731412 136 if(foundResult){
ecarrick 25:2e95a5731412 137 //foundResult=false;
ecarrick 25:2e95a5731412 138 break;
ecarrick 25:2e95a5731412 139 }
ecarrick 25:2e95a5731412 140 vector<char> empty;
ecarrick 25:2e95a5731412 141 swap(empty, pass);
ecarrick 25:2e95a5731412 142 vector<char> empty2;
ecarrick 25:2e95a5731412 143 swap(empty2, name);
ecarrick 25:2e95a5731412 144 //pass.clear();
ecarrick 25:2e95a5731412 145 //name.clear();
pshabbaki3 19:6fce7b88de5e 146
pshabbaki3 19:6fce7b88de5e 147 } else if (im[i] == ':') {
pshabbaki3 19:6fce7b88de5e 148 colon = true;
ecarrick 16:fb2a50f0ecde 149 } else {
pshabbaki3 19:6fce7b88de5e 150 if(colon)
ecarrick 24:94e8b3e00c24 151 pass.push_back(unsigned(im[i]));
pshabbaki3 19:6fce7b88de5e 152 else
ecarrick 24:94e8b3e00c24 153 name.push_back(char(im[i]));
ecarrick 16:fb2a50f0ecde 154 }
ecarrick 16:fb2a50f0ecde 155 }
ecarrick 16:fb2a50f0ecde 156 }
ecarrick 16:fb2a50f0ecde 157
pshabbaki3 9:11a6f6c8c54b 158 void fallInterrupt()
pshabbaki3 9:11a6f6c8c54b 159 {
mbedTrent 7:52b51f507ee5 160 int key_code=0;
mbedTrent 7:52b51f507ee5 161 int i=0;
mbedTrent 7:52b51f507ee5 162 int value=mpr121.read(0x00);
mbedTrent 7:52b51f507ee5 163 value +=mpr121.read(0x01)<<8;
mbedTrent 10:cf127bd9b857 164
mbedTrent 10:cf127bd9b857 165 //checks every key for press
mbedTrent 7:52b51f507ee5 166 for (i=0; i<=11; i++) {
pshabbaki3 12:22444d5f5920 167
mbedTrent 10:cf127bd9b857 168 //if key 10 (clr) is pressed, clear the last value on the vector will be popped off
mbedTrent 10:cf127bd9b857 169 if ((((value>>i)&0x01)==1)&&(i==10)) {
ecarrick 25:2e95a5731412 170
mbedTrent 10:cf127bd9b857 171 if (!password.empty()) {
ecarrick 17:632c56db3c0a 172 ledb = 1;
mbedTrent 10:cf127bd9b857 173 password.pop_back(); //pop off last value on the vector
ecarrick 25:2e95a5731412 174 //printPW();//for debugging
ecarrick 25:2e95a5731412 175 //pc.printf("container size: %d\r\n", password.size());//for dubugging
mbedTrent 10:cf127bd9b857 176 }
mbedTrent 15:3d43fe8e108b 177 break;
mbedTrent 10:cf127bd9b857 178 }
pshabbaki3 12:22444d5f5920 179
mbedTrent 10:cf127bd9b857 180 //if key 11 (ENTER) is pressed, the password will be submitted IF it is long enough
mbedTrent 10:cf127bd9b857 181 else if ((((value>>i)&0x01)==1)&&(i==11)) {
ecarrick 25:2e95a5731412 182 if(lock == 0){
ecarrick 25:2e95a5731412 183 lock = 1.0;
ecarrick 25:2e95a5731412 184 break;
ecarrick 25:2e95a5731412 185 }
mbedTrent 10:cf127bd9b857 186 //if the password is long enough, check passwords, and clear vector.
mbedTrent 15:3d43fe8e108b 187 if (password.size() >= minLength) {
ecarrick 25:2e95a5731412 188 //ledb = 1;
ecarrick 24:94e8b3e00c24 189 //ans = password;
ecarrick 25:2e95a5731412 190 //pc.printf("ENTER KEY PRESSED\n\r");
ecarrick 25:2e95a5731412 191 //printPW();
ecarrick 25:2e95a5731412 192 //for(unsigned k =0; k<password.size(); k++)
ecarrick 25:2e95a5731412 193 // ans.push_back(password[k]);
ecarrick 16:fb2a50f0ecde 194 checkKeyboard();
ecarrick 25:2e95a5731412 195 rtc = time(NULL);
ecarrick 27:2bd737c0a8af 196 char time_s[128];
ecarrick 27:2bd737c0a8af 197 struct tm * p = localtime(&rtc);
ecarrick 27:2bd737c0a8af 198 strftime(time_s, 128, "%T %F", p);
ecarrick 25:2e95a5731412 199 if(foundResult){
ecarrick 25:2e95a5731412 200 foundResult=false;
ecarrick 25:2e95a5731412 201 char buf[128];
ecarrick 27:2bd737c0a8af 202 sprintf(buf,"SUCCESS %s %s", print_vector(name).c_str(), time_s);
ecarrick 25:2e95a5731412 203 if(accessLog.size()<logLength){
ecarrick 25:2e95a5731412 204 accessLog.push_back(buf);
ecarrick 25:2e95a5731412 205 } else{
ecarrick 25:2e95a5731412 206 vector<string> empty;
ecarrick 25:2e95a5731412 207 swap(accessLog,empty);
ecarrick 25:2e95a5731412 208 //accessLog.clear();
ecarrick 25:2e95a5731412 209 accessLog.push_back(buf);
ecarrick 25:2e95a5731412 210 }
ecarrick 25:2e95a5731412 211 } else{
ecarrick 25:2e95a5731412 212 ledr = 1;
ecarrick 25:2e95a5731412 213 char buf[128];
ecarrick 27:2bd737c0a8af 214 sprintf(buf,"FAILURE %s %s", print_vector(password).c_str(), time_s);
ecarrick 25:2e95a5731412 215 if(accessLog.size()<logLength){
ecarrick 25:2e95a5731412 216 accessLog.push_back(buf);
ecarrick 25:2e95a5731412 217 } else{
ecarrick 25:2e95a5731412 218 vector<string> empty;
ecarrick 25:2e95a5731412 219 swap(accessLog,empty);
ecarrick 25:2e95a5731412 220 //accessLog.clear();
ecarrick 25:2e95a5731412 221 accessLog.push_back(buf);
ecarrick 25:2e95a5731412 222 }
ecarrick 25:2e95a5731412 223 }
ecarrick 25:2e95a5731412 224 //update_log(accessLog);
ecarrick 25:2e95a5731412 225 updateAccessLog = true;
ecarrick 27:2bd737c0a8af 226 wait(0.005);
ecarrick 25:2e95a5731412 227 ledg=0;
ecarrick 25:2e95a5731412 228 ledr=0;
mbedTrent 15:3d43fe8e108b 229 vector<char> empty;
mbedTrent 15:3d43fe8e108b 230 swap(empty, password);
ecarrick 25:2e95a5731412 231 //password.clear();
mbedTrent 10:cf127bd9b857 232 }
pshabbaki3 12:22444d5f5920 233
mbedTrent 10:cf127bd9b857 234 else {
ecarrick 25:2e95a5731412 235 //pc.printf("The password must be at least %d characters long\r\n", minLength);
mbedTrent 10:cf127bd9b857 236 }
mbedTrent 15:3d43fe8e108b 237 break;
pshabbaki3 12:22444d5f5920 238 }
pshabbaki3 12:22444d5f5920 239
mbedTrent 10:cf127bd9b857 240 //if keys 0 through 9 are pressed
mbedTrent 10:cf127bd9b857 241 else if (((value>>i)&0x01)==1) {
mbedTrent 7:52b51f507ee5 242
mbedTrent 10:cf127bd9b857 243 //if max pw length has not been reached, push onto password vector
mbedTrent 10:cf127bd9b857 244 if (password.size() < maxLength) {
ecarrick 17:632c56db3c0a 245 ledb = 1;
ecarrick 18:107fe4158212 246
ecarrick 17:632c56db3c0a 247
mbedTrent 7:52b51f507ee5 248 key_code=i;
ecarrick 24:94e8b3e00c24 249 password.push_back((char)(key_code+48));
ecarrick 25:2e95a5731412 250 //printPW(); //for debugging
ecarrick 25:2e95a5731412 251 //pc.printf("times: %d\r\n", password.size());
mbedTrent 15:3d43fe8e108b 252
mbedTrent 15:3d43fe8e108b 253 if (password.size() == maxLength) {
mbedTrent 15:3d43fe8e108b 254 //pc.printf("Max password length reached. Press clr to delete character. Press any number key to reset.\r\n");
ecarrick 25:2e95a5731412 255 ledb = 0;
ecarrick 25:2e95a5731412 256 ledr = 1;
ecarrick 25:2e95a5731412 257 wait(0.05);
ecarrick 25:2e95a5731412 258 ledr = 0;
mbedTrent 15:3d43fe8e108b 259 vector<char> empty;
mbedTrent 15:3d43fe8e108b 260 swap(empty, password);
mbedTrent 15:3d43fe8e108b 261 //password.clear();
mbedTrent 15:3d43fe8e108b 262 }
mbedTrent 15:3d43fe8e108b 263 }
mbedTrent 15:3d43fe8e108b 264
mbedTrent 15:3d43fe8e108b 265 //if max password length has been reached
mbedTrent 15:3d43fe8e108b 266 else {
ecarrick 25:2e95a5731412 267 //pc.printf("Maximum password length reached, password has been cleared. \r\n");
ecarrick 25:2e95a5731412 268 //password.clear();
ecarrick 25:2e95a5731412 269 vector<char> empty;
ecarrick 25:2e95a5731412 270 swap(empty, password);
mbedTrent 15:3d43fe8e108b 271 }
mbedTrent 15:3d43fe8e108b 272 break;
mbedTrent 15:3d43fe8e108b 273 }
mbedTrent 15:3d43fe8e108b 274
mbedTrent 15:3d43fe8e108b 275 }
ecarrick 25:2e95a5731412 276 wait(0.005);
ecarrick 18:107fe4158212 277 ledb = 0;
mbedTrent 15:3d43fe8e108b 278
mbedTrent 15:3d43fe8e108b 279 }
mbedTrent 15:3d43fe8e108b 280
pshabbaki3 9:11a6f6c8c54b 281 void save_to_file()
pshabbaki3 9:11a6f6c8c54b 282 {
ecarrick 5:a2fbe5bd2be0 283 FILE * fp = fopen("/local/users.txt", "w");
pshabbaki3 9:11a6f6c8c54b 284 if(fp != NULL) {
pshabbaki3 9:11a6f6c8c54b 285 for(unsigned i=0; i< im.size(); i++) {
ecarrick 6:50a82641d07b 286 fprintf(fp,"%c",im[i]);
ecarrick 5:a2fbe5bd2be0 287 }
ecarrick 5:a2fbe5bd2be0 288 }
ecarrick 5:a2fbe5bd2be0 289 fclose(fp);
ecarrick 5:a2fbe5bd2be0 290 }
ecarrick 5:a2fbe5bd2be0 291
pshabbaki3 9:11a6f6c8c54b 292 void load_from_file()
pshabbaki3 9:11a6f6c8c54b 293 {
ecarrick 5:a2fbe5bd2be0 294 FILE * fp = fopen("/local/users.txt", "r");
pshabbaki3 9:11a6f6c8c54b 295 if(fp != NULL) {
ecarrick 5:a2fbe5bd2be0 296 im.clear();
pshabbaki3 9:11a6f6c8c54b 297 do {
ecarrick 6:50a82641d07b 298 im.push_back(fgetc(fp));
pshabbaki3 9:11a6f6c8c54b 299 } while(im.back() != '#');
ecarrick 5:a2fbe5bd2be0 300 }
ecarrick 5:a2fbe5bd2be0 301 fclose(fp);
ecarrick 5:a2fbe5bd2be0 302 }
pshabbaki3 0:5d35ff3dc9a5 303
pshabbaki3 0:5d35ff3dc9a5 304 int i = 0;
pshabbaki3 0:5d35ff3dc9a5 305
pshabbaki3 0:5d35ff3dc9a5 306
pshabbaki3 0:5d35ff3dc9a5 307
pshabbaki3 12:22444d5f5920 308 //Interrupt
pshabbaki3 12:22444d5f5920 309 void Rx_interrupt()
pshabbaki3 0:5d35ff3dc9a5 310 {
ecarrick 26:f08205fa22d3 311 if(!newData){
ecarrick 27:2bd737c0a8af 312 // at the start of getting new data we need to indicate we are receiving data
ecarrick 27:2bd737c0a8af 313 // the first character will clear the temporary IM and save the char
ecarrick 27:2bd737c0a8af 314 ledb = 1;
ecarrick 26:f08205fa22d3 315 tempim.clear();
ecarrick 27:2bd737c0a8af 316 char c = pc.getc();
ecarrick 27:2bd737c0a8af 317 if(c=='!')
ecarrick 27:2bd737c0a8af 318 print_to_serial();
ecarrick 27:2bd737c0a8af 319 else{
ecarrick 27:2bd737c0a8af 320 tempim.push_back(c);
ecarrick 27:2bd737c0a8af 321 newData = true;
ecarrick 27:2bd737c0a8af 322 }
ecarrick 26:f08205fa22d3 323 }
ecarrick 26:f08205fa22d3 324 else{
ecarrick 27:2bd737c0a8af 325 // get the next character
ecarrick 26:f08205fa22d3 326 char c = pc.getc();
ecarrick 27:2bd737c0a8af 327 // unless we see a #, then we expect more characters
ecarrick 26:f08205fa22d3 328 if (c!='#') {
ecarrick 26:f08205fa22d3 329 tempim.push_back(c); //writing all the characters into vector
ecarrick 27:2bd737c0a8af 330 // if we see a #, the string is complete, reset all of the flags and update im
ecarrick 26:f08205fa22d3 331 } else {
ecarrick 27:2bd737c0a8af 332 ledb=0;
ecarrick 26:f08205fa22d3 333 tempim.push_back(c);
ecarrick 26:f08205fa22d3 334 saveToFileFlag = true;
ecarrick 26:f08205fa22d3 335 im = tempim;
ecarrick 26:f08205fa22d3 336 newData = false;
ecarrick 26:f08205fa22d3 337 }
ecarrick 26:f08205fa22d3 338 }
pshabbaki3 12:22444d5f5920 339 return;
pshabbaki3 0:5d35ff3dc9a5 340 }
pshabbaki3 0:5d35ff3dc9a5 341
pshabbaki3 0:5d35ff3dc9a5 342
pshabbaki3 12:22444d5f5920 343 int main()
pshabbaki3 12:22444d5f5920 344 {
ecarrick 27:2bd737c0a8af 345 // notify over PC serial that we have reset the mbed
ecarrick 25:2e95a5731412 346 pc.printf("\r\n\r\nMBED RESET\r\n");
ecarrick 27:2bd737c0a8af 347 // ensure the lock starts in the locked position
ecarrick 27:2bd737c0a8af 348 // lock = 0 is unlocked
ecarrick 25:2e95a5731412 349 lock = 1.0;
ecarrick 27:2bd737c0a8af 350
ecarrick 27:2bd737c0a8af 351 // to show it's setting up, we keep the LED blue, when a function completes it flashes
ecarrick 27:2bd737c0a8af 352 // when the LED flashes green 3 times the setup is complete
ecarrick 27:2bd737c0a8af 353 ledb=1;
ecarrick 27:2bd737c0a8af 354 // setup and connect to the WiFi
ecarrick 25:2e95a5731412 355 pc.printf("Setting up WIFI\r\n");
ecarrick 27:2bd737c0a8af 356 setup_wifi();
ecarrick 27:2bd737c0a8af 357 ledb = 0;
ecarrick 27:2bd737c0a8af 358 wait(0.3);
ecarrick 27:2bd737c0a8af 359 ledb = 1;
ecarrick 27:2bd737c0a8af 360 // send the HTTP socket functions to the ESP8266 module
ecarrick 25:2e95a5731412 361 pc.printf("Setting Up HTTP\r\n");
ecarrick 27:2bd737c0a8af 362 setup_http();
ecarrick 27:2bd737c0a8af 363 ledb = 0;
ecarrick 27:2bd737c0a8af 364 wait(0.3);
ecarrick 27:2bd737c0a8af 365 ledb = 1;
ecarrick 27:2bd737c0a8af 366 // send the NTP connection functions to the WiFi module
ecarrick 25:2e95a5731412 367 pc.printf("Setting up NTP\r\n");
ecarrick 27:2bd737c0a8af 368 setup_ntp();
ecarrick 27:2bd737c0a8af 369 ledb = 0;
ecarrick 27:2bd737c0a8af 370 wait(0.3);
ecarrick 27:2bd737c0a8af 371 ledb = 1;
ecarrick 27:2bd737c0a8af 372 // use NTP and update the mbed RTC
ecarrick 25:2e95a5731412 373 pc.printf("Updating NTP\r\n");
ecarrick 27:2bd737c0a8af 374 update_ntp();
ecarrick 27:2bd737c0a8af 375 ledb = 0;
ecarrick 27:2bd737c0a8af 376 wait(0.3);
ecarrick 27:2bd737c0a8af 377 ledb = 1;
ecarrick 27:2bd737c0a8af 378 // verify to the user over the PC serial port the time obtained
ecarrick 25:2e95a5731412 379 rtc = time(NULL);
ecarrick 25:2e95a5731412 380 pc.printf("%s\r\n", ctime(&rtc));
ecarrick 25:2e95a5731412 381
ecarrick 27:2bd737c0a8af 382 // load the user/password information saved on the device
ecarrick 24:94e8b3e00c24 383 load_from_file();
ecarrick 16:fb2a50f0ecde 384 print_to_serial();
ecarrick 27:2bd737c0a8af 385 ledb = 1;
ecarrick 27:2bd737c0a8af 386 wait(0.3);
ecarrick 27:2bd737c0a8af 387 ledb = 0;
ecarrick 27:2bd737c0a8af 388 // register the iterrupts for handling the keypad
pshabbaki3 12:22444d5f5920 389 interrupt.fall(&fallInterrupt);
pshabbaki3 12:22444d5f5920 390 interrupt.mode(PullUp);
ecarrick 27:2bd737c0a8af 391 ledb = 1;
ecarrick 27:2bd737c0a8af 392 wait(0.3);
ecarrick 27:2bd737c0a8af 393 ledb = 0;
ecarrick 27:2bd737c0a8af 394 //interupt driven read from serial port C# program
ecarrick 27:2bd737c0a8af 395 // sets saveToFileFlag;
pshabbaki3 12:22444d5f5920 396 pc.attach(&Rx_interrupt, Serial::RxIrq);
ecarrick 27:2bd737c0a8af 397 ledb = 1;
ecarrick 27:2bd737c0a8af 398 wait(0.3);
ecarrick 27:2bd737c0a8af 399 ledb = 0;
ecarrick 27:2bd737c0a8af 400 // blink green three times to indicate full boot
ecarrick 27:2bd737c0a8af 401 ledg = 1; wait(0.3);ledg = 0;
ecarrick 27:2bd737c0a8af 402 wait(0.3); ledg = 1; wait(0.3);
ecarrick 27:2bd737c0a8af 403 ledg = 0; wait(0.3);ledg = 1;
ecarrick 27:2bd737c0a8af 404 wait(0.3); ledg = 0;
ecarrick 25:2e95a5731412 405
ecarrick 25:2e95a5731412 406 while(1){
ecarrick 25:2e95a5731412 407 if(updateAccessLog){
ecarrick 25:2e95a5731412 408 update_log(accessLog);
ecarrick 25:2e95a5731412 409 updateAccessLog = false;
ecarrick 25:2e95a5731412 410 }
ecarrick 25:2e95a5731412 411
ecarrick 25:2e95a5731412 412 if(saveToFileFlag){
ecarrick 27:2bd737c0a8af 413 pc.printf("\r\nSAVING TO FILE\r\n");
ecarrick 25:2e95a5731412 414 save_to_file();
ecarrick 25:2e95a5731412 415 saveToFileFlag = false;
ecarrick 25:2e95a5731412 416 }
ecarrick 25:2e95a5731412 417
ecarrick 27:2bd737c0a8af 418 wait(1);
ecarrick 25:2e95a5731412 419 //sleep();
ecarrick 25:2e95a5731412 420
ecarrick 25:2e95a5731412 421 }
ecarrick 25:2e95a5731412 422
pshabbaki3 12:22444d5f5920 423 }
pshabbaki3 12:22444d5f5920 424
pshabbaki3 12:22444d5f5920 425