Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 3:a0b26799134f, committed 2016-05-29
- Comitter:
- gauresh2798
- Date:
- Sun May 29 22:16:29 2016 +0000
- Parent:
- 2:d5c9337fdce1
- Commit message:
- Final and working (goes to ap mode if no wifi server found, then sets ssid and password from user input, and finally joins the server to host page )(add ons: power cycle or reset will not remove the ssid stored in esp8266, connects automatically)
Changed in this revision
--- a/EDUVANCE_WIFI_SHIELD.cpp Sat May 28 15:46:20 2016 +0000 +++ b/EDUVANCE_WIFI_SHIELD.cpp Sun May 29 22:16:29 2016 +0000 @@ -4,18 +4,19 @@ //CONSTANTS FOR MODES #define STATIONMODE 10 #define APMODE 20 - +int AP_LOGIN =0; +int STATION_LOGIN= 0; Serial pc(USBTX, USBRX);// COMPUTER DISPLAY Serial esp(PTE0, PTE1); //ESP8266 SERIAL extern int modeselector=0; char ssid[32]; char pwd[32]; - +bool aplogin=false; const char ch = 's'; -char *getreq,*ssid_new,*pass_new,*left,*right; +char *getreq,*ssid_new,*pass_new,*left,*right,*pad_string; //ADD DEVICES,PINS AND LEDS HERE DigitalOut led1(LED_RED); - +int port=8266; @@ -40,7 +41,7 @@ char webbuff[4096]; // Currently using 1986 characters, Increase this if more web page data added int mode_sel=0; -int port ; // set server port + // set server port int SERVtimeout =5; // set server timeout in seconds incase link breaks.void callback(void); //TAKES SSID, PASSWORD AND PORT ADDRESS @@ -51,7 +52,7 @@ pc.printf("\r\n SSID is %s, PASSWORD is %s, PORT number is %d \r\n",ssid_f,pass_f,port_f); strcpy(ssid,ssid_f); strcpy(pwd,pass_f); - port=port_f; + // port=8266; } //SETS BAUD RATE @@ -361,7 +362,18 @@ sprintf(webdata," http://%s:%d", IP, port); pc.printf(webdata); } +void disp_ssid(void){ + pc.printf("\n\r++++++++++ DISPLAY CURRENT SSID ++++++++++\r\n"); + strcpy(cmdbuff,"AT+CWJAP?\r\n"); + timeout=8000; + getcount=1000; + SendCMD(); + getreply(); + pc.printf("%s\r\n",replybuff); + + + } void finishup(void){ //END PART bufflen=200;count=0; @@ -372,6 +384,7 @@ int startserver(void){ + pc.printf("++++++++++++++++++++++++ START MAIN SERVER ++++++++++++++++++++++\r\n"); ATcheck(); ATReset(); StationModeSet(); @@ -384,6 +397,7 @@ SendCMD(); getreply(); pc.printf("%s\r\n",replybuff); + /* if (strstr(replybuff, ssid) != NULL) { t2.reset();t2.start(); @@ -393,7 +407,8 @@ t2.reset();t2.start(); return 20; } - + */ + return 0; } @@ -421,15 +436,27 @@ } -void StationConfig(void){ - pc.printf("\n\r------------------- IN THE STATION MODE -------------------\r\n"); - StationModeSet(); +void StationConfig_NO_SSID_NEED(void){ + + pc.printf("\n\r------------------- IN THE STATION MODE(MATCHING SSID) -------------------\r\n"); + Commtype(); + StartServer_AT(); + getIP(); + finishup(); + + } + +void StationConfig_SSID_NEED(void){ + pc.printf("\n\r------------------- IN THE STATION MODE(NON MATCHED SSID) -------------------\r\n"); + StationModeSet(); ConnectWifiServer(); Commtype(); StartServer_AT(); getIP(); finishup(); + } + void ApConfig(void){ pc.printf("\n\r--------------------- IN THE AP MODE -----------------------\r\n"); ApModeSet(); @@ -437,6 +464,7 @@ StartServer_AT(); getIP(); finishup(); + modeselector=20; } void request_fetch_station(void){ @@ -514,7 +542,86 @@ // wait(5); closeserver_AT(); modeselector=10; - StationConfig(); + StationConfig_SSID_NEED(); request_fetch_station(); } + } + + + +char* rtrim(char* string, char junk) +{ + char* original = string + strlen(string); + while(*--original == junk); + *(original + 1) = '\0'; + return string; +} +char* ltrim(char *string, char junk) +{ + char* original = string; + char *p = original; + int trimmed = 0; + do + { + if (*original != junk || trimmed) + { + trimmed = 1; + *p++ = *original; + } + } + while (*original++ != '\0'); + return string; +} + void data_sep_ssid(char replyback[],char ch){ + + + char *reply; + reply = strchr(replyback, ch); + pad_string = getname(reply,",",1); + printf( "\n\r ssid is %s\n\r", pad_string ); + + + } +void verifyssid(void){ + char *newd,*readb; + + //GET INITIAL ACCESS + ATReset(); + StationModeSet(); + pc.printf("++++++++++++++++++++++++ INITIAL Listing Access ESP ++++++++++++++++++++++\r\n"); + strcpy(cmdbuff,"AT+CWLAP\r\n"); + timeout=8000; + getcount=1000; + SendCMD(); + getreply(); + pc.printf("%s\r\n",replybuff); + newd=replybuff; + //RECEIVE STORED SSID + disp_ssid(); + int mo; + if (strstr(replybuff, "No AP") != NULL){ + //DEVICE NEWLY INSTALLED + pc.printf("++++++++++++++++++++++++ DEVICE NEWLY INSTALLED -> REGISTERATION ++++++++++++++++++++++\r\n"); + mo=startserver(); + t2.reset();t2.start(); + ApConfig(); + } + else{ + data_sep_ssid(replybuff,'"'); + printf("The final ssid is %s\n\r", ltrim(rtrim( pad_string, '"'), '"')); + readb=ltrim(rtrim( pad_string, '"'), '"'); + + + if (strstr(newd, readb) != NULL) { + pc.printf("++++++++++++++++++++++++ SSID PRESENT ++++++++++++++++++++++\r\n"); + get_ssid_pass(readb,"",8266); + // AP_LOGIN=30; + mo=startserver(); + t2.reset();t2.start(); + StationConfig_NO_SSID_NEED(); + + modeselector=10; + } + + } } \ No newline at end of file
--- a/EDUVANCE_WIFI_SHIELD.h Sat May 28 15:46:20 2016 +0000 +++ b/EDUVANCE_WIFI_SHIELD.h Sun May 29 22:16:29 2016 +0000 @@ -16,7 +16,8 @@ void sendpage_register(void); void SendWEB(void); void sendcheck(void); -void StationConfig(void); +void StationConfig_SSID_NEED(void); +void StationConfig_NO_SSID_NEED(void); void ApConfig(void); void newcre(char webstring[]); void ATcheck(void); @@ -33,6 +34,10 @@ void setbaudrate(int baud_f); void request_fetch_station(void); void request_fetch_ap(void); - +void verifyssid(void); +void disp_ssid(void); +void data_sep_ssid(char replyback[],char ch); void closeserver_AT(void); +char* ltrim(char *string, char junk); +char* rtrim(char* string, char junk); #endif \ No newline at end of file
--- a/main.cpp Sat May 28 15:46:20 2016 +0000 +++ b/main.cpp Sun May 29 22:16:29 2016 +0000 @@ -30,24 +30,24 @@ setbaudrate(115200); //SEND THE SSID, PASSWORD AND USER DEFINED PORT ADDRESS TO THE LIBRARY - get_ssid_pass(ssid_main,pwd_main,port_main); - + //get_ssid_pass(ssid_main,pwd_main,port_main); + verifyssid(); /* START SERVER THE FUNCTION RETURNS THE VALUE 10 IF THE ABOVE GIVEN SSID IS ACTIVE NEARBY OR ELSE IT RETURNS 20. */ - modeselector=startserver(); + - if(modeselector==10){ +// if(modeselector==10){ //CONFIGUR IN STATION MODE AND GET A VALID IP ADDRESS FROM SERVER - StationConfig(); - } - else if(modeselector==20){ +// StationConfig(); +// } +// else if(modeselector==20){ //CONFIGUR IN AP MODE AND GENERATE A WIFI ACCESS POINT (HOTSPOT) WITH VALID IP ADDRESS - ApConfig(); +// ApConfig(); - } +// } //DO THIS OPERATION CONTINUOUSLY while(1){