main/ims_tcp.c
/*
 * Sends the configuration page based on the state of the global variables
 */
Sends the configuration page based on the state of the global variables
Sends the configuration page based on the state of the global variables
void sendReplyHTML(int socket){
	char sendbuf[4096] = { 0 };
	char ipbuf[20];
	char nmbuf[20];
	char gwbuf[20];
	char ripbuf0[20];
	inet_ntop(AF_INET,&globalIpInfo.localIpInfo.ip,ipbuf,20);
	inet_ntop(AF_INET,&globalIpInfo.localIpInfo.netmask,nmbuf,20);
	inet_ntop(AF_INET,&globalIpInfo.localIpInfo.gw,gwbuf,20);
	inet_ntop(AF_INET,&globalIpInfo.remotes[0].ip,ripbuf0,20);
	sprintf(sendbuf, "HTTP/1.1 200 OK\r\n"
			"Content-Type: text/html\r\n\r\n"
			"<html>\n"
			"<head>\n"
			"<title>Wifi Sensor</title>\n"
			"</head>\n"
			"<body>\n"
			"<h3>Wifi Sensor configuration</h3>\n"
			"<form action=\"\" method=\"get\">\n"
			"<p>Node ID:&nbsp;<input name=\"nodeid\" type=\"number\" min=\"0\" max=\"255\" value=\"%d\" /></p>"
			"<table border=\"0\">\n"
			"<tr><th colspan=\"2\">Local settings</th><th colspan=\"2\">UDP Remote</th></tr>\n"
			"<tr>\n"
			"<td>Local IP:</td><td><input type=\"text\" name=\"localip\" value=\"%s\" size=\"11\" maxlength=\"15\"></td>\n"
			"<td>IP address:</td><td><input type=\"text\" name=\"remoteip0\" value=\"%s\" size=\"11\" maxlength=\"15\"></td>\n"
			"</tr>\n"
			"<tr>\n"
			"<td>Netmask:</td><td><input type=\"text\" name=\"netmask\" value=\"%s\" size=\"11\" maxlength=\"15\"></td>\n"
			"<td>Local port:</td><td><input type=\"text\" name=\"localport0\" value=\"%d\" size=\"11\"></td>"
			"</tr>\n"
			"<tr><td>Gateway:</td>\n"
			"<td><input type=\"text\" name=\"gatewayip\" value=\"%s\" size=\"11\" maxlength=\"15\"></td>\n"
			"<td>Remote port:</td><td><input type=\"text\" name=\"remoteport0\" value=\"%d\" size=\"11\"></td>\n"
			"</tr>\n"
			"</table>\n"
			"<font color=\"green\">%s</font>\n"
			"<input type=\"submit\" value=\"Save\">\n"
			"</form>\n"
			"<form action=\"\" method=\"get\">\n"
			"Sensor calibration:&nbsp;\n"
			"<input type=\"hidden\" name=\"calibrate\" value=\"%s\" disabled=\"disabled\">"
			"<input type=\"submit\" value=\"%s\" disabled=\"disabled\">\n"
			"</form>\n"
			"<form action=\"\" method=\"get\">\n"
			"<p>Threshold:&nbsp;<input name=\"threshold\" type=\"number\" min=\"0\" max=\"100\" value=\"%d\"  disabled=\"disabled\" size=\"8\"/>&nbsp;%%\n"
			"<input type=\"submit\" value=\"set\" disabled=\"disabled\">\n"
			"</form>\n"
			"<form action=\"\" method=\"get\">\n"
			"Transmit raw sensor data only:&nbsp;\n"
			"<input type=\"hidden\" name=\"rawdata\" value=\"%s\" disabled=\"disabled\">"
			"<input type=\"submit\" onclick=\"rawdata\" value=\"%s\" disabled=\"disabled\">\n"
			"</form>\n"
			"<h3>Firmware update</h3>\n"
			"<form action=\"\" method=\"get\">\n"
			"Update firmware? <input type=\"checkbox\" name=\"fwupdate\"><br>To update: Start an http server on port 8070 in the directory with the new .bin file<br>(e.g. python -m SimpleHTTPServer 8070)<br>\n"
			"<br><input type=\"submit\" value=\"Update\">\n"
			"</form>\n"
			"<p></p>\n"
			"<form action=\"\"><input type=\"submit\" value=\"Refresh page\">\n"
			"</form></body></html>\r\n", nodeid, ipbuf, ripbuf0, nmbuf, globalIpInfo.remotes[0].localPort, gwbuf, globalIpInfo.remotes[0].remotePort, submitStr, calibrateStr, calibrateStr, threshold, sendRawDataStr, sendRawDataStr);
	if (send(socket, sendbuf, sizeof(sendbuf), 0) == -1) { 
		perror("send");
	}
	strncpy(submitStr, "\0", 1);
}
void sendReplyHTML ( int socket ) { char sendbuf [ 4096 ] = { 0 } ; char ipbuf [ 20 ] ; char nmbuf [ 20 ] ; char gwbuf [ 20 ] ; char ripbuf0 [ 20 ] ; inet_ntop ( AF_INET , & globalIpInfo . localIpInfo . ip , ipbuf , 20 ) ; inet_ntop ( AF_INET , & globalIpInfo . localIpInfo . netmask , nmbuf , 20 ) ; inet_ntop ( AF_INET , & globalIpInfo . localIpInfo . gw , gwbuf , 20 ) ; inet_ntop ( AF_INET , & globalIpInfo . remotes [ 0 ] . ip , ripbuf0 , 20 ) ; sprintf ( sendbuf , " \r \n " " \r \n \r \n " " \n " " \n " " \n " " \n " " \n " " \n " " \" \" \" \" \n " " \" \" \" \" \" \" \" \" \" \" " " \" \" \n " " \" \" \" \" \n " " \n " " \" \" \" \" \" \" \" \" \" \" \n " " \" \" \" \" \" \" \" \" \" \" \n " " \n " " \n " " \" \" \" \" \" \" \" \" \" \" \n " " \" \" \" \" \" \" \" \" " " \n " " \n " " \" \" \" \" \" \" \" \" \" \" \n " " \" \" \" \" \" \" \" \" \n " " \n " " \n " " \" \" \n " " \" \" \" \" \n " " \n " " \" \" \" \" \n " " \n " " \" \" \" \" \" \" \" \" " " \" \" \" \" \" \" \n " " \n " " \" \" \" \" \n " " \" \" \" \" \" \" \" \" \" \" \" \" \" \" \n " " \" \" \" \" \" \" \n " " \n " " \" \" \" \" \n " " \n " " \" \" \" \" \" \" \" \" " " \" \" \" \" \" \" \" \" \n " " \n " " \n " " \" \" \" \" \n " " \" \" \" \" \n " " \" \" \" \" \n " " \n " " \n " " \" \" \" \" \" \" \n " " \r \n " , nodeid , ipbuf , ripbuf0 , nmbuf , globalIpInfo . remotes [ 0 ] . localPort , gwbuf , globalIpInfo . remotes [ 0 ] . remotePort , submitStr , calibrateStr , calibrateStr , threshold , sendRawDataStr , sendRawDataStr ) ; if ( send ( socket , sendbuf , sizeof ( sendbuf ) , 0 ) == -1 ) { perror ( " " ) ; } strncpy ( submitStr , " \0 " , 1 ) ; }
Sends the configuration page based on the state of the global variables
Sends the configuration page based on the state of the global variables
//get string representations of ip addresses //reply with some html //this has to be sizeof the whole buffer //reset the submit text