c - The use of "if (strcmp(URL, "/") == 0)" in Arduino network sketches -
i'm trying understand "if (strcmp(url, "/") == 0)" line in arduino sketch below (see sendmypage function halfway down):
#include <wiserver.h> #define wireless_mode_infra 1 #define wireless_mode_adhoc 2 #define aref_voltage 5 const int tmppin = a0; int tmpreading = 0; // wireless configuration parameters ---------------------------------------- unsigned char local_ip[] = {192,168,31,199}; // ip address of wishield unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway ip address unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask local network const prog_char ssid[] progmem = {"mercury_7f3f70"}; // max 32 bytes unsigned char security_type = 3; // 0 - open; 1 - wep; 2 - wpa; 3 - wpa2 // wpa/wpa2 passphrase const prog_char security_passphrase[] progmem = {"11163127"}; // max 64 characters // wep 128-bit keys // sample hex keys prog_uchar wep_keys[] progmem = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // key 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // key 1 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // key 2 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // key 3 }; // setup wireless mode // infrastructure - connect ap // adhoc - connect wifi device unsigned char wireless_mode = wireless_mode_infra; unsigned char ssid_len; unsigned char security_passphrase_len; // end of wireless configuration parameters ---------------------------------------- float testtmp (void){ tmpreading = analogread (tmppin); float voltage = tmpreading * aref_voltage; voltage /= 1023; float tmpc = (voltage - 0.5) * 100; return tmpc; } // our page serving function generates web pages **boolean sendmypage(char* url)** { // check if requested url matches "/" **if (strcmp(url, "/") == 0) {** // use wiserver's print , println functions write out page content float tmpc = testtmp (); wiserver.print("<html>"); // wiserver.print("hello world!"); wiserver.print(tmpc); wiserver.print("</html>"); // url recognized return true; } // url not found return false; } void setup() { // initialize wiserver , have use sendmypage function serve pages wiserver.init(sendmypage); // enable serial output , ask wiserver generate log messages (optional) serial.begin(57600); wiserver.enableverbosemode(true); } void loop(){ // run wiserver wiserver.server_task(); delay(10); }
it seems function accepts url argument, , sends data page using wisever.print if url valid. how 'if (strcmp(url, "/") == 0)' determine if url good?
i've seen kind of check before, don't understand how works.
thanks!
the line:
if (strcmp(url, "/") == 0) {
is testing see if string url matches string literal "/". if so, returns 0
.
note, if wanted test see if string url
contained "/", use:
if (strstr(url, "/") != null) {
regarding but how 'if (strcmp(url, "/") == 0)' determine if url good?
not. more needed single character determine if url good, appears comment, written, not expressing code block does.
Comments
Post a Comment