update readme a bit

This commit is contained in:
Me No Dev
2016-05-15 03:42:27 +03:00
parent 29b3f72e80
commit 8917b98332

View File

@@ -94,6 +94,18 @@ if(request->hasHeader("MyHeader")){
AsyncWebHeader* h = request->getHeader("MyHeader"); AsyncWebHeader* h = request->getHeader("MyHeader");
Serial.printf("MyHeader: %s\n", h->value().c_str()); Serial.printf("MyHeader: %s\n", h->value().c_str());
} }
//List all collected headers (Compatibility)
int headers = request->headers();
int i;
for(i=0;i<headers;i++){
Serial.printf("HEADER[%s]: %s\n", headerName(i).c_str(),header(i).c_str());
}
//get specific header by name (Compatibility)
if(request->hasHeader("MyHeader")){
Serial.printf("MyHeader: %s\n", header("MyHeader").c_str());
}
``` ```
### GET, POST and FILE parameters ### GET, POST and FILE parameters
@@ -112,16 +124,26 @@ for(int i=0;i<params;i++){
} }
//Check if GET parameter exists //Check if GET parameter exists
bool exists = request->hasParam("download"); if(request->hasParam("download"))
AsyncWebParameter* p = request->getParam("download"); AsyncWebParameter* p = request->getParam("download");
//Check if POST (but not File) parameter exists //Check if POST (but not File) parameter exists
bool exists = request->hasParam("download", true); if(request->hasParam("download", true))
AsyncWebParameter* p = request->getParam("download", true); AsyncWebParameter* p = request->getParam("download", true);
//Check if FILE was uploaded //Check if FILE was uploaded
bool exists = request->hasParam("download", true, true); if(request->hasParam("download", true, true))
AsyncWebParameter* p = request->getParam("download", true, true); AsyncWebParameter* p = request->getParam("download", true, true);
//List all parameters (Compatibility)
int args = request->args();
for(int i=0;i<args;i++){
Serial.printf("ARG[%s]: %s\n", argName(i).c_str(), arg(i).c_str());
}
//Check if parameter exists (Compatibility)
if(equest->hasArg("download"))
String arg = request->arg("download");
``` ```
### FILE Upload handling ### FILE Upload handling
@@ -470,48 +492,52 @@ void onEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
//Server methods //Server methods
AsyncWebSocket ws("/ws"); AsyncWebSocket ws("/ws");
//printf to a client //printf to a client
ws.printf([client id], [arguments...]); ws.printf((uint32_t)client_id, arguments...);
//printf to all clients //printf to all clients
ws.printfAll([arguments...]); ws.printfAll(arguments...);
//printf_P to a client //printf_P to a client
ws.printf_P([client id], PSTR([format]), [arguments...]); ws.printf_P((uint32_t)client_id, PSTR(format), arguments...);
//printfAll_P to all clients //printfAll_P to all clients
ws.printf_P(PSTR([format]), [arguments...]); ws.printf_P(PSTR(format), arguments...);
//send text to a client //send text to a client
ws.text([client id], [(char*)text]); ws.text((uint32_t)client_id, (char*)text);
ws.text([client id], [text], [len]); ws.text((uint32_t)client_id, (uint8_t*)text, (size_t)len);
//send text from PROGMEM to a client
ws.text((uint32_t)client_id, PSTR("text"));
const char flash_text[] PROGMEM = "Text to send" const char flash_text[] PROGMEM = "Text to send"
ws.text([client id], [PSTR("text")]); ws.text((uint32_t)client_id, FPSTR(flash_text));
ws.text([client id], [FPSTR(flash_text)]);
//send text to all clients //send text to all clients
ws.textAll([(char*text]); ws.textAll((char*)text);
ws.textAll([text], [len]); ws.textAll((uint8_t*)text, (size_t)len);
//send binary to a client //send binary to a client
ws.binary([client id], [(char*)binary]); ws.binary((uint32_t)client_id, (char*)binary);
ws.binary([client id], [binary], [len]); ws.binary((uint32_t)client_id, (uint8_t*)binary, (size_t)len);
//send binary from PROGMEM to a client
const uint8_t flash_binary[] PROGMEM = { 0x01, 0x02, 0x03, 0x04 }; const uint8_t flash_binary[] PROGMEM = { 0x01, 0x02, 0x03, 0x04 };
ws.binary([client id], [flash_binary], [len]); ws.binary((uint32_t)client_id, flash_binary, 4);
//send binary to all clients //send binary to all clients
ws.binaryAll([(char*binary]); ws.binaryAll((char*)binary);
ws.binaryAll([binary], [len]); ws.binaryAll((uint8_t*)binary, (size_t)len);
//client methods //client methods
AsyncWebSocketClient * client; AsyncWebSocketClient * client;
//printf to a client //printf
client->printf([arguments...]); client->printf(arguments...);
//printf_P to a client //printf_P
client->printf_P( PSTR([format]), [arguments...]); client->printf_P(PSTR(format), arguments...);
//send text to a client //send text
client->text([(char*)text]); client->text((char*)text);
client->text([text], [len]); client->text((uint8_t*)text, (size_t)len);
//send text from PROGMEM
client->text(PSTR("text"));
const char flash_text[] PROGMEM = "Text to send"; const char flash_text[] PROGMEM = "Text to send";
client->text([PSTR("text")]); client->text(FPSTR(flash_text));
client->text([FPSTR(flash_text)]); //send binary
//send binary to a client client->binary((char*)binary);
client->binary([(char*)binary]); client->binary((uint8_t*)binary, (size_t)len);
client->binary([binary], [len]); //send binary from PROGMEM
const uint8_t flash_binary[] PROGMEM = { 0x01, 0x02, 0x03, 0x04 }; const uint8_t flash_binary[] PROGMEM = { 0x01, 0x02, 0x03, 0x04 };
client->binary([flash_binary], [len]); client->binary(flash_binary, 4);
``` ```
@@ -595,5 +621,3 @@ void setup(){
void loop(){} void loop(){}
``` ```