For Wifi personal security mode. It is always cumbersome to change the password whenever there is a breach in the network. and even more annoying is to distribute the passwords to the clients/guests. WifiFlexManager is a project that can change the password (with a random predefined length string) whenever the admin sends a specific IR code (through android app) and can retrieve the current password or the connected users (Through Bluetooth screen). So as a client who wants to get connected to the router, you only need to point your phone's IR towards the mbed and press a button, and the current password will be shown at your phone's screen.
Dependencies: EthernetInterface HTTPServer RemoteIR SDFileSystem mbed-rpc mbed-rtos mbed
Diff: main.cpp
- Revision:
- 1:79a18ad6eeb5
- Parent:
- 0:c08dc0b2963b
- Child:
- 2:17304882739c
--- a/main.cpp Tue Apr 28 06:55:14 2015 +0000 +++ b/main.cpp Tue Apr 28 20:27:18 2015 +0000 @@ -29,7 +29,7 @@ // Start RPC #include "RPCVariable.h" int Request = 0; -int Learn = 0; +int Learn = 1; char Learn_name0; char Learn_name1; char Learn_name2; @@ -59,6 +59,9 @@ Serial pc(USBTX, USBRX, "pc"); + +Serial HC06(PTC15,PTC14); // BT TX,RX + // Instantiate a HTTPServer to handle incoming requests HTTPServer svr; // Instantiate a local file system handler named 'local' which will be used later to access files on the mbed. @@ -70,7 +73,7 @@ const char* ECHO_SERVER_ADDRESS = "192.168.2.1"; const int ECHO_SERVER_PORT = 23; void cursor(char *check, bool sd,char c); -void lsusrsf(void); //Function that calls the function that lists users +//void lsusrsf(void); //Function that calls the function that lists users TCPSocketConnection socket; void telnet_task(int taskNumber); @@ -80,21 +83,23 @@ char cursr[]="WRT:~# "; char username[]=" root\r\n"; char password[]="password\r\n"; -char chngpwd[]="nvram set wl0_wpa_psk=random\r\n"; +char chngpwd[]="nvram set wl_wpa_psk=PleaseVote1forkamoona\r\n"; char getusers[]="cat /proc/net/arp\r\n"; -char getpwd[]="nvram get wl0_wpa_psk\r\n"; +char getpwd[]="nvram get wl_wpa_psk\r\n"; int main() { // Telnet related //Ticker listusers; //Timer to repeatedly fetch the users connected to the Router! // SDFileSystem sd(PTE3,PTE1,PTE2,PTE4, "sd"); // the pinout on the mbed + HC06.baud(9600); + HC06.printf("Bluetooth connected. Please send an IR command!\n"); - printf("Setting up SD card...\n \r"); + printf("Bluetooth connected. Please send an IR command!\n"); // mkdir("/sd/mydir", 0777); mkdir("/sd/Wifi", 0777); - printf("Wifi directory created!\n"); + printf("Created the /sd/Wifi directory in SD card\n"); FILE *fp = fopen("/sd/Wifi/sdtest.txt", "w"); @@ -104,10 +109,12 @@ fprintf(fp, "Opened SD for to test!"); fclose(fp); - printf("Wiring successful!\n"); + printf("Printed in /sd/Wifi/sdtest.txt successfullly !\n"); EthernetInterface eth; - eth.init ("192.168.137.9","255.255.255.0","0.0.0.0"); + led1 = 1; + led2 = 1; + eth.init ("192.168.2.9","255.255.255.0","0.0.0.0"); eth.connect(); printf("IP Address is %s\n", eth.getIPAddress()); @@ -116,8 +123,8 @@ //listusers.attach(&lsusrsf, 300.0); // IR Related - led1 = 1; - led2 = 1; +// led1 = 1; +// led2 = 1; printf("Setting up Apache...\n \r"); // HTTPFsRequestHandler::mount("/sd/local", "/"); @@ -164,7 +171,7 @@ int bitlength1; int bitlength2; char tempstr[3]; - char bufc1[2]; + char bufc1[2]; //For IR command comparison RemoteIR::Format format; printf("Constructor Initialized\n"); memset(buf1, 0x00, sizeof(buf1)); @@ -204,22 +211,25 @@ if (strcmp(bufc1,"4B") == 0) { printf("Running task 0 ...\n"); + led1 = 1; telnet_task(0); } - else if (strcmp(bufc1,"F3") == 0) + else if (strcmp(bufc1,"71") == 0) { printf("Running task 1 ...\n"); + led1 = 1; telnet_task(1); } - else if (bufc1 == "E3") + else if (strcmp(bufc1,"E3") == 0) { - printf("Running task 0 ...\n"); + printf("Running task 2 ...\n"); + led1 = 1; telnet_task(2); } } // Reset led1 = 1; - Learn = 0; + // Learn = 0; // Set up the variables sprintf(tuple_name, "%c%c%c%c%c%c%c%c%c%c", Learn_name0,Learn_name1,Learn_name2,Learn_name3,Learn_name4,Learn_name5,Learn_name6,Learn_name7,Learn_name8,Learn_name9); sprintf(tuple_code, "%X", buf1); @@ -283,6 +293,9 @@ void cursor(char *check, bool sd,char c) { printf("Check = %s\n", check); + printf("sd = %d\n", sd); + printf("c = %c\n", c); + char BTbuf[100], title[100]; char shift[]=" "; // 7 Characters string char buf[] = " "; bool res=false; @@ -301,8 +314,12 @@ { int n = socket.receive(buf, 1); if (sd) - fprintf(fp, "%c",buf[0]); + { + fprintf(fp, "%c",buf[0]); + + } printf("%c",buf[0]); + HC06.printf("%c",buf[0]); for (int k=0;k<6;k++) shift[k]=shift[k+1]; shift[6]=buf[0]; @@ -315,15 +332,25 @@ if (sd) { printf("Closing file on SD...\n"); + + fgets(BTbuf, sizeof BTbuf, fp); /* expect string like "title: TITLE WITH SPACES" */ + sscanf(buf, "%*s %99[^\n]", title); + + HC06.printf("%s",BTbuf); + printf("%s",BTbuf); + HC06.printf("%s",title); + printf("%s",title); + fclose(fp); } + } -void lsusrsf(void) //callstring is a sting passed to be sent by the TCP socket +/*void lsusrsf(void) //callstring is a sting passed to be sent by the TCP socket { socket.send_all("cat /proc/net/arp\r\n", sizeof("cat /proc/net/arp\r\n") - 1); printf("Users listed in memory card: \n Exited lsusersf function, after \n"); -} +} */ void telnet_task(int taskNumber) { @@ -347,23 +374,29 @@ printf("Sent password!\n"); printf("Entering function: \n"); - cursor(&cursr[0],true,'u'); + cursor(&cursr[0],false,'a'); printf("Exiting function: \n"); switch (taskNumber) { case 0: // Get users + printf("Entering Case 0 function: \n"); socket.send_all(getusers, sizeof(getusers) - 1); - cursor(&cursr[0],false,'a'); + cursor(&cursr[0],true,'u'); + break; case 1: // Change password + printf("Entering Case 1 function: \n"); socket.send_all(chngpwd, sizeof(chngpwd) - 1); + cursor(&cursr[0],false,'a'); printf("Sent chngpwd!\n"); break; case 2: // Get password - socket.send_all(getpwd, sizeof(getpwd) - 1); - printf("Sent chngpwd!\n"); + printf("Entering Case 2 function: \n"); + socket.send_all(getpwd, sizeof(getpwd) - 1); + cursor(&cursr[0],true,'p'); + printf("getpwd!\n"); break; } socket.close();