/***************************************************************************** Function: HTTP_IO_RESULT HTTPExecutePost(void) This function processes every GET request from the pages. ***************************************************************************/ HTTP_IO_RESULT HTTPExecutePost(void) { // Resolve which function to use and pass along BYTE filename[20]; // Load the file name // Make sure BYTE filename[] above is large enough for your longest name MPFSGetFilename(curHTTP.file, filename, sizeof(filename)); return HTTP_IO_DONE; }
/**************************************************************************** FUNCTION HTTP_IO_RESULT HTTPExecuteGet(void) This function processes every GET request from the pages. In the example, it processes only the leds.cgi function, but you can add code to process other GET requests. *****************************************************************************/ HTTP_IO_RESULT HTTPExecuteGet(void) { BYTE *ptr; BYTE filename[20]; // STEP #1: // The function MPFSGetFilename retrieves the name of the requested cgi, // in this case "leds.cgi" and puts it inside the filename variable. // Make sure BYTE filename[] above is large enough for your longest name MPFSGetFilename(curHTTP.file, filename, 20); // STEP #2: // Handling of the cgi requests, in this case we have only "leds.cgi" but // it would be possible to have any other cgi request, depending on the webpage if(!memcmp(filename, "leds.cgi", 8)) // Is the requested file name "leds.cgi"? { // STEP #3: // The complete request is contained inside the system variable curHTTP.data. // Using the function HTTPGetArg is possible to read the arguments // of the cgi request from curHTTP.data. In this case we are reading the // argument "led" from the request "leds.cgi?led=x" and we assign it to ptr. ptr = HTTPGetArg(curHTTP.data, (BYTE *)"led"); // The requested led is toggled switch(*ptr) { case '0': IOPut(p4, toggle); REGTOREAD = CONFIG; break; case '1': IOPut(p6, toggle); REGTOREAD = AWATT; break; case '2': IOPut(p17, toggle); break; case '3': IOPut(p19, toggle); break; case '4': IOPut(p21, toggle); break; } } return HTTP_IO_DONE; }
/***************************************************************************** Function: HTTP_IO_RESULT HTTPExecutePost(void) Internal: See documentation in the TCP/IP Stack API or HTTP2.h for details. ***************************************************************************/ HTTP_IO_RESULT HTTPExecutePost(void) { // Resolve which function to use and pass along BYTE filename[20]; // Load the file name // Make sure BYTE filename[] above is large enough for your longest name MPFSGetFilename(curHTTP.file, filename, sizeof(filename)); /******************************************/ // If it's the configure.htm page, use settings to reconfigure wifi settings /******************************************/ #if defined(STACK_USE_EZ_CONFIG) if(!memcmppgm2ram(filename, "configure.htm", 13)) return HTTPPostWifiConfig(); #endif return HTTP_IO_DONE; }
/**************************************************************************** FUNCTION HTTP_IO_RESULT HTTPExecuteGet(void) This function processes every GET request from the pages. In the example, it processes only the leds.cgi function, but you can add code to process other GET requests. *****************************************************************************/ HTTP_IO_RESULT HTTPExecuteGet(void) { // Not used yet -> BYTE *ptr; BYTE filename[20]; // STEP #1: // The function MPFSGetFilename retrieves the name of the requested cgi, // in this case "leds.cgi" and puts it inside the filename variable. // Make sure BYTE filename[] above is large enough for your longest name MPFSGetFilename(curHTTP.file, filename, 20); // STEP #2: // Handling of the cgi requests, in this case we have only "leds.cgi" but // it would be possible to have any other cgi request, depending on the webpage // TODO: insert here cgi request file handling (see webserver example for further info) return HTTP_IO_DONE; }
/***************************************************************************** Function: HTTP_IO_RESULT HTTPExecutePost(void) This function processes every POST request from the pages. ***************************************************************************/ HTTP_IO_RESULT HTTPExecutePost(void) { // Resolve which function to use and pass along BYTE filename[20]; int len; // Load the file name // Make sure BYTE filename[] above is large enough for your longest name MPFSGetFilename(curHTTP.file, filename, sizeof(filename)); while(curHTTP.byteCount) { // Check for a complete variable len = TCPFind(sktHTTP, '&', 0, FALSE); if(len == 0xffff) { // Check if is the last post, otherwise continue in the loop if( TCPIsGetReady(sktHTTP) == curHTTP.byteCount) len = curHTTP.byteCount - 1; else { return HTTP_IO_NEED_DATA; // No last post, we need more data } } if(len > HTTP_MAX_DATA_LEN - 2) { // Make sure we don't overflow curHTTP.byteCount -= TCPGetArray(sktHTTP, (BYTE*)String_post, len+1); continue; } len = TCPGetArray(sktHTTP,curHTTP.data, len+1); curHTTP.byteCount -= len; curHTTP.data[len] = '\0'; HTTPURLDecode(curHTTP.data); // NETWORK TYPE SELECTION: ADHOC/INFRASTRUCTURE/SOFTAP(WIFI G only) if(memcmppgm2ram(curHTTP.data,(ROM void*)"NETTYPE", 7) == 0) { memcpy(String_post,(void*)&curHTTP.data[8], len-8); WFSetParam(NETWORK_TYPE, String_post); } // DHCP CLIENT ENABLING/DISABLING else if(memcmppgm2ram(curHTTP.data,(ROM void*)"DHCPCL", 6) == 0) { memcpy(String_post,(void*)&curHTTP.data[7], len-7); if (String_post [0] == 'd') WFSetParam(DHCP_ENABLE , DISABLED); else WFSetParam(DHCP_ENABLE , ENABLED); } // IP ADDRESS OF THE DEVICE else if(memcmppgm2ram(curHTTP.data,(ROM void*)"IPADDR", 6) == 0) { memcpy(String_post,(void*)&curHTTP.data[7], len-7); WFSetParam(MY_IP_ADDR, String_post); } // SUBNET MASK else if(memcmppgm2ram(curHTTP.data,(ROM void*)"SUBNET", 6) == 0) { memcpy(String_post,(void*)&curHTTP.data[7], len-7); WFSetParam(SUBNET_MASK, String_post); } // DEFAULT GATEWAY else if(memcmppgm2ram(curHTTP.data,(ROM void*)"GATEWAY", 7) == 0) { memcpy(String_post,(void*)&curHTTP.data[8], len-8); WFSetParam(MY_GATEWAY, String_post); } // DNS SERVER #1 else if(memcmppgm2ram(curHTTP.data,(ROM void*)"DNS1", 4) == 0) { memcpy(String_post,(void*)&curHTTP.data[5], len-5); WFSetParam(PRIMARY_DNS, String_post); } // DNS SERVER #2 else if(memcmppgm2ram(curHTTP.data,(ROM void*)"DNS2", 4) == 0) { memcpy(String_post,(void*)&curHTTP.data[5], len-5); WFSetParam(SECONDARY_DNS, String_post); } // SSID else if(memcmppgm2ram(curHTTP.data,(ROM void*)"SSID", 4) == 0) { memcpy(String_post,(void*)&curHTTP.data[5], len-5); WFSetParam(SSID_NAME, String_post); } // SECURITY TYPE else if(memcmppgm2ram(curHTTP.data,(ROM void*)"SECTYPE", 7) == 0) { memcpy(String_post,(void*)&curHTTP.data[8], len-8); if (String_post[2] == 'E') { security = 0; WFSetSecurity(WF_SECURITY_OPEN, "", 0, 0); ParamSet = TRUE; } else if (String_post[2] == 'A') { if (String_post[3] == '2') security = 5; else security = 3; } else if (String_post[2] == 'P') { if (String_post[3] == '4') security = 1; else security = 2; } } // ---------- SECURITY KEY AND PASSWORD ---------- // WEP40 KEY else if (memcmppgm2ram(curHTTP.data,(ROM void*)"WEP40KEY4", 9) == 0) { if (security == 1) { if (len > 10) { int j = 0, j1 = 0; WORD_VAL dummy; for ( j=0; j<40; j=j+2) { memcpy(String_post,(void*)&curHTTP.data[10+j], 2); dummy.v[1] = String_post[0]; dummy.v[0] = String_post[1]; PassKey[j1] = hexatob(dummy); j1++; } PassKey[j1]= '\0'; security = 1; } } } // WEP40 KEY INDEX else if (memcmppgm2ram(curHTTP.data,(ROM void*)"WEP40KEYID", 10) == 0) { memcpy(String_post,(void*)&curHTTP.data[11], len-11); int k_index; k_index = atoi(String_post); k_index--; if (security == 1) { WFSetSecurity(WF_SECURITY_WEP_40, PassKey, 20, k_index); ParamSet = TRUE; } } // WEP104 KEY INDEX else if (memcmppgm2ram(curHTTP.data,(ROM void*)"WEP104KEY", 9) == 0) { if (security == 2) { int j = 0, j1 = 0; WORD_VAL dummy; for ( j=0; j<32; j=j+2) { memcpy(String_post,(void*)&curHTTP.data[10+j], 2); dummy.v[1] = String_post[0]; dummy.v[0] = String_post[1]; PassKey[j1] = hexatob(dummy); j1++; } PassKey[j1]= '\0'; WFSetSecurity(WF_SECURITY_WEP_104, PassKey, 16, 0); ParamSet = TRUE; } } // WPA WITH PASSPHRASE else if (memcmppgm2ram(curHTTP.data,(ROM void*)"WPAPASS", 7) == 0) { if (security == 3) { if (len > 10) { memcpy(String_post,(void*)&curHTTP.data[8], len-8); WFSetSecurity(WF_SECURITY_WPA_WITH_PASS_PHRASE, String_post, len-9, 0); ParamSet = TRUE; } } } // WPA WITH PASSKEY else if (memcmppgm2ram(curHTTP.data,(ROM void*)"WPAKEY", 6) == 0) { if (security == 3) { if (len > 10) { int j = 0, j1 = 0; WORD_VAL dummy; for ( j=0; j<64; j=j+2) { memcpy(String_post,(void*)&curHTTP.data[7+j], 2); dummy.v[1] = String_post[0]; dummy.v[0] = String_post[1]; PassKey[j1] = hexatob(dummy); j1++; } PassKey[j1]= '\0'; WFSetSecurity(WF_SECURITY_WPA_WITH_KEY, PassKey, 32, 0); ParamSet = TRUE; } } } // WPA2 WITH PASSPHRASE else if (memcmppgm2ram(curHTTP.data,(ROM void*)"WPA2PASS", 8) == 0) { if (len > 10) { memcpy(String_post,(void*)&curHTTP.data[9], len-9); WFSetSecurity(WF_SECURITY_WPA2_WITH_PASS_PHRASE, String_post, len-9, 0); ParamSet = TRUE; } } // WPA2 WITH PASSKEY else if (memcmppgm2ram(curHTTP.data,(ROM void*)"WPA2KEY", 7) == 0) { if (len > 10) { int j = 0, j1 = 0; WORD_VAL dummy; for ( j=0; j<64; j=j+2) { memcpy(String_post,(void*)&curHTTP.data[8+j], 2); dummy.v[1] = String_post[0]; dummy.v[0] = String_post[1]; PassKey[j1] = hexatob(dummy); j1++; } PassKey[j1]= '\0'; WFSetSecurity(WF_SECURITY_WPA2_WITH_KEY, PassKey, 32, 0); ParamSet = TRUE; } } /* EMAIL */ else if (memcmppgm2ram(curHTTP.data,(ROM void*)"TXEMAIL", 7) == 0) { memcpy(MY_EMAIL,(void*)&curHTTP.data[8], len-8); } else if (memcmppgm2ram(curHTTP.data,(ROM void*)"USEREMAIL", 9) == 0) { memcpy(MY_EMAIL_USER,(void*)&curHTTP.data[10], len-10); } else if (memcmppgm2ram(curHTTP.data,(ROM void*)"PASSEMAIL", 9) == 0) { memcpy(MY_EMAIL_PASS,(void*)&curHTTP.data[10], len-10); } else if (memcmppgm2ram(curHTTP.data,(ROM void*)"SERVER", 6) == 0) { memcpy(MY_SMTP,(void*)&curHTTP.data[7], len-7); } else if (memcmppgm2ram(curHTTP.data,(ROM void*)"PORT", 4) == 0) { memcpy(MY_SMTP_PORT,(void*)&curHTTP.data[5], len-5); } else if (memcmppgm2ram(curHTTP.data,(ROM void*)"SUBJ", 4) == 0) { memcpy(EMAIL_SUBJECT,(void*)&curHTTP.data[5], len-5); } else if (memcmppgm2ram(curHTTP.data,(ROM void*)"TEXT", 4) == 0) { memcpy(EMAIL_BODY,(void*)&curHTTP.data[5], len-5); } else if (memcmppgm2ram(curHTTP.data,(ROM void*)"RXEMAIL", 7) == 0) { memcpy(EMAIL_DEST,(void*)&curHTTP.data[8], len-8); } /* ALARM */ else if (memcmppgm2ram(curHTTP.data,(ROM void*)"GMT", 3) == 0) { memcpy(GMT,(void*)&curHTTP.data[4], len-4); } else if (memcmppgm2ram(curHTTP.data,(ROM void*)"START", 5) == 0) { memcpy(start_string,(void*)&curHTTP.data[6], len-6); } else if (memcmppgm2ram(curHTTP.data,(ROM void*)"STOP", 4) == 0) { memcpy(stop_string,(void*)&curHTTP.data[5], len-5); } } return HTTP_IO_DONE; }
/***************************************************************************** Function: HTTP_IO_RESULT HTTPExecuteGet(void) Internal: See documentation in the TCP/IP Stack API or HTTP2.h for details. ***************************************************************************/ HTTP_IO_RESULT HTTPExecuteGet(void) { BYTE *ptr; BYTE filename[20]; // Load the file name // Make sure BYTE filename[] above is large enough for your longest name MPFSGetFilename(curHTTP.file, filename, 20); /******************************************/ // If it's the leds.cgi LED update file /******************************************/ if(!memcmppgm2ram(filename, "leds.cgi", 8)) { // Determine which LED to toggle ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led"); // Toggle the specified LED switch(*ptr) { case '1': LED1_INV(); break; case '2': LED2_INV(); break; default: break; } } /******************************************/ // If it's the wifi.xml scan file /******************************************/ if(!memcmppgm2ram(filename, "wifi.xml", 8)) { ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"scan"); if (ptr != NULL) { if(IS_SCAN_IN_PROGRESS(SCANCXT.scanState)) return HTTP_IO_WAITING; if(IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) return HTTP_IO_DONE; // Start Scan Request if (WFStartScan() == WF_SUCCESS) { SCAN_SET_DISPLAY(SCANCXT.scanState); SCANCXT.displayIdx = 0; return HTTP_IO_WAITING; } } } else { ; } return HTTP_IO_DONE; }
/* Every request to the board is a GET request */ HTTP_IO_RESULT HTTPExecuteGet(void) { BYTE filename[12]; /* loads the filename - max length of file name is 12 characters */ MPFSGetFilename(curHTTP.file, filename, 12); /* board.cgi does not require any parameters so return immediatelly */ if (!memcmppgm2ram(filename, "board.cgi",9)) { return HTTP_IO_DONE; } #if defined(FW_UPGRADE_USE_OTA) if (!memcmppgm2ram(filename, "upgrade.cgi",11)) { ProcessUpgradeCommand(); return HTTP_IO_DONE; } #endif /* all other pages require at least the channel number parameter */ int channelNo = GetChannelNo(); if (channelNo == 0) return HTTP_IO_DONE; /* checks if the filename is known and the channel type requested coresponds with the channel */ if(!memcmppgm2ram(filename, "blinds.cgi", 10) && (channels[channelNo - 1].channelType == BLINDS)) { ProcessBlindsCommand(channelNo); return HTTP_IO_DONE; } if (!memcmppgm2ram(filename, "onoff.cgi", 9) && ((channels[channelNo - 1].channelType == ONOFF_W_KEY) || (channels[channelNo - 1].channelType == ONOFF_W_BUTTON))) { ProcessOnOffCommand(channelNo); return HTTP_IO_DONE; } if (!memcmppgm2ram(filename, "onoffbtn.cgi", 12) && (channels[channelNo - 1].channelType == ONOFF_BUTTON)) { ProcessOnOffCommand(channelNo); return HTTP_IO_DONE; } if (!memcmppgm2ram(filename, "onoffcmd.cgi", 12) && (channels[channelNo - 1].channelType == ONOFF_COMMAND)) { ProcessOnOffCommand(channelNo); return HTTP_IO_DONE; } if (!memcmppgm2ram(filename, "onoffpls.cgi", 12) && (channels[channelNo - 1].channelType == ONOFF_PULSE)) { ProcessOnOffCommand(channelNo); return HTTP_IO_DONE; } return HTTP_IO_DONE; }
/* POST method is used only for setting the WiFi parameters in the board */ HTTP_IO_RESULT HTTPExecutePost(void) { BYTE name[20]; WORD len; char buf[100]; // Load the file name // Make sure BYTE filename[] above is large enough for your longest name MPFSGetFilename(curHTTP.file, name, 20); if(strcmppgm2ram((char*)name, (ROM char*)"connecting.htm") != 0) return HTTP_IO_DONE; // Loop while data remains while(curHTTP.byteCount) { // Check for a complete variable len = TCPFind(sktHTTP, '&', 0, FALSE); if(len == 0xffff) {// Check if this is the last one if(TCPIsGetReady(sktHTTP) == curHTTP.byteCount) len = curHTTP.byteCount - 1; else // Wait for more data { return HTTP_IO_NEED_DATA; } } // Make sure we don't overflow if(len > HTTP_MAX_DATA_LEN-2) { curHTTP.byteCount -= TCPGetArray(sktHTTP, NULL, len+1); continue; } // Read the next variable and parse HTTPReadPostValue((BYTE*)buf,100); // Figure out which variable it is if(memcmppgm2ram(buf, (ROM void*)"host", 4) == 0) { strcpy(config_parms.MyHost,&buf[5]); } else if(memcmppgm2ram(buf, (ROM void*)"ssid", 4) == 0) { strcpy(config_parms.MySSID,&buf[5]); } else if(memcmppgm2ram(buf, (ROM void*)"select1", 7) == 0) { if (memcmppgm2ram(&buf[8],(ROM void*)"adhoc", 5) == 0) { config_parms.networkType = (BYTE)'A'; } else if (memcmppgm2ram(&buf[8],(ROM void*)"infra", 5) == 0) { config_parms.networkType = (BYTE)'I'; } } else if(memcmppgm2ram(buf, (ROM void*)"select2", 7) == 0) { if (memcmppgm2ram(&buf[8],(ROM void*)"auto", 4) == 0) { config_parms.SecurityMode = WF_SECURITY_WPA_AUTO_WITH_KEY; } else if (memcmppgm2ram(&buf[8],(ROM void*)"open", 4) == 0) { config_parms.SecurityMode = WF_SECURITY_OPEN; } } else if(memcmppgm2ram(buf, (ROM void*)"pphrase", 7) == 0) { strcpy((char *)config_parms.SecurityPhrase,&buf[8]); } else if(memcmppgm2ram(buf, (ROM void*)"chkbx", 5) == 0) { if (memcmppgm2ram(&buf[6],(ROM void*)"on", 2) == 0) { config_parms.UseKey = TRUE; } else { config_parms.UseKey = FALSE; } } else if(memcmppgm2ram(buf, (ROM void*)"pkey", 4) == 0) { strcpy((char *)config_parms.SecurityKey, &buf[5]); } else if(memcmppgm2ram(buf, (ROM void*)"ip", 2) == 0) { strcpy(config_parms.MyIPAddr,&buf[3]); } else if(memcmppgm2ram(buf, (ROM void*)"subnetmask", 10) == 0) { strcpy(config_parms.MyMask,&buf[11]); } else if(memcmppgm2ram(buf, (ROM void*)"gateway", 7) == 0) { strcpy(config_parms.MyGateway,&buf[8]); } else if(memcmppgm2ram(buf, (ROM void*)"pdns", 4) == 0) { strcpy(config_parms.PrimaryDNSServer,&buf[5]); } else if(memcmppgm2ram(buf, (ROM void*)"sdns", 4) == 0) { strcpy(config_parms.SecondaryDNSServer,&buf[5]); } else if(memcmppgm2ram(buf, (ROM void*)"submit", 6) == 0) // see which button was pressed { config_parms.flag = 1; } else if(memcmppgm2ram(buf, (ROM void*)"connect", 7) == 0) // see which button was pressed { config_parms.flag = 2; } } if (config_parms.flag == 1) { SaveWiFiStateToFlash(); CheckAndWriteCustom(); config_parms.DoConnectFlag = FALSE; config_parms.flag = 0; } else if (config_parms.flag == 2) { SaveWiFiStateToFlash(); CheckAndWriteCustom(); config_parms.DoConnectFlag = TRUE; config_parms.flag = 0; } return HTTP_IO_DONE; }