Académique Documents
Professionnel Documents
Culture Documents
HSD / SBS4
Daniel Pfeil
Name:
Gruppe 2
Gruppe:
1/2
Punkte:
/ 12
Abgabe
Sourcecode (genderte Stellen) (5 Punkte)
Beschreibung der Ablufe bzw. Server Side Includes (5 Punkte)
Screenshot von Wireshark (Verbindungsaufbau, Webseite laden,
Seite 1 von 1
Oyrer Andreas
SBS4: Ubung
11
Ubung
11
Inhaltsverzeichnis
Beispiel 1
Funktionsbeschreibung der Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Beschreibung der Abl
aufe bzw. Server Side Includes . . . . . . . . . . . . . . . . . . . . . . . . . .
Beschreiben Sie, wie der Ablauf zum Laden einer Webseite mittels GET ist bzw. was bei einem
POST passiert. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Wie k
onnen Variablen vom MCBSTM32F200-Board (z.B. Taste gedr
uckt ja/nein) in die Webseite eingebaut und zur Laufzeit (beim Laden der Webseite vom Board) an den Webbrowser u
bertragen werden? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Beschreiben Sie dazu die Funktionsweise von Server Side Includes. . . . . . . . . . . . . . . .
Sourcecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Screenshot von Wireshark (Verbindungsaufbau, Webseite laden,Verbindungsabbau) . . . . . . . . .
Screenshot des Browsers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Foto vom GLCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
4
4
4
4
4
5
18
19
22
Seite 3 von 24
Ubung
11
Beispiel 1
Daten u
wird die Verbindung Serverseitig beendet.
bertragen. Nach der Ubertragung
POST
Mit dem HTTP Befehl POST k
onnen Daten zum Server geschickt werden. Im Gegensatz zu GET sind
aber die Daten nicht in der URL enthalten. Somit ist es moglich auch groe Datenmengen zum Server
zu u
bertragen. schickt unbegrenzte, je nach physischer Ausstattung des eingesetzten Servers, Mengen
an Daten zur weiteren Verarbeitung zum Server, diese werden als Inhalt der Nachricht u
bertragen und
k
onnen beispielsweise aus Name-Wert-Paaren bestehen, die aus einem HTML-Formular stammen. Es
k
onnen so neue Ressourcen auf dem Server entstehen oder bestehende modifiziert werden. POST-Daten
werden im Allgemeinen nicht von Caches zwischengespeichert. Zusatzlich konnen bei dieser Art der
Ubermittlung
auch Daten wie in der GET-Methode an den URI gehangt werden.
Wie k
onnen Variablen vom MCBSTM32F200-Board (z.B. Taste gedr
uckt ja/nein) in die Webseite eingebaut und zur Laufzeit (beim Laden der Webseite vom Board) an den Webbrowser
u
bertragen werden?
Dies wird mittels Server Side Includes realisiert. Dies Funktionsweise wird im nachsten Punkt beschrieben.
Beschreiben Sie dazu die Funktionsweise von Server Side Includes.
Server Side Includes sind in HTML-Dokumente eingebettete, einfach zu nutzende Skript-Befehle, die auf
dem Webserver ausgef
uhrt werden, bevor das Dokument an den Client ausgeliefert wird. Sie stellen eine
einfach zu verwendende Alternative zu Programmen bzw. Skripten dar, die das ganze Dokument dynamisch
generieren.
Seite 4 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
Zusammengefasst kann man mit den SSIs den Inhalt der Webseite verandern. Vor dem Senden der Website
an den Client werden die Werte vom Server eingetragen. Der Browser baut dann die Seite mit den aktuellen
Werten auf. Somit kann dynamisch die Website geandert werden.
Syntax f
ur eine SSI:
<!--#befehl parametername1="wert" parametername2="wert" -->
Sourcecode
aus Ubung
10 u
ur fehlen sollte, bitte melden :-)
bernommen. Wenn etwas f
Listing 1: main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
******************************************************************************
LwIP/LwIP_TCP_Echo_Server/Src/main.c
* @file
* @author MCD Application Team
* @version V1.1.0
13-March-2014
* @date
This sample code implements a TCP Echo Server application based on
* @brief
Raw API of LwIP stack. This application uses STM32F2xx the
*
ETH HAL API to transmit and receive data.
*
The communication is done with a web browser of a remote PC.
*
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
http://www.st.com/software_license_agreement_liberty_v2
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
30
31
32
33
34
35
36
37
38
39
/* Includes ------------------------------------------------------------------*/
#include "lwip/opt.h"
#include "lwip/init.h"
#include "lwip/netif.h"
#include "lwip/lwip_timers.h"
#include "netif/etharp.h"
#include "ethernetif.h"
#include "app_ethernet.h"
#include "tcp_echoserver.h"
40
Seite 5 von 24
41
42
43
44
45
46
#include
#include
#include
#include
#include
#include
Ubung
11
Beispiel 1 (fortgesetzt)
"stm32f2xx_hal.h"
"board_glcd.h"
"board_led.h"
"board_buttons.h"
"httpd.h"
<string.h>
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//init GLCD
GLCD_Initialize();
color: black, background color: white
// default: foreground
Seite 6 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
GLCD_ClearScreen();
GLCD_SetFont(font);
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* Infinite loop */
while (1)
{
/* Check for link changes */
ethernetif_set_link(&gnetif);
111
112
113
114
115
116
117
118
119
/* handle timeouts */
sys_check_timeouts();
120
121
122
123
124
125
126
#i f d e f USE_DHCP_SERVER
/* handle DHCP process */
DHCP_process(&gnetif);
#endif
127
128
129
130
131
132
133
134
/**
135
136
137
138
139
140
141
142
143
144
145
Seite 7 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
lwip_init();
146
147
148
149
150
151
152
153
154
155
156
157
158
#i f d e f USE_DHCP_SERVER
IP4_ADDR(&ipaddr, 0, 0, 0, 0);
IP4_ADDR(&netmask, 0, 0, 0, 0);
IP4_ADDR(&gw, 0, 0, 0, 0);
#e l s e
IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
#endif
/* add the network interface */
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &
ethernet_input);
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* Set the link callback function, this function is called on change of link
status*/
netif_set_link_callback(&gnetif, ethernetif_update_config);
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
* @brief
*
*
*
*
*
*
*
*
*
*
*
*
*
*
Seite 8 von 24
197
198
199
200
201
202
203
Ubung
11
Beispiel 1 (fortgesetzt)
* @param None
* @retval None
*/
s t a t i c void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
204
205
206
207
208
209
210
211
212
213
214
215
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#i f d e f RTE_CMSIS_RTOS_RTX
/*----------------------------------------------------------------------------this method is needed because SysTick_Handler is used for the OS
but HAL_Delay needs a tick timer (i.e. HAL_Delay which is used for GLCD
so we have to provide the tick counter from the os
*----------------------------------------------------------------------------*/
extern uint32_t os_time;
248
249
uint32_t HAL_GetTick(void) {
Seite 9 von 24
Ubung
11
250
251
252
253
254
255
256
257
258
259
260
261
Beispiel 1 (fortgesetzt)
return os_time;
}
#e l s e
/*----------------------------------------------------------------------------this is the SysTick interrupt handler which is called every 1ms
we have to increment the HAL tick counter which is used for HAL_Delay
this is only needed if we dont use a OS
*----------------------------------------------------------------------------*/
void SysTick_Handler(){
HAL_IncTick();
}
#endif
262
263
#i f d e f
USE_FULL_ASSERT
264
265
/**
266
* @brief Reports the name of the source file and the source line number
where the assert_param error has occurred.
*
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/* Infinite loop */
while (1)
{}
}
#endif
282
283
284
Listing 2: httpd-cgi-ssi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
******************************************************************************
LwIP/LwIP_HTTP_Server_Raw/Src/httpd_cg_ssi.c
* @file
* @author MCD Application Team
* @version V1.1.0
13-March-2014
* @date
Webserver SSI and CGI handlers
* @brief
******************************************************************************
* @attention
*
*
*
*
*
*
*
Seite 10 von 24
17
18
19
20
21
22
23
24
25
26
Ubung
11
Beispiel 1 (fortgesetzt)
http://www.st.com/software_license_agreement_liberty_v2
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
27
28
29
30
31
32
33
34
35
36
/* Includes ------------------------------------------------------------------*/
#include "lwip/debug.h"
#include "httpd.h"
#include "lwip/tcp.h"
#include "fs.h"
#include "board_led.h"
#include "board_glcd.h"
#include "board_buttons.h"
#include "stm32f2xx_hal.h"
37
38
39
40
#include <string.h>
#include <stdlib.h>
41
42
uint32_t ADC_not_configured=1;
43
44
ADC_HandleTypeDef hadc;
45
46
47
48
49
50
51
52
//defines
//------#define USER
1
#define TAMPER
2
#define WAKEUP 4
#define LCD_FONT_H 8
#define LCD_FONT_W 6
53
54
55
56
57
// variables
//---------s t a t i c uint16_t adcVal = 0;
s t a t i c bool adcConvCompl = f a l s e ;
58
59
60
61
62
//constants
//--------s t a t i c uint32_t const cMaxVoltage = 3300;
s t a t i c uint32_t const cFactor = 4096;
63
64
65
66
67
68
69
Seite 11 von 24
Ubung
11
70
71
72
73
74
75
76
77
78
79
Beispiel 1 (fortgesetzt)
"led3",
"led4",
"led5",
"led6",
"led7",
"led8",
"key1",
"key2",
"key3"
};
80
81
#define SSI_TAGS_COUNT
12
82
83
84
85
86
87
88
89
90
91
92
93
#define CGI_TABS_COUNT
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @brief ADC_MspInit
* @param None
* @retval None
*/
void HAL_ADC_MspInit(ADC_HandleTypeDef *heth)
{
/* TODO: configure ADC GPIO and clock */
}
108
109
/**
110
111
112
113
114
115
116
117
118
119
120
Seite 12 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
121
122
123
124
//Init ADC
__ADC3_CLK_ENABLE();
ADC3->SQR3 |= ADC_SQR3_SQ1_0 | ADC_SQR3_SQ1_1 | ADC_SQR3_SQ1_2; //Input
7, Sequence 1
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//HAL_ADC_PollForConversion(&hadc, 10);
/* TODO: get ADC conversion value and convert it to mV */
ADC3->CR2 |= ADC_CR2_SWSTART; //starts adc conv
while(adcConvCompl == f a l s e );
adcConvCompl = f a l s e ;
voltage = adcVal * cMaxVoltage / cFactor;
172
Seite 13 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
173
174
175
176
177
178
179
180
181
/* prepare
*pcInsert
*(pcInsert
*(pcInsert
*(pcInsert
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//
//
//
//
//
//
//
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
keyState = Buttons_GetState();
i f (iIndex == idxUserKey)
{
i f (keyState & USER)
{
strcpy(pcInsert, "pressed");
return 7;
}
else
{
strcpy(pcInsert, "released");
return 8;
}
}
224
225
i f (iIndex == idxTamperKey)
Seite 14 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
226
227
228
229
230
231
232
233
234
235
236
237
238
i f (iIndex == idxWakeupKey)
{
i f (keyState & WAKEUP)
{
strcpy(pcInsert, "pressed");
return 7;
}
else
{
strcpy(pcInsert, "released");
return 8;
}
}
239
240
241
242
243
244
245
246
247
248
249
250
251
252
}
return 0;
253
254
255
256
257
/**
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
Seite 15 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
}
}
/* TODO: now switch on or off the LEDs based on the values in ledState */
for (i = 0; i < LED_COUNT; i++)
{
ledState[i] == 1 ? LED_On(i) : LED_Off(i);
}
278
279
280
281
282
283
284
285
}
/* uri to send after cgi call*/
return "/STM32F2x7LED.shtml";
286
287
288
289
290
291
/**
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
GLCD_DrawString(0,2*LCD_FONT_H, pcValue[0]);
320
321
}
/* uri to send after cgi call*/
return "/STM32F2x7GLCD.html";
322
323
324
325
326
327
328
329
/**
* Initialize SSI handlers
*/
Seite 16 von 24
330
331
332
333
334
Ubung
11
Beispiel 1 (fortgesetzt)
void httpd_ssi_init(void)
{
/* configure SSI handlers (ADC and LED page SSI) */
http_set_ssi_handler(SSI_Handler, (char const **)SSI_TAGS, SSI_TAGS_COUNT);
}
335
336
337
338
339
340
341
342
343
344
345
/**
* Initialize CGI handlers
*/
void httpd_cgi_init(void)
{
/* configure CGI handlers (LEDs and GLCD control CGI) */
CGI_TABS[0] = LEDS_CGI;
CGI_TABS[1] = GLCD_CGI;
http_set_cgi_handlers(CGI_TABS, CGI_TABS_COUNT);
}
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/**********************************************
\fn
ADC_IRQHandler
\brief
ISR for ADC
\param[in]
none
\returns
none
************************************************/
void ADC_IRQHandler(void)
{
i f (ADC3->SR & ADC_SR_EOC)
//conversion completet
{
adcVal = ADC3->DR;
adcConvCompl = true;
}
}
362
363
Seite 17 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
Seite 18 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
Seite 19 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
Seite 20 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
Seite 21 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
Seite 22 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
Seite 23 von 24
Ubung
11
Beispiel 1 (fortgesetzt)
Seite 24 von 24