2
2
3
3
IoTApp::IoTApp ()
4
4
{
5
- // this->handleData = [this](void *, AsyncClient *client, void *data, size_t len)
6
- // {
7
- // this->onData(client, (uint8_t *)data, len);
8
- // };
9
5
}
10
6
11
7
void IoTApp::use (IoTMiddleware middleware)
@@ -36,19 +32,6 @@ void IoTApp::runMiddleware(IoTRequest *request, int index = 0)
36
32
}
37
33
}
38
34
39
- // static void handleData(void* arg, AsyncClient* client, void *data, size_t len)
40
- // {
41
- // Serial.print("[CALLBACK] data received, ip: " + client->remoteIP().toString());
42
- // Serial.println( " [" + String((char*)data) + "]");
43
-
44
- // // or loop through data , using data[i] and len:
45
- // // for ( int i = 0 ; i < len ; i++ ) {
46
- // // if ( uint8_t*)data[i] == 0 ) { } }
47
-
48
- // // could send to server here, by doing:
49
- // // sendToServer( "Hello!");
50
- // }
51
-
52
35
void IoTApp::listen (Client *client)
53
36
{
54
37
this ->clients .push_back (client);
@@ -235,12 +218,7 @@ IoTRequest *IoTApp::send(IoTRequest *request, IoTRequestResponse *requestRespons
235
218
dataLength += 2 + request->bodyLength ; /* 1 + 1 (B+\n) + request->bodyLength */
236
219
}
237
220
238
- // uint8_t *data = (uint8_t *)(malloc(dataLength * sizeof(uint8_t)));
239
- // uint8_t *data = new uint8_t[dataLength];
240
-
241
- // char data[dataLength+1]; /* +1 (\0) */
242
221
uint8_t data[dataLength + 1 ]; /* +1 (\0) */
243
- // uint8_t data[6 + pathLength + 2]; /* +2 (\n\0) */
244
222
data[0 ] = request->version ;
245
223
data[1 ] = ' \n ' ;
246
224
data[2 ] = static_cast <uint8_t >((char )request->method );
@@ -250,39 +228,30 @@ IoTRequest *IoTApp::send(IoTRequest *request, IoTRequestResponse *requestRespons
250
228
251
229
size_t nextIndex = 5 ;
252
230
253
- // memcpy((data + 6), request->path, pathLength);
254
231
for (size_t i = 0 ; i < pathLength; i++)
255
232
{
256
233
data[++nextIndex] = *(request->path + i);
257
234
}
258
235
259
- // size_t nextIndex = 6 + pathLength; /* 5 (last index) + pathLength + 1 (next) */
260
- // data[nextIndex] = '\n';
261
- // nextIndex++;
262
-
263
236
data[++nextIndex] = ' \n ' ;
264
237
265
238
if (headers.length () > 0 )
266
239
{
267
- // memcpy((data + nextIndex), headers.c_str(), headers.length());
268
240
for (size_t i = 0 ; i < headers.length (); i++)
269
241
{
270
242
data[++nextIndex] = (headers.charAt (i));
271
243
}
272
- // nextIndex += headers.length();
273
244
}
274
245
275
246
if (request->body != NULL )
276
247
{
277
248
data[++nextIndex] = ' B' ;
278
249
data[++nextIndex] = ' \n ' ;
279
- // memcpy((data + nextIndex + 1), request->body, request->bodyLength);
280
250
for (size_t i = 0 ; i < request->bodyLength ; i++)
281
251
{
282
252
data[++nextIndex] = *(request->body + i);
283
253
}
284
254
}
285
- // data[nextIndex + request->bodyLength + 1] = '\0';
286
255
287
256
data[++nextIndex] = ' \0 ' ;
288
257
@@ -298,94 +267,8 @@ IoTRequest *IoTApp::send(IoTRequest *request, IoTRequestResponse *requestRespons
298
267
this ->requestResponse .insert (std::make_pair (request->id , *requestResponse));
299
268
}
300
269
301
- // request->client->print("teste");
302
- // String _data = String((const char*)data);
303
- // request->client->print(_data);
304
- // const uint8_t* _data = data;
305
-
306
- // const uint8_t* _data = data;
307
- // request->client->print(String(_data, dataLength));
308
- // request->client->print("lorem ipsum fuck the message how much logger is this better for our test and counter lorem ipsum fuck the message how much logger is this better for our test and counter lorem ipsum fuck the message how much logger is this better for our test and counter");
309
-
310
- // request->client->add((const char*)data, dataLength);
311
- // request->client->send();
312
-
313
- // request->client->write((const char*)data, dataLength);
314
-
315
- // const char* teste = (const char *)(malloc(dataLength * sizeof(char)));
316
-
317
- /* char c[3];
318
-
319
- c[0] = 'h';
320
- c[1] = 'i';
321
- c[2] = '\0'; */
322
-
323
- // ---- ok com path
324
- // char c[6 + pathLength + 2];
325
-
326
- // c[0] = request->version;
327
- // c[1] = '\n';
328
- // c[2] = static_cast<uint8_t>((char)request->method);
329
- // c[3] = request->id >> 8; /* Id as Big Endian - (MSB first) */
330
- // c[4] = request->id - (data[3] << 8); /* Id as Big Endian - (LSB last) */
331
- // c[5] = '\n';
332
- // size_t cursor = 6;
333
- // // char p[pathLength];
334
- // for (size_t i = 0; i < pathLength; i++)
335
- // {
336
- // c[cursor + i] = *(request->path+i);
337
- // }
338
- // // char p[] = "/who/r/i";
339
- // // for (size_t i = 0; i < 8; i++)
340
- // // {
341
- // // c[cursor + i] = p[i];
342
- // // }
343
- // // memcpy((c + 6), request->path, pathLength);
344
- // c[(6 + pathLength)] = '\n';
345
- // c[(7 + pathLength)] = '\0';
346
-
347
- // const char *d = c;
348
- // request->client->write(d, dataLength);
349
- // ----- ok com path
350
- // const uint8_t *d = data;
351
-
352
- // std::copy(data, data+dataLength, teste);
353
- // memcpy((char*)teste, data, dataLength);
354
-
355
270
request->client ->write (data, dataLength);
356
- // request->client->write(d, 6 + pathLength + 1);
357
-
358
- // size_t space = request->client->space();
359
- // if (space > dataLength)
360
- // {
361
- // // request->client->write((const char *)data, dataLength, ASYNC_WRITE_FLAG_MORE);
362
-
363
- // }
364
-
365
- // free((char*)teste);
366
-
367
- // request->client->free();
368
-
369
- // write the data in chunks
370
- // int chunk_size = 16; // write data in 16-byte chunks
371
- // for (int i = 0; i < dataLength; i += chunk_size)
372
- // {
373
- // size_t remainToWrite = dataLength - i;
374
- // size_t amountToWrite = ( remainToWrite > chunk_size) ? chunk_size : remainToWrite;
375
- // int bytes_written = request->client->write(data + i, amountToWrite);
376
- // }
377
-
378
- // _data = String();
379
-
380
- // request->client->flush();
381
- // request->client->stop();
382
-
383
- // request->client->;
384
- // request->client->close();
385
-
386
- // free(data);
387
-
388
- // delete[] data;
271
+
389
272
if (shouldFreePath)
390
273
{
391
274
free (request->path );
0 commit comments