bool PyrobarHTTPRequestHandler::parseRequest(EthernetClient client) { if (client.available()) { if(client.readStringUntil(' ') == "GET") { if(client.read() == '/') { String dataType = client.readStringUntil('/'); if (DEBUG_REQUEST_HANDLER) { Serial.print("Data Type: "); Serial.println(dataType); } if(dataType == pyrobarDataTypeBuffer) { return handleBuffer(client); } else if(dataType == pyrobarDataTypeFire) { return handleFireSequence(client); } else if(dataType == pyrobarDataTypeScalar) { return handleScalar(client); } else if(dataType == pyrobarDataTypeLights) { return handleLightsOnOff(client); } else { return false; } } } else { return false; } } }
bool PyrobarHTTPRequestHandler::handleScalar(EthernetClient client) { // E.g. /sclr/sndSens/0.789 String scalarType = client.readStringUntil('/'); if (DEBUG_REQUEST_HANDLER) { Serial.print("Scalar type: "); Serial.println(scalarType); } float value = client.readStringUntil(' ').toFloat(); return _lightMap->setScalar(scalarType, value); }
bool PyrobarHTTPRequestHandler::handleLightsOnOff(EthernetClient client) { String type = client.readStringUntil('/'); String instruction = client.readStringUntil(' '); if (DEBUG_REQUEST_HANDLER) { Serial.print("Turning lights "); Serial.println(instruction); } if (instruction == pyrobarLightsOut) _lightMap->turnLights(type, OFF); else if (instruction == pyrobarLightsOn) _lightMap->turnLights(type, ON); else return false; return true; }
bool PyrobarHTTPRequestHandler::handleBuffer(EthernetClient client) { // E.g. /bfr/snd/0/000001... String bufferType = client.readStringUntil('/'); if (DEBUG_REQUEST_HANDLER) { Serial.print("Buffer type: "); Serial.println(bufferType); } if (bufferType == pyrobarBfrTypeFreq || bufferType == pyrobarBfrTypeSnd) { int zone = atoi(client.readStringUntil('/').c_str()); if (zone < TOTAL_ZONE_COUNT) { loadBuffer(bufferType, zone, client); return true; } else { // add error notice to stream return false; } } }