Frank Vannieuwkerke / Mbed 2 deprecated Wi-Go_IOT_Demo_MKII

Dependencies:   NVIC_set_all_priorities mbed cc3000_hostdriver_mbedsocket TEMT6200 TSI Wi-Go_eCompass_Lib_V3 WiGo_BattCharger

Committer:
frankvnk
Date:
Sat Feb 28 20:23:30 2015 +0000
Revision:
7:9d86d022fa68
Parent:
5:bd9705c7cf51
Fixed Webserver lockup by skipping all code in the SysTick_Handler while HTTP data is sent.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frankvnk 5:bd9705c7cf51 1
frankvnk 5:bd9705c7cf51 2 /*****************************************************************************
frankvnk 5:bd9705c7cf51 3 * Dynamic HTML string handlers:
frankvnk 5:bd9705c7cf51 4 * Nine dynamic HTML fields are updated on browser refresh or button press:
frankvnk 5:bd9705c7cf51 5 * Acceleration
frankvnk 5:bd9705c7cf51 6 * Magnetometer
frankvnk 5:bd9705c7cf51 7 * eCompass
frankvnk 5:bd9705c7cf51 8 * Altitude
frankvnk 5:bd9705c7cf51 9 * Battery Voltage
frankvnk 5:bd9705c7cf51 10 * Ambient Light
frankvnk 5:bd9705c7cf51 11 * Temperature
frankvnk 5:bd9705c7cf51 12 * Slider Position
frankvnk 5:bd9705c7cf51 13 * Page Views
frankvnk 5:bd9705c7cf51 14 *
frankvnk 5:bd9705c7cf51 15 * CGI HTML forms:
frankvnk 5:bd9705c7cf51 16 * Three CGI form inputs are used to submit data from browser to the Server:
frankvnk 5:bd9705c7cf51 17 * On screen buttons: -Red-, Green, Blue (for control of RGB LED output color)
frankvnk 5:bd9705c7cf51 18 *
frankvnk 5:bd9705c7cf51 19 * myindex[] contains the HTML string that defines the webpage that is served
frankvnk 5:bd9705c7cf51 20 * Use an online HTML validator to verify HTML code before running it on the MCU
frankvnk 5:bd9705c7cf51 21 * eg.
frankvnk 5:bd9705c7cf51 22 * www.w3schools.com/tags/tryit.asp?filename=tryhtml_div_test
frankvnk 5:bd9705c7cf51 23 * www.onlinewebcheck.com/check.php?adv=1
frankvnk 5:bd9705c7cf51 24 * Note: Before checking the HTML in one of these validators,
frankvnk 5:bd9705c7cf51 25 * strip-out all “\” backslash characters (using search & replace)
frankvnk 5:bd9705c7cf51 26 *
frankvnk 5:bd9705c7cf51 27 * Webserver code is based on TI's CC3000 Simple HTTP Webserver:
frankvnk 5:bd9705c7cf51 28 * http://processors.wiki.ti.com/index.php/CC3000_Wi-Fi_for_MCU
frankvnk 5:bd9705c7cf51 29 *
frankvnk 5:bd9705c7cf51 30 * More detail on implementation of this Webserver App is available here:
frankvnk 5:bd9705c7cf51 31 * http://processors.wiki.ti.com/index.php/CC3000_HTTP_Server_Demo_Session
frankvnk 5:bd9705c7cf51 32 *
frankvnk 5:bd9705c7cf51 33 * A more advanced Webserver and Client App is also available from TI for the CC3000:
frankvnk 5:bd9705c7cf51 34 * http://processors.wiki.ti.com/index.php/CC3000_Web_Server_Client_Application
frankvnk 5:bd9705c7cf51 35 * (at this time not yet ported to Kinetis-L as the host processor)
frankvnk 5:bd9705c7cf51 36 *
frankvnk 5:bd9705c7cf51 37 ******************************************************************************
frankvnk 5:bd9705c7cf51 38 *
frankvnk 5:bd9705c7cf51 39 * demo.c - CC3000 Main Demo Application
frankvnk 5:bd9705c7cf51 40 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
frankvnk 5:bd9705c7cf51 41 *
frankvnk 5:bd9705c7cf51 42 * Redistribution and use in source and binary forms, with or without
frankvnk 5:bd9705c7cf51 43 * modification, are permitted provided that the following conditions
frankvnk 5:bd9705c7cf51 44 * are met:
frankvnk 5:bd9705c7cf51 45 *
frankvnk 5:bd9705c7cf51 46 * Redistributions of source code must retain the above copyright
frankvnk 5:bd9705c7cf51 47 * notice, this list of conditions and the following disclaimer.
frankvnk 5:bd9705c7cf51 48 *
frankvnk 5:bd9705c7cf51 49 * Redistributions in binary form must reproduce the above copyright
frankvnk 5:bd9705c7cf51 50 * notice, this list of conditions and the following disclaimer in the
frankvnk 5:bd9705c7cf51 51 * documentation and/or other materials provided with the
frankvnk 5:bd9705c7cf51 52 * distribution.
frankvnk 5:bd9705c7cf51 53 *
frankvnk 5:bd9705c7cf51 54 * Neither the name of Texas Instruments Incorporated nor the names of
frankvnk 5:bd9705c7cf51 55 * its contributors may be used to endorse or promote products derived
frankvnk 5:bd9705c7cf51 56 * from this software without specific prior written permission.
frankvnk 5:bd9705c7cf51 57 *
frankvnk 5:bd9705c7cf51 58 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
frankvnk 5:bd9705c7cf51 59 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
frankvnk 5:bd9705c7cf51 60 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
frankvnk 5:bd9705c7cf51 61 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
frankvnk 5:bd9705c7cf51 62 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
frankvnk 5:bd9705c7cf51 63 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
frankvnk 5:bd9705c7cf51 64 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
frankvnk 5:bd9705c7cf51 65 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
frankvnk 5:bd9705c7cf51 66 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
frankvnk 5:bd9705c7cf51 67 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
frankvnk 5:bd9705c7cf51 68 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
frankvnk 5:bd9705c7cf51 69 *
frankvnk 5:bd9705c7cf51 70 *****************************************************************************/
frankvnk 5:bd9705c7cf51 71
frankvnk 5:bd9705c7cf51 72 #include "mbed.h"
frankvnk 5:bd9705c7cf51 73 #include "defLED.h"
frankvnk 5:bd9705c7cf51 74 #include "demo.h"
frankvnk 5:bd9705c7cf51 75 #include "AvnetHTML.h"
frankvnk 5:bd9705c7cf51 76 #include "TSISensor.h"
frankvnk 5:bd9705c7cf51 77 #include "Wi-Go_eCompass_Lib_V3.h"
frankvnk 5:bd9705c7cf51 78
frankvnk 5:bd9705c7cf51 79 extern DigitalOut ledr;
frankvnk 5:bd9705c7cf51 80 extern DigitalOut ledg;
frankvnk 5:bd9705c7cf51 81 extern DigitalOut ledb;
frankvnk 5:bd9705c7cf51 82 extern DigitalOut led1;
frankvnk 5:bd9705c7cf51 83 extern DigitalOut led2;
frankvnk 5:bd9705c7cf51 84 extern DigitalOut led3;
frankvnk 5:bd9705c7cf51 85 extern TSISensor tsi;
frankvnk 5:bd9705c7cf51 86
frankvnk 5:bd9705c7cf51 87 // Setup the functions to handle our CGI parameters
frankvnk 5:bd9705c7cf51 88 cgi_handler pHandlers;
frankvnk 5:bd9705c7cf51 89 dyn_html_handler htmlHandlers;
frankvnk 5:bd9705c7cf51 90
frankvnk 5:bd9705c7cf51 91 extern tNetappIpconfigRetArgs ipinfo2;
frankvnk 5:bd9705c7cf51 92
frankvnk 5:bd9705c7cf51 93 extern axis6_t axis6;
frankvnk 5:bd9705c7cf51 94 extern int server_running;
frankvnk 5:bd9705c7cf51 95 extern unsigned char newData;
frankvnk 5:bd9705c7cf51 96 extern unsigned short adc_sample3;
frankvnk 5:bd9705c7cf51 97
frankvnk 7:9d86d022fa68 98 // Variable declared in main and checked in the systick handler
frankvnk 7:9d86d022fa68 99 // Code in the systick handler is only processed when Systick_Allowed = 1
frankvnk 7:9d86d022fa68 100 extern bool Systick_Allowed;
frankvnk 7:9d86d022fa68 101
frankvnk 5:bd9705c7cf51 102 /** \brief Pointer to the index HTML page */
frankvnk 5:bd9705c7cf51 103 char * indexPage;
frankvnk 5:bd9705c7cf51 104
frankvnk 5:bd9705c7cf51 105 /** \brief Pointer to CGI handler structure */
frankvnk 5:bd9705c7cf51 106 cgi_handler * chList;
frankvnk 5:bd9705c7cf51 107
frankvnk 5:bd9705c7cf51 108 /** \brief Pointer to Dynamic HTML handler structure */
frankvnk 5:bd9705c7cf51 109 dyn_html_handler * htmlList;
frankvnk 5:bd9705c7cf51 110
frankvnk 5:bd9705c7cf51 111 /** \brief Page view counter */
frankvnk 5:bd9705c7cf51 112 int viewCounter = 1;
frankvnk 5:bd9705c7cf51 113 #define REQ_BUFFER_SIZE 400
frankvnk 5:bd9705c7cf51 114 #define HTTP_TX_BLOCK_SIZE 256
frankvnk 5:bd9705c7cf51 115 //#define HTTP_TX_BLOCK_SIZE 1024
frankvnk 5:bd9705c7cf51 116 //#define HTTP_TX_BLOCK_SIZE 512
frankvnk 5:bd9705c7cf51 117
frankvnk 5:bd9705c7cf51 118
frankvnk 5:bd9705c7cf51 119 // Setup the functions to handle our CGI parameters
frankvnk 5:bd9705c7cf51 120 char requestBuffer[REQ_BUFFER_SIZE];
frankvnk 5:bd9705c7cf51 121
frankvnk 5:bd9705c7cf51 122
frankvnk 5:bd9705c7cf51 123
frankvnk 5:bd9705c7cf51 124
frankvnk 5:bd9705c7cf51 125
frankvnk 5:bd9705c7cf51 126 /*
frankvnk 5:bd9705c7cf51 127 // ---------- HTML Webpage Content is defined here ----------
frankvnk 5:bd9705c7cf51 128 // Caution! Field labels and spaces in the HTML should not be edited without making corresponding changes in the C-code!
frankvnk 5:bd9705c7cf51 129 char index[] = {
frankvnk 5:bd9705c7cf51 130 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html lang=\"en-US\">"
frankvnk 5:bd9705c7cf51 131 "<head>"
frankvnk 5:bd9705c7cf51 132 "<META content=\"text/html;charset=ISO-8859-1\" http-equiv=\"content-type\">"
frankvnk 5:bd9705c7cf51 133 "<title>Wi-Go WebServer</title>"
frankvnk 5:bd9705c7cf51 134 //"<META HTTP-EQUIV=\"refresh\" content=\"2\">" // Uncomment for auto-refresh every 2 seconds
frankvnk 5:bd9705c7cf51 135 "</head>"
frankvnk 5:bd9705c7cf51 136
frankvnk 5:bd9705c7cf51 137 "<body><div style=\"text-align: left\"><font size=\"6\" color=\"Red\" face=\"Tahoma\">"
frankvnk 5:bd9705c7cf51 138 "<b>Avnet Wi-Go Webserver</b></font>"
frankvnk 5:bd9705c7cf51 139 "<hr size=3 width=600 align=left>"
frankvnk 5:bd9705c7cf51 140 "<font size=\"5\" color=\"Red\" face=\"Tahoma\"><b>LED RGB color select...</b></font>"
frankvnk 5:bd9705c7cf51 141
frankvnk 5:bd9705c7cf51 142 //"<font size=\"5\" color=\"Black\" face=\"monospace\"></font>"
frankvnk 5:bd9705c7cf51 143 "<form method=\"get\" action=\"index.html\" name=\"server\">"
frankvnk 5:bd9705c7cf51 144 "<input name=\"ledCon\" type=\"submit\" value=\"-Red-\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
frankvnk 5:bd9705c7cf51 145 "<input name=\"ledCon\" type=\"submit\" value=\"Green\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
frankvnk 5:bd9705c7cf51 146 "<input name=\"ledCon\" type=\"submit\" value=\"Blue-\">"
frankvnk 5:bd9705c7cf51 147 "</form></div>"
frankvnk 5:bd9705c7cf51 148
frankvnk 5:bd9705c7cf51 149 "<hr size=3 width=600 align=left>"
frankvnk 5:bd9705c7cf51 150 "<div style=\"text-align: left\"><font size=\"5\" color=\"Red\" face=\"Tahoma\">"
frankvnk 5:bd9705c7cf51 151 "<b>Navigation Sensors</b></font></div>"
frankvnk 5:bd9705c7cf51 152
frankvnk 5:bd9705c7cf51 153 "<div style=\"text-align:left\"><font size=\"4\" color=\"Black\" face=\"monospace\"><b>"
frankvnk 5:bd9705c7cf51 154 "Acceleration(G).. <br>"
frankvnk 5:bd9705c7cf51 155 "Magnetometer(uT). <br>"
frankvnk 5:bd9705c7cf51 156 "eCompass......... <br>"
frankvnk 5:bd9705c7cf51 157 "Altitude......... <br></b></font></div>"
frankvnk 5:bd9705c7cf51 158
frankvnk 5:bd9705c7cf51 159 "<hr size=3 width=600 align=left>"
frankvnk 5:bd9705c7cf51 160 "<div style=\"text-align: left\"><font size=\"5\" color=\"Red\" face=\"Tahoma\">"
frankvnk 5:bd9705c7cf51 161 "<b>Status and Control</b></font></div>"
frankvnk 5:bd9705c7cf51 162
frankvnk 5:bd9705c7cf51 163 "<div style=\"text-align:left\"><font size=\"4\" color=\"Black\" face=\"monospace\"><b>"
frankvnk 5:bd9705c7cf51 164 "Battery Voltage.. <br>"
frankvnk 5:bd9705c7cf51 165 "Ambient Light.... <br>"
frankvnk 5:bd9705c7cf51 166 "Temperature...... <br>"
frankvnk 5:bd9705c7cf51 167 "Slider Position.. <br>"
frankvnk 5:bd9705c7cf51 168 "Page Views....... </b></font>"
frankvnk 5:bd9705c7cf51 169 "<hr size=3 width=600 align=left>"
frankvnk 5:bd9705c7cf51 170 "</body></html>"}; // delete this line if adding the SVG code below...
frankvnk 5:bd9705c7cf51 171 */
frankvnk 5:bd9705c7cf51 172 // Optional section 1: Full SVG graphic example: Uncomment this section to display the standard Wi-Fi logo in lower area of webpage
frankvnk 5:bd9705c7cf51 173 // Browsers supporting SVG: Chrome and FireFox (all versions), Android (3.0 onwards), Safari (5.0 onwards), IE (9.0 onwards?)
frankvnk 5:bd9705c7cf51 174 /*
frankvnk 5:bd9705c7cf51 175 "<!--[if !IE]><!-->" // This prevents SVG content being sent to Internet Explorer
frankvnk 5:bd9705c7cf51 176 "<svg>"
frankvnk 5:bd9705c7cf51 177 "xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" height=\"175.49\" width=\"400\""
frankvnk 5:bd9705c7cf51 178 "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\""
frankvnk 5:bd9705c7cf51 179 "xmlns:cc=\"http://creativecommons.org/ns#\""
frankvnk 5:bd9705c7cf51 180 "xmlns:dc=\"http://purl.org/dc/elements/1.1/\">"
frankvnk 5:bd9705c7cf51 181 "<defs></defs>"
frankvnk 5:bd9705c7cf51 182 "<metadata>"
frankvnk 5:bd9705c7cf51 183 "<rdf:RDF>"
frankvnk 5:bd9705c7cf51 184 "<cc:Work rdf:about=\"\">"
frankvnk 5:bd9705c7cf51 185 "<dc:format>image/svg+xml</dc:format>"
frankvnk 5:bd9705c7cf51 186 "<dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>"
frankvnk 5:bd9705c7cf51 187 "<dc:title/>"
frankvnk 5:bd9705c7cf51 188 "</cc:Work>"
frankvnk 5:bd9705c7cf51 189 "</rdf:RDF>"
frankvnk 5:bd9705c7cf51 190 "</metadata>"
frankvnk 5:bd9705c7cf51 191 "<g transform=\"translate(-309.85919,-343.20843)\">"
frankvnk 5:bd9705c7cf51 192 "<g transform=\"matrix(3.7361528,0,0,-3.7361528,576.05074,474.82936)\">"
frankvnk 5:bd9705c7cf51 193 "<path fill-rule=\"nonzero\" fill=\"#231f20\" d=\"m0,0c4.977,0,9.049,4.077,9.049,9.049v5.389c0,4.973-4.072,9.048-9.049,9.048h-35.433c-4.973,0-9.049-4.075-9.049-9.048v-5.389c0-4.972,4.076-9.049,9.049-9.049\"/>"
frankvnk 5:bd9705c7cf51 194 "</g>"
frankvnk 5:bd9705c7cf51 195 "<g transform=\"matrix(3.7361528,0,0,-3.7361528,514.3818,441.01715)\">"
frankvnk 5:bd9705c7cf51 196 "<path fill-rule=\"nonzero\" fill=\"#FFF\" d=\"m0,0,0,5.389c0,4.072,3.314,7.32,7.32,7.32h9.187c4.007,0,7.253-3.248,7.253-7.32v-5.389c0-4.005-3.246-7.32-7.253-7.32h-20.239c2.281,1.656,3.732,4.284,3.732,7.32\"/>"
frankvnk 5:bd9705c7cf51 197 "</g>"
frankvnk 5:bd9705c7cf51 198 "<g transform=\"matrix(3.7361528,0,0,-3.7361528,469.99257,451.60916)\">"
frankvnk 5:bd9705c7cf51 199 "<path fill-rule=\"nonzero\" fill=\"#FFF\" d=\"m0,0-3.043,0-0.55,2.56c-0.345,1.794-0.692,4.005-0.761,4.833-0.069-0.828-0.416-3.039-0.825-4.833l-0.555-2.56h-2.968l-2.767,11.748h3.317l0.343-2.004c0.276-1.66,0.556-3.659,0.695-5.044,0.136,1.385,0.481,3.384,0.896,5.044l0.412,2.004h2.972l0.413-2.004c0.348-1.66,0.693-3.659,0.833-5.044,0.136,1.385,0.482,3.384,0.757,5.044l0.278,2.004h3.313\"/>"
frankvnk 5:bd9705c7cf51 200 "</g>"
frankvnk 5:bd9705c7cf51 201 "<g transform=\"matrix(3.7361528,0,0,-3.7361528,491.40819,416.23898)\">"
frankvnk 5:bd9705c7cf51 202 "<path fill-rule=\"nonzero\" fill=\"#FFF\" d=\"m0,0c-0.968,0-1.727,0.553-1.727,1.451,0,0.899,0.759,1.45,1.727,1.45,1.036,0,1.796-0.551,1.796-1.45,0-0.898-0.76-1.451-1.796-1.451m-1.521-0.968,3.0401,0,0-8.4984-3.0401,0,0,8.4984z\"/>"
frankvnk 5:bd9705c7cf51 203 "</g>"
frankvnk 5:bd9705c7cf51 204 "<g transform=\"matrix(3.7361528,0,0,-3.7361528,541.9845,418.05849)\">"
frankvnk 5:bd9705c7cf51 205 "<path fill-rule=\"nonzero\" fill=\"#231f20\" d=\"m0,0,0-2.618,6.22,0,0-2.767-6.22,0,0-3.593-3.247,0,0,11.748,10.156,0,0-2.77\"/>"
frankvnk 5:bd9705c7cf51 206 "</g>"
frankvnk 5:bd9705c7cf51 207 "<g transform=\"matrix(3.7361528,0,0,-3.7361528,580.44446,416.23898)\">"
frankvnk 5:bd9705c7cf51 208 "<path fill-rule=\"nonzero\" fill=\"#231f20\" d=\"m0,0c-0.97,0-1.727,0.553-1.727,1.451,0,0.899,0.757,1.45,1.727,1.45,1.035,0,1.797-0.551,1.797-1.45,0-0.898-0.762-1.451-1.797-1.451m-1.521-0.968,3.0371,0,0-8.4984-3.0371,0,0,8.4984z\"/>"
frankvnk 5:bd9705c7cf51 209 "</g>"
frankvnk 5:bd9705c7cf51 210 "</g>"
frankvnk 5:bd9705c7cf51 211 "</svg>"
frankvnk 5:bd9705c7cf51 212 "<!--<![endif]-->"
frankvnk 5:bd9705c7cf51 213 */ // end of conditional inclusion of SVG graphic (excludes Internet Explorer browser)
frankvnk 5:bd9705c7cf51 214 // ---- End of Wi-Fi logo SVG image definition ----
frankvnk 5:bd9705c7cf51 215
frankvnk 5:bd9705c7cf51 216 // Optional section 2: Simple SVG graphic example: Uncomment this section to generate a filled circle in lower area of webpage
frankvnk 5:bd9705c7cf51 217 // eg. Could use to indicate RGB LED color (with addition of applicable C-code to dynamically update specified "fill=" color)
frankvnk 5:bd9705c7cf51 218 /*
frankvnk 5:bd9705c7cf51 219 "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">"
frankvnk 5:bd9705c7cf51 220 "<circle cx=\"155\" cy=\"22\" r=\"20\" stroke=\"DimGrey\" stroke-width=\"2\" fill=\"Red\"/>"
frankvnk 5:bd9705c7cf51 221 "</svg>"
frankvnk 5:bd9705c7cf51 222 "</body></html>"};
frankvnk 5:bd9705c7cf51 223 */
frankvnk 5:bd9705c7cf51 224
frankvnk 5:bd9705c7cf51 225 // ----------------------------------------------------------
frankvnk 5:bd9705c7cf51 226
frankvnk 5:bd9705c7cf51 227 //char ssid_name[] = SSID;
frankvnk 5:bd9705c7cf51 228 char testString[20];
frankvnk 5:bd9705c7cf51 229 //int vcc = 0;
frankvnk 5:bd9705c7cf51 230 //*****************************************************************************
frankvnk 5:bd9705c7cf51 231 //
frankvnk 5:bd9705c7cf51 232 //! demo_wi-fi_main
frankvnk 5:bd9705c7cf51 233 //!
frankvnk 5:bd9705c7cf51 234 //! \param None
frankvnk 5:bd9705c7cf51 235 //!
frankvnk 5:bd9705c7cf51 236 //! \return none
frankvnk 5:bd9705c7cf51 237 //!
frankvnk 5:bd9705c7cf51 238 //! \brief The main loop is executed here
frankvnk 5:bd9705c7cf51 239 //
frankvnk 5:bd9705c7cf51 240 //*****************************************************************************
frankvnk 5:bd9705c7cf51 241
frankvnk 5:bd9705c7cf51 242 int demo_wifi_main(void)
frankvnk 5:bd9705c7cf51 243 {
frankvnk 5:bd9705c7cf51 244 server_running = 1;
frankvnk 5:bd9705c7cf51 245 while(1)
frankvnk 5:bd9705c7cf51 246 {
frankvnk 5:bd9705c7cf51 247 /* Configure dynamic HTML string handlers
frankvnk 5:bd9705c7cf51 248 0 : Acceleration
frankvnk 5:bd9705c7cf51 249 1 : Magnetometer
frankvnk 5:bd9705c7cf51 250 2 : eCompass
frankvnk 5:bd9705c7cf51 251 3 : Altitude
frankvnk 5:bd9705c7cf51 252 -------------------
frankvnk 5:bd9705c7cf51 253 4 : Battery Voltage
frankvnk 5:bd9705c7cf51 254 5 : Ambient Light
frankvnk 5:bd9705c7cf51 255 6 : Temperature
frankvnk 5:bd9705c7cf51 256 7 : Slider Position
frankvnk 5:bd9705c7cf51 257 8 : Page Views
frankvnk 5:bd9705c7cf51 258 */
frankvnk 5:bd9705c7cf51 259 (htmlHandlers.dynHtmlFunc[0]) = getAccelXYZ_Str;
frankvnk 5:bd9705c7cf51 260 memcpy(htmlHandlers.dynHtmlParamName[0],"Acceleration(G).. ",strlen("Acceleration(G).. "));
frankvnk 5:bd9705c7cf51 261 htmlHandlers.dynHtmlParamName[0][strlen("Acceleration(G).. ")] ='\0';
frankvnk 5:bd9705c7cf51 262
frankvnk 5:bd9705c7cf51 263 (htmlHandlers.dynHtmlFunc[1]) = getM3110Str;
frankvnk 5:bd9705c7cf51 264 memcpy(htmlHandlers.dynHtmlParamName[1],"Magnetometer(uT). ",strlen("Magnetometer(uT). "));
frankvnk 5:bd9705c7cf51 265 htmlHandlers.dynHtmlParamName[1][strlen("Magnetometer(uT). ")] ='\0';
frankvnk 5:bd9705c7cf51 266
frankvnk 5:bd9705c7cf51 267 (htmlHandlers.dynHtmlFunc[2]) = getCompassStr;
frankvnk 5:bd9705c7cf51 268 memcpy(htmlHandlers.dynHtmlParamName[2],"eCompass......... ",strlen("eCompass......... "));
frankvnk 5:bd9705c7cf51 269 htmlHandlers.dynHtmlParamName[2][strlen("eCompass......... ")] ='\0';
frankvnk 5:bd9705c7cf51 270
frankvnk 5:bd9705c7cf51 271 (htmlHandlers.dynHtmlFunc[3]) = getAltitudeStr;
frankvnk 5:bd9705c7cf51 272 memcpy(htmlHandlers.dynHtmlParamName[3],"Altitude......... ",strlen("Altitude......... "));
frankvnk 5:bd9705c7cf51 273 htmlHandlers.dynHtmlParamName[3][strlen("Altitude......... ")] ='\0';
frankvnk 5:bd9705c7cf51 274
frankvnk 5:bd9705c7cf51 275 (htmlHandlers.dynHtmlFunc[4]) = getBatteryVoltageStr;
frankvnk 5:bd9705c7cf51 276 memcpy(htmlHandlers.dynHtmlParamName[4],"Battery Voltage.. ",strlen("Battery Voltage.. "));
frankvnk 5:bd9705c7cf51 277 htmlHandlers.dynHtmlParamName[4][strlen("Battery Voltage.. ")] ='\0';
frankvnk 5:bd9705c7cf51 278
frankvnk 5:bd9705c7cf51 279 (htmlHandlers.dynHtmlFunc[5]) = getLightVoltageStr;
frankvnk 5:bd9705c7cf51 280 memcpy(htmlHandlers.dynHtmlParamName[5],"Ambient Light.... ",strlen("Ambient Light.... "));
frankvnk 5:bd9705c7cf51 281 htmlHandlers.dynHtmlParamName[5][strlen("Ambient Light.... ")] ='\0';
frankvnk 5:bd9705c7cf51 282
frankvnk 5:bd9705c7cf51 283 (htmlHandlers.dynHtmlFunc[6]) = getTemperatureStr;
frankvnk 5:bd9705c7cf51 284 memcpy(htmlHandlers.dynHtmlParamName[6],"Temperature...... ",strlen("Temperature...... "));
frankvnk 5:bd9705c7cf51 285 htmlHandlers.dynHtmlParamName[6][strlen("Temperature...... ")] ='\0';
frankvnk 5:bd9705c7cf51 286
frankvnk 5:bd9705c7cf51 287 (htmlHandlers.dynHtmlFunc[7]) = getTSI_sliderStr;
frankvnk 5:bd9705c7cf51 288 memcpy(htmlHandlers.dynHtmlParamName[7],"Slider Position.. ",strlen("Slider Position.. "));
frankvnk 5:bd9705c7cf51 289 htmlHandlers.dynHtmlParamName[7][strlen("Slider Position.. ")] ='\0';
frankvnk 5:bd9705c7cf51 290
frankvnk 5:bd9705c7cf51 291 (htmlHandlers.dynHtmlFunc[8]) = getViewsNum;
frankvnk 5:bd9705c7cf51 292 memcpy(htmlHandlers.dynHtmlParamName[8],"Page Views....... ",strlen("Page Views....... "));
frankvnk 5:bd9705c7cf51 293 htmlHandlers.dynHtmlParamName[8][strlen("Page Views....... ")] ='\0';
frankvnk 5:bd9705c7cf51 294
frankvnk 5:bd9705c7cf51 295 // Configure CGI Handler
frankvnk 5:bd9705c7cf51 296 (pHandlers.cgiHandlerFunc[0]) = testFunc;
frankvnk 5:bd9705c7cf51 297
frankvnk 5:bd9705c7cf51 298 serverMain(HTTP_PORT,(char *)index, &pHandlers, &htmlHandlers);
frankvnk 5:bd9705c7cf51 299 }
frankvnk 5:bd9705c7cf51 300 }
frankvnk 5:bd9705c7cf51 301
frankvnk 5:bd9705c7cf51 302
frankvnk 5:bd9705c7cf51 303 void testFunc(char * str)
frankvnk 5:bd9705c7cf51 304 {
frankvnk 5:bd9705c7cf51 305 memcpy(testString,str,strlen(str));
frankvnk 5:bd9705c7cf51 306 if(strcmp(str, "-Red-") == 0)
frankvnk 5:bd9705c7cf51 307 {
frankvnk 5:bd9705c7cf51 308 RED_ON; GREEN_OFF; BLUE_OFF;
frankvnk 5:bd9705c7cf51 309 }
frankvnk 5:bd9705c7cf51 310 else if(strcmp(str, "Green") == 0)
frankvnk 5:bd9705c7cf51 311 {
frankvnk 5:bd9705c7cf51 312 RED_OFF; GREEN_ON; BLUE_OFF;
frankvnk 5:bd9705c7cf51 313 }
frankvnk 5:bd9705c7cf51 314 else if (strcmp(str, "Blue-") == 0)
frankvnk 5:bd9705c7cf51 315 {
frankvnk 5:bd9705c7cf51 316 RED_OFF; GREEN_OFF; BLUE_ON;
frankvnk 5:bd9705c7cf51 317 }
frankvnk 5:bd9705c7cf51 318 }
frankvnk 5:bd9705c7cf51 319
frankvnk 5:bd9705c7cf51 320 void getBatteryVoltageStr(char * str)
frankvnk 5:bd9705c7cf51 321 {
frankvnk 5:bd9705c7cf51 322 sprintf(str," "); //clears field (needed if previous string had more characters)
frankvnk 5:bd9705c7cf51 323 sprintf(str, "%d %%", adc_sample3);
frankvnk 5:bd9705c7cf51 324 }
frankvnk 5:bd9705c7cf51 325
frankvnk 5:bd9705c7cf51 326 void getLightVoltageStr(char * str)
frankvnk 5:bd9705c7cf51 327 {
frankvnk 5:bd9705c7cf51 328 int LightPercent = 0;
frankvnk 5:bd9705c7cf51 329 LightPercent = (axis6.light * 100) / 4096;
frankvnk 5:bd9705c7cf51 330 sprintf(str," "); //clears field (needed if previous string had more characters)
frankvnk 5:bd9705c7cf51 331 sprintf(str, "%d %%", LightPercent);
frankvnk 5:bd9705c7cf51 332 }
frankvnk 5:bd9705c7cf51 333
frankvnk 5:bd9705c7cf51 334 void getAccelXYZ_Str(char * str) // MMA8451Q accelerometer - report axis with highest value
frankvnk 5:bd9705c7cf51 335 {
frankvnk 5:bd9705c7cf51 336 sprintf(str," "); //clears field (needed if previous string had more characters)
frankvnk 5:bd9705c7cf51 337 sprintf(str, "X= %1.2f, Y= %1.2f, Z= %1.2f", axis6.fGax, axis6.fGay, axis6.fGaz);;
frankvnk 5:bd9705c7cf51 338 }
frankvnk 5:bd9705c7cf51 339
frankvnk 5:bd9705c7cf51 340 void getTemperatureStr(char * str) //
frankvnk 5:bd9705c7cf51 341 {
frankvnk 5:bd9705c7cf51 342 sprintf(str, "%+d C", axis6.temp);
frankvnk 5:bd9705c7cf51 343 }
frankvnk 5:bd9705c7cf51 344
frankvnk 5:bd9705c7cf51 345 void getTSI_sliderStr(char * str) // TSI Slider position
frankvnk 5:bd9705c7cf51 346 {
frankvnk 5:bd9705c7cf51 347 uint8_t slider_position;
frankvnk 5:bd9705c7cf51 348
frankvnk 5:bd9705c7cf51 349 slider_position = tsi.readPercentage() * 100; // Slider position as percentage
frankvnk 5:bd9705c7cf51 350 sprintf(str," "); //clears field (needed if previous string had more characters)
frankvnk 5:bd9705c7cf51 351 sprintf(str, "%d %%", slider_position);
frankvnk 5:bd9705c7cf51 352 }
frankvnk 5:bd9705c7cf51 353
frankvnk 5:bd9705c7cf51 354 void getCompassStr(char * str) // Mag3110 generated Compass bearing
frankvnk 5:bd9705c7cf51 355 {
frankvnk 5:bd9705c7cf51 356 char *compass_points[9] = {"North", "N-East", "East", "S-East", "South", "S-West", "West", "N-West", "North"};
frankvnk 5:bd9705c7cf51 357 signed short compass_bearing = (axis6.compass + 23) / 45;
frankvnk 5:bd9705c7cf51 358 sprintf(str," "); //clears field (needed if previous string had more characters)
frankvnk 5:bd9705c7cf51 359 sprintf(str, "Roll=%-d Pitch=%-d Yaw=%-d [%s]", axis6.roll, axis6.pitch, axis6.yaw, compass_points[compass_bearing]); //
frankvnk 5:bd9705c7cf51 360 }
frankvnk 5:bd9705c7cf51 361
frankvnk 5:bd9705c7cf51 362 void getM3110Str(char * str) // Mag3110 displayed in units of UT
frankvnk 5:bd9705c7cf51 363 {
frankvnk 5:bd9705c7cf51 364 sprintf(str," "); //clears field (needed if previous string had more characters)
frankvnk 5:bd9705c7cf51 365 sprintf(str, "X= %3.1f, Y= %3.1f, Z= %3.1f", axis6.fUTmx, axis6.fUTmy, axis6.fUTmz);
frankvnk 5:bd9705c7cf51 366 }
frankvnk 5:bd9705c7cf51 367
frankvnk 5:bd9705c7cf51 368 void getAltitudeStr(char * str) // Get Altitude
frankvnk 5:bd9705c7cf51 369 {
frankvnk 5:bd9705c7cf51 370 sprintf(str, "%+d meters", axis6.alt); // str = integer portion of result
frankvnk 5:bd9705c7cf51 371 }
frankvnk 5:bd9705c7cf51 372
frankvnk 5:bd9705c7cf51 373
frankvnk 5:bd9705c7cf51 374
frankvnk 5:bd9705c7cf51 375 //*****************************************************************************
frankvnk 5:bd9705c7cf51 376 //
frankvnk 5:bd9705c7cf51 377 //! \brief Main HTTP Server
frankvnk 5:bd9705c7cf51 378 //!
frankvnk 5:bd9705c7cf51 379 //! \param none
frankvnk 5:bd9705c7cf51 380 //!
frankvnk 5:bd9705c7cf51 381 //! \return none
frankvnk 5:bd9705c7cf51 382 //!
frankvnk 5:bd9705c7cf51 383 //
frankvnk 5:bd9705c7cf51 384 //*****************************************************************************
frankvnk 5:bd9705c7cf51 385 void serverMain(int port,
frankvnk 5:bd9705c7cf51 386 char * ipage,
frankvnk 5:bd9705c7cf51 387 cgi_handler * handleList,
frankvnk 5:bd9705c7cf51 388 dyn_html_handler * dhList)
frankvnk 5:bd9705c7cf51 389 {
frankvnk 5:bd9705c7cf51 390 static TCPSocketServer server;
frankvnk 5:bd9705c7cf51 391 static TCPSocketConnection client;
frankvnk 5:bd9705c7cf51 392
frankvnk 5:bd9705c7cf51 393 indexPage = ipage;
frankvnk 5:bd9705c7cf51 394 chList = handleList;
frankvnk 5:bd9705c7cf51 395 htmlList = dhList;
frankvnk 5:bd9705c7cf51 396
frankvnk 5:bd9705c7cf51 397 server.bind(port);
frankvnk 5:bd9705c7cf51 398
frankvnk 5:bd9705c7cf51 399 printf("Main HTTP server\r\n");
frankvnk 5:bd9705c7cf51 400
frankvnk 5:bd9705c7cf51 401 // Start Listening
frankvnk 7:9d86d022fa68 402 if(server.listen() != 0); // !!?? if statement is of no use - replace with server.listen();
frankvnk 5:bd9705c7cf51 403
frankvnk 5:bd9705c7cf51 404 // Handle Clients and Data
frankvnk 5:bd9705c7cf51 405 while(1)
frankvnk 5:bd9705c7cf51 406 {
frankvnk 5:bd9705c7cf51 407 int32_t status = server.accept(client);
frankvnk 5:bd9705c7cf51 408 if (status >= 0)
frankvnk 5:bd9705c7cf51 409 {
frankvnk 5:bd9705c7cf51 410 LED_D2_ON;
frankvnk 5:bd9705c7cf51 411 // Connection Accepted, Send Data
frankvnk 5:bd9705c7cf51 412 // Wait for a data update
frankvnk 5:bd9705c7cf51 413 client.set_blocking(true);
frankvnk 5:bd9705c7cf51 414 printf("Connection\r\n");
frankvnk 5:bd9705c7cf51 415 // printf("Connection from: %s \r\n", client.get_address());
frankvnk 7:9d86d022fa68 416 if(newData)
frankvnk 7:9d86d022fa68 417 {
frankvnk 7:9d86d022fa68 418 Systick_Allowed = 0;
frankvnk 7:9d86d022fa68 419 // Alternative to Systick_Allowed - more intrusive as it will entirely disable systicks
frankvnk 7:9d86d022fa68 420 // SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; // *** Disable SysTick Timer
frankvnk 7:9d86d022fa68 421 handleHTTPRequest(&client);
frankvnk 7:9d86d022fa68 422 }
frankvnk 5:bd9705c7cf51 423 newData = 0;
frankvnk 5:bd9705c7cf51 424 client.close();
frankvnk 5:bd9705c7cf51 425 LED_D2_OFF;
frankvnk 5:bd9705c7cf51 426 }
frankvnk 5:bd9705c7cf51 427 else if(status == -57)
frankvnk 5:bd9705c7cf51 428 {
frankvnk 5:bd9705c7cf51 429 // BUG: Socket inactive so reopen socket
frankvnk 5:bd9705c7cf51 430 // Inactive Socket, close and reopen it
frankvnk 5:bd9705c7cf51 431 printf("Oops!!!\r\n");
frankvnk 5:bd9705c7cf51 432 server.close();
frankvnk 5:bd9705c7cf51 433 indexPage = ipage;
frankvnk 5:bd9705c7cf51 434 chList = handleList;
frankvnk 5:bd9705c7cf51 435 htmlList = dhList;
frankvnk 5:bd9705c7cf51 436 server.bind(port);
frankvnk 5:bd9705c7cf51 437
frankvnk 5:bd9705c7cf51 438 // Start Listening
frankvnk 7:9d86d022fa68 439 if (server.listen() != 0); // !!?? if statement is of no use - replace with server.listen();
frankvnk 5:bd9705c7cf51 440 }
frankvnk 7:9d86d022fa68 441 Systick_Allowed = 1;
frankvnk 7:9d86d022fa68 442 // SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; // *** Re-Enable SysTick Timer
frankvnk 5:bd9705c7cf51 443 }
frankvnk 5:bd9705c7cf51 444 }
frankvnk 5:bd9705c7cf51 445
frankvnk 5:bd9705c7cf51 446 //*****************************************************************************
frankvnk 5:bd9705c7cf51 447 //
frankvnk 5:bd9705c7cf51 448 //! \brief Handles HTTP Requests
frankvnk 5:bd9705c7cf51 449 //!
frankvnk 5:bd9705c7cf51 450 //! \param cnum is the client socket handle to be used
frankvnk 5:bd9705c7cf51 451 //!
frankvnk 5:bd9705c7cf51 452 //! \return none
frankvnk 5:bd9705c7cf51 453 //!
frankvnk 5:bd9705c7cf51 454 //
frankvnk 5:bd9705c7cf51 455 //*****************************************************************************
frankvnk 5:bd9705c7cf51 456 void handleHTTPRequest(TCPSocketConnection *client)
frankvnk 5:bd9705c7cf51 457 {
frankvnk 5:bd9705c7cf51 458 char * reqline[3];
frankvnk 5:bd9705c7cf51 459 char * cgiTok;
frankvnk 5:bd9705c7cf51 460
frankvnk 5:bd9705c7cf51 461 int i = 0;
frankvnk 5:bd9705c7cf51 462 char paramBuf[20];
frankvnk 5:bd9705c7cf51 463 int bytesRecvd;
frankvnk 5:bd9705c7cf51 464 char tempStr[40]; //PF was 26
frankvnk 5:bd9705c7cf51 465
frankvnk 5:bd9705c7cf51 466 memset(requestBuffer,0,sizeof (requestBuffer));
frankvnk 5:bd9705c7cf51 467 bytesRecvd = client->receive(requestBuffer, sizeof(requestBuffer));
frankvnk 5:bd9705c7cf51 468
frankvnk 5:bd9705c7cf51 469 printf("handleHTTPRequest\r\n");
frankvnk 5:bd9705c7cf51 470
frankvnk 5:bd9705c7cf51 471 if(bytesRecvd > 0)
frankvnk 5:bd9705c7cf51 472 {
frankvnk 5:bd9705c7cf51 473 // Received some data, check it and send data back
frankvnk 5:bd9705c7cf51 474 reqline[0] = strstr(requestBuffer, "GET");
frankvnk 5:bd9705c7cf51 475 if ( reqline[0] != NULL )
frankvnk 5:bd9705c7cf51 476 {
frankvnk 5:bd9705c7cf51 477 if (strstr (requestBuffer, "HTTP/1.0") != NULL && strstr (requestBuffer, "HTTP/1.1") != NULL )
frankvnk 5:bd9705c7cf51 478 {
frankvnk 5:bd9705c7cf51 479 client->send_all("HTTP/1.0 400 Bad Request\n", 25);
frankvnk 5:bd9705c7cf51 480 }
frankvnk 5:bd9705c7cf51 481 else
frankvnk 5:bd9705c7cf51 482 {
frankvnk 5:bd9705c7cf51 483
frankvnk 5:bd9705c7cf51 484 #ifdef HTTP_CGI_ENABLED
frankvnk 5:bd9705c7cf51 485 // Do we have CGI parameters we need to parse?
frankvnk 5:bd9705c7cf51 486 if(strchr(requestBuffer, '?') != NULL)
frankvnk 5:bd9705c7cf51 487 {
frankvnk 5:bd9705c7cf51 488 // Decode URL and handle each parameter sequentially
frankvnk 5:bd9705c7cf51 489 // according to table previously setup.
frankvnk 5:bd9705c7cf51 490 cgiTok = strstr(requestBuffer,"=");
frankvnk 5:bd9705c7cf51 491 if(cgiTok != NULL)
frankvnk 5:bd9705c7cf51 492 {
frankvnk 5:bd9705c7cf51 493 memset(paramBuf,0,sizeof(paramBuf));
frankvnk 5:bd9705c7cf51 494 memcpy(paramBuf,cgiTok+1,5); // hard-coded for demo: 5 character parameter (-Red-/Green/Blue-)
frankvnk 5:bd9705c7cf51 495 chList->cgiHandlerFunc[0](paramBuf);
frankvnk 5:bd9705c7cf51 496
frankvnk 5:bd9705c7cf51 497 }
frankvnk 5:bd9705c7cf51 498 }
frankvnk 5:bd9705c7cf51 499 #endif
frankvnk 5:bd9705c7cf51 500
frankvnk 5:bd9705c7cf51 501 #ifdef HTTP_DYN_HTML_ENABLED
frankvnk 5:bd9705c7cf51 502 // The code below replaces data in the HTML page
frankvnk 5:bd9705c7cf51 503 // with that generated by the specified functions.
frankvnk 5:bd9705c7cf51 504 for(i = 0; i < 9; i++) // change the range here for more dynamic fields on webpage
frankvnk 5:bd9705c7cf51 505 {
frankvnk 5:bd9705c7cf51 506 memset(tempStr,0,sizeof(tempStr));
frankvnk 5:bd9705c7cf51 507 htmlList->dynHtmlFunc[i](tempStr);
frankvnk 5:bd9705c7cf51 508 tempStr[strlen(tempStr)]= ' ';
frankvnk 5:bd9705c7cf51 509 pageReplace((char *)indexPage,
frankvnk 5:bd9705c7cf51 510 (char *)htmlList->dynHtmlParamName[i],
frankvnk 5:bd9705c7cf51 511 (char *)tempStr);
frankvnk 5:bd9705c7cf51 512 }
frankvnk 5:bd9705c7cf51 513 #endif
frankvnk 5:bd9705c7cf51 514 viewCounter++;
frankvnk 5:bd9705c7cf51 515 sendHTTPData(HTTP_RESP, strlen(HTTP_RESP), client);
frankvnk 5:bd9705c7cf51 516
frankvnk 5:bd9705c7cf51 517 for(i = 0; i < strlen(indexPage); i += HTTP_TX_BLOCK_SIZE)
frankvnk 5:bd9705c7cf51 518 {
frankvnk 5:bd9705c7cf51 519 if(strlen(indexPage) - i < HTTP_TX_BLOCK_SIZE)
frankvnk 5:bd9705c7cf51 520 {
frankvnk 5:bd9705c7cf51 521 sendHTTPData(&indexPage[i], strlen(indexPage) - i, client);
frankvnk 5:bd9705c7cf51 522 }
frankvnk 5:bd9705c7cf51 523 else
frankvnk 5:bd9705c7cf51 524 {
frankvnk 5:bd9705c7cf51 525 sendHTTPData(&indexPage[i], HTTP_TX_BLOCK_SIZE, client);
frankvnk 5:bd9705c7cf51 526 }
frankvnk 5:bd9705c7cf51 527 }
frankvnk 5:bd9705c7cf51 528 }
frankvnk 5:bd9705c7cf51 529 }
frankvnk 5:bd9705c7cf51 530 }
frankvnk 5:bd9705c7cf51 531 }
frankvnk 5:bd9705c7cf51 532
frankvnk 5:bd9705c7cf51 533 //*****************************************************************************
frankvnk 5:bd9705c7cf51 534 //
frankvnk 5:bd9705c7cf51 535 //! \brief Inserts characters in page that appear after an indicator ind
frankvnk 5:bd9705c7cf51 536 //! with the value from val
frankvnk 5:bd9705c7cf51 537 //!
frankvnk 5:bd9705c7cf51 538 //! \param page is a pointer to the array holding the page's HTML code
frankvnk 5:bd9705c7cf51 539 //! \param ind is a pointer to a string that has the name of the parameter on the page to modify
frankvnk 5:bd9705c7cf51 540 //! \param val is the pointer to a string holding the string to insert in the XXX
frankvnk 5:bd9705c7cf51 541 //!
frankvnk 5:bd9705c7cf51 542 //! \return none
frankvnk 5:bd9705c7cf51 543 //!
frankvnk 5:bd9705c7cf51 544 //
frankvnk 5:bd9705c7cf51 545 //*****************************************************************************
frankvnk 5:bd9705c7cf51 546 void pageReplace(char * page, char * ind, char * val)
frankvnk 5:bd9705c7cf51 547 {
frankvnk 5:bd9705c7cf51 548 char * indicLoc;
frankvnk 5:bd9705c7cf51 549 indicLoc = strstr (page,ind);
frankvnk 5:bd9705c7cf51 550 memcpy(indicLoc+strlen(ind), val, strlen(val));
frankvnk 5:bd9705c7cf51 551 }
frankvnk 5:bd9705c7cf51 552
frankvnk 5:bd9705c7cf51 553 //*****************************************************************************
frankvnk 5:bd9705c7cf51 554 //
frankvnk 5:bd9705c7cf51 555 //! \brief Returns a string with the number of views of the page
frankvnk 5:bd9705c7cf51 556 //!
frankvnk 5:bd9705c7cf51 557 //! \param str is a pointer to the array where the number of views will be put
frankvnk 5:bd9705c7cf51 558 //!
frankvnk 5:bd9705c7cf51 559 //! \return none
frankvnk 5:bd9705c7cf51 560 //!
frankvnk 5:bd9705c7cf51 561 //
frankvnk 5:bd9705c7cf51 562 //*****************************************************************************
frankvnk 5:bd9705c7cf51 563 void getViewsNum(char * str)
frankvnk 5:bd9705c7cf51 564 {
frankvnk 5:bd9705c7cf51 565 sprintf(str, "%d", viewCounter);
frankvnk 5:bd9705c7cf51 566 }
frankvnk 5:bd9705c7cf51 567
frankvnk 5:bd9705c7cf51 568 //*****************************************************************************
frankvnk 5:bd9705c7cf51 569 //
frankvnk 5:bd9705c7cf51 570 //! \brief Sends HTTP Data
frankvnk 5:bd9705c7cf51 571 //!
frankvnk 5:bd9705c7cf51 572 //! \param sdesc is the socket descriptor of the socket used for sending data
frankvnk 5:bd9705c7cf51 573 //! \param buf is a pointer to the buffer with the data to be sent
frankvnk 5:bd9705c7cf51 574 //! \param len is the number of bytes to send
frankvnk 5:bd9705c7cf51 575 //!
frankvnk 5:bd9705c7cf51 576 //! \return none
frankvnk 5:bd9705c7cf51 577 //!
frankvnk 5:bd9705c7cf51 578 //
frankvnk 5:bd9705c7cf51 579 //*****************************************************************************
frankvnk 5:bd9705c7cf51 580 void sendHTTPData(char * buf, long len, TCPSocketConnection *client)
frankvnk 5:bd9705c7cf51 581 {
frankvnk 5:bd9705c7cf51 582 int bytesSent = -2;
frankvnk 5:bd9705c7cf51 583 while(bytesSent == -2) bytesSent = client->send_all(buf, len);
frankvnk 5:bd9705c7cf51 584 }
frankvnk 5:bd9705c7cf51 585
frankvnk 5:bd9705c7cf51 586
frankvnk 5:bd9705c7cf51 587